Centralize effective artifact selection
This commit is contained in:
@@ -84,18 +84,29 @@ func (analyzeStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
||||
}}, nil
|
||||
}
|
||||
|
||||
effective := env.EffectiveArtifacts
|
||||
if !effective.Resolved() {
|
||||
effective, err = artifacts.ResolveEffectiveArtifactSet(
|
||||
artifacts.ConfiguredArtifactDefinitions(env.Config.Pipeline.Scriptorium.Artifacts),
|
||||
env.SelectedArtifactKeys,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("analyze: resolve effective artifacts: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
runtimeCatalog, err := buildAnalyzeRuntimeArtifactCatalog(
|
||||
paths,
|
||||
m,
|
||||
env.Config.Pipeline.Scriptorium,
|
||||
env.Config.Pipeline.Notarius,
|
||||
env.SelectedArtifactKeys,
|
||||
effective,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("analyze: build runtime artifact catalog: %w", err)
|
||||
}
|
||||
|
||||
plans, skipReason, err := buildAnalyzeExecutionPlans(env.Config.Pipeline.Scriptorium, runtimeCatalog)
|
||||
plans, skipReason, err := buildAnalyzeExecutionPlans(env.Config.Pipeline.Scriptorium, effective, runtimeCatalog)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("analyze: %w", err)
|
||||
}
|
||||
@@ -182,6 +193,7 @@ func (analyzeStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
||||
|
||||
func buildAnalyzeExecutionPlans(
|
||||
scriptoriumCfg *config.ScriptoriumConfig,
|
||||
effective artifacts.EffectiveArtifactSet,
|
||||
catalog *artifacts.ArtifactCatalog,
|
||||
) ([]analyzeArtifactExecutionPlan, string, error) {
|
||||
if scriptoriumCfg == nil {
|
||||
@@ -191,18 +203,11 @@ func buildAnalyzeExecutionPlans(
|
||||
return nil, "no scriptorium artifacts configured", nil
|
||||
}
|
||||
|
||||
entries := catalog.ListConfigured()
|
||||
selected := make([]string, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
if entry.Executable {
|
||||
selected = append(selected, entry.ConfiguredKey)
|
||||
}
|
||||
}
|
||||
if len(selected) == 0 {
|
||||
if len(effective.Keys()) == 0 {
|
||||
return nil, "no selected scriptorium artifacts to execute", nil
|
||||
}
|
||||
|
||||
ordered, err := orderSelectedScriptoriumArtifacts(scriptoriumCfg.Artifacts, selected, catalog)
|
||||
ordered, err := orderSelectedScriptoriumArtifacts(scriptoriumCfg.Artifacts, effective, catalog)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@@ -220,16 +225,12 @@ func buildAnalyzeExecutionPlans(
|
||||
|
||||
func orderSelectedScriptoriumArtifacts(
|
||||
artifactsCfg map[string]config.ScriptoriumArtifactConfig,
|
||||
selected []string,
|
||||
effective artifacts.EffectiveArtifactSet,
|
||||
catalog *artifacts.ArtifactCatalog,
|
||||
) ([]string, error) {
|
||||
selectedSet := map[string]struct{}{}
|
||||
for _, key := range selected {
|
||||
trimmed := strings.TrimSpace(key)
|
||||
if trimmed == "" {
|
||||
return nil, fmt.Errorf("selected artifact key must be non-empty")
|
||||
}
|
||||
selectedSet[trimmed] = struct{}{}
|
||||
for _, key := range effective.Keys() {
|
||||
selectedSet[key] = struct{}{}
|
||||
}
|
||||
|
||||
for selectedKey := range selectedSet {
|
||||
@@ -722,33 +723,20 @@ func buildAnalyzeRuntimeArtifactCatalog(
|
||||
m *manifest.Manifest,
|
||||
scriptoriumCfg *config.ScriptoriumConfig,
|
||||
notariusCfg *config.NotariusConfig,
|
||||
selectedArtifacts []string,
|
||||
effective artifacts.EffectiveArtifactSet,
|
||||
) (*artifacts.ArtifactCatalog, error) {
|
||||
catalog := artifacts.NewArtifactCatalog()
|
||||
if err := catalog.RegisterBuiltIns(); err != nil {
|
||||
return nil, err
|
||||
configured := artifacts.ConfiguredArtifactDefinitions(nil)
|
||||
if scriptoriumCfg != nil {
|
||||
configured = artifacts.ConfiguredArtifactDefinitions(scriptoriumCfg.Artifacts)
|
||||
}
|
||||
extractionDefinitions := artifacts.ExtractionDefinitionsFromConfig(notariusCfg)
|
||||
if err := catalog.RegisterExtractionArtifacts(extractionDefinitions); err != nil {
|
||||
catalog, err := artifacts.BootstrapRuntimeCatalog(configured, effective, extractionDefinitions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if notariusCfg != nil && notariusCfg.Enabled {
|
||||
catalog.HydrateExtractionArtifacts(paths, m, extractionDefinitions)
|
||||
}
|
||||
if scriptoriumCfg == nil {
|
||||
return catalog, nil
|
||||
}
|
||||
|
||||
configured := map[string]artifacts.ConfiguredArtifactDefinition{}
|
||||
for key, artifactCfg := range scriptoriumCfg.Artifacts {
|
||||
configured[key] = artifacts.ConfiguredArtifactDefinition{
|
||||
Enabled: artifactCfg.Enabled,
|
||||
OutputPath: artifactCfg.OutputPath,
|
||||
}
|
||||
}
|
||||
if err := catalog.RegisterConfiguredArtifacts(configured, selectedArtifacts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, entry := range catalog.ListConfigured() {
|
||||
if entry.Executable {
|
||||
|
||||
Reference in New Issue
Block a user