Add family artifact selection and provenance
This commit is contained in:
@@ -60,10 +60,14 @@ func resolveEffectiveArtifacts(cfg *config.Config, selected []string) (artifacts
|
||||
return artifacts.EffectiveArtifactSet{}, fmt.Errorf("--artifacts requires pipeline.scriptorium.artifacts to be configured")
|
||||
}
|
||||
configured := artifacts.ConfiguredArtifactDefinitions(cfg.Pipeline.Scriptorium.Artifacts)
|
||||
if len(selected) > 0 && len(configured) == 0 {
|
||||
normalized, err := normalizeArtifactSelection(cfg, selected)
|
||||
if err != nil {
|
||||
return artifacts.EffectiveArtifactSet{}, err
|
||||
}
|
||||
if len(normalized) > 0 && len(configured) == 0 {
|
||||
return artifacts.EffectiveArtifactSet{}, fmt.Errorf("--artifacts requires at least one configured artifact in pipeline.scriptorium.artifacts")
|
||||
}
|
||||
effective, err := artifacts.ResolveEffectiveArtifactSet(configured, selected)
|
||||
effective, err := artifacts.ResolveEffectiveArtifactSet(configured, normalized)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "is not configured") {
|
||||
return artifacts.EffectiveArtifactSet{}, fmt.Errorf("--artifacts includes unknown artifact %q", selectedArtifactName(err))
|
||||
@@ -73,7 +77,47 @@ func resolveEffectiveArtifacts(cfg *config.Config, selected []string) (artifacts
|
||||
if err := validateEffectiveArtifactConfiguration(cfg.Pipeline.Scriptorium.Artifacts, effective); err != nil {
|
||||
return artifacts.EffectiveArtifactSet{}, err
|
||||
}
|
||||
return effective, nil
|
||||
return effective.WithOrigins(effectiveArtifactOrigins(cfg.Pipeline)), nil
|
||||
}
|
||||
|
||||
func normalizeArtifactSelection(cfg *config.Config, selected []string) ([]string, error) {
|
||||
if len(selected) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
configured := cfg.Pipeline.Scriptorium.Artifacts
|
||||
families := config.ArtifactFamilies(cfg.Pipeline).Families
|
||||
set := make(map[string]struct{}, len(selected))
|
||||
for _, raw := range selected {
|
||||
key := strings.TrimSpace(raw)
|
||||
if key == "" {
|
||||
return nil, fmt.Errorf("artifact names must be non-empty")
|
||||
}
|
||||
if family, ok := families[key]; ok {
|
||||
for _, member := range family.Members {
|
||||
set[member] = struct{}{}
|
||||
}
|
||||
continue
|
||||
}
|
||||
if _, ok := configured[key]; !ok {
|
||||
return nil, fmt.Errorf("--artifacts includes unknown artifact %q", key)
|
||||
}
|
||||
set[key] = struct{}{}
|
||||
}
|
||||
normalized := make([]string, 0, len(set))
|
||||
for key := range set {
|
||||
normalized = append(normalized, key)
|
||||
}
|
||||
sort.Strings(normalized)
|
||||
return normalized, nil
|
||||
}
|
||||
|
||||
func effectiveArtifactOrigins(pipeline *config.PipelineConfig) map[string]artifacts.EffectiveArtifactOrigin {
|
||||
catalog := config.ArtifactFamilies(pipeline)
|
||||
origins := make(map[string]artifacts.EffectiveArtifactOrigin, len(catalog.Members))
|
||||
for key, member := range catalog.Members {
|
||||
origins[key] = artifacts.EffectiveArtifactOrigin{Family: member.Family, CharacterID: member.CharacterID}
|
||||
}
|
||||
return origins
|
||||
}
|
||||
|
||||
func selectedArtifactName(err error) string {
|
||||
|
||||
Reference in New Issue
Block a user