Centralize effective artifact selection
This commit is contained in:
@@ -138,10 +138,28 @@ func (c *ArtifactCatalog) RegisterBuiltIns() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterConfiguredArtifacts registers configured artifacts and applies executable selection.
|
||||
// RegisterConfiguredArtifacts registers configured artifacts. New runtime
|
||||
// callers should resolve selection first and use RegisterEffectiveConfiguredArtifacts.
|
||||
func (c *ArtifactCatalog) RegisterConfiguredArtifacts(
|
||||
configured map[string]ConfiguredArtifactDefinition,
|
||||
selected []string,
|
||||
selected ...[]string,
|
||||
) error {
|
||||
var requested []string
|
||||
if len(selected) > 0 {
|
||||
requested = selected[0]
|
||||
}
|
||||
effective, err := ResolveEffectiveArtifactSet(configured, requested)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.RegisterEffectiveConfiguredArtifacts(configured, effective)
|
||||
}
|
||||
|
||||
// RegisterEffectiveConfiguredArtifacts registers configured artifacts using one
|
||||
// resolved analyze execution set.
|
||||
func (c *ArtifactCatalog) RegisterEffectiveConfiguredArtifacts(
|
||||
configured map[string]ConfiguredArtifactDefinition,
|
||||
effective EffectiveArtifactSet,
|
||||
) error {
|
||||
keys := make([]string, 0, len(configured))
|
||||
for key := range configured {
|
||||
@@ -149,15 +167,6 @@ func (c *ArtifactCatalog) RegisterConfiguredArtifacts(
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
selectedSet := map[string]struct{}{}
|
||||
for _, key := range selected {
|
||||
trimmed := strings.TrimSpace(key)
|
||||
if !artifactpolicy.IsConfiguredKey(trimmed) {
|
||||
return fmt.Errorf("selected artifact key %q must match ^[a-z][a-z0-9_]*$", key)
|
||||
}
|
||||
selectedSet[trimmed] = struct{}{}
|
||||
}
|
||||
|
||||
for _, key := range keys {
|
||||
trimmed := strings.TrimSpace(key)
|
||||
if !artifactpolicy.IsConfiguredKey(trimmed) {
|
||||
@@ -169,11 +178,6 @@ func (c *ArtifactCatalog) RegisterConfiguredArtifacts(
|
||||
return fmt.Errorf("duplicate configured artifact key %q", trimmed)
|
||||
}
|
||||
|
||||
executable := def.Enabled
|
||||
if len(selectedSet) > 0 {
|
||||
_, executable = selectedSet[trimmed]
|
||||
}
|
||||
|
||||
if err := c.addEntry(CatalogEntry{
|
||||
SourceID: sourceID,
|
||||
ConfiguredKey: trimmed,
|
||||
@@ -181,24 +185,36 @@ func (c *ArtifactCatalog) RegisterConfiguredArtifacts(
|
||||
ProducerStage: "analyze",
|
||||
OutputKind: "scriptorium_artifact",
|
||||
Planned: true,
|
||||
Executable: executable,
|
||||
Executable: effective.Includes(trimmed),
|
||||
}); err != nil {
|
||||
return fmt.Errorf("register configured artifact %q: %w", trimmed, err)
|
||||
}
|
||||
c.configuredIndex[trimmed] = sourceID
|
||||
}
|
||||
|
||||
if len(selectedSet) > 0 {
|
||||
for key := range selectedSet {
|
||||
if _, ok := c.configuredIndex[key]; !ok {
|
||||
return fmt.Errorf("selected artifact %q is not configured", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// BootstrapRuntimeCatalog creates the deterministic catalog definitions shared
|
||||
// by runtime consumers. Availability remains the caller's responsibility.
|
||||
func BootstrapRuntimeCatalog(
|
||||
configured map[string]ConfiguredArtifactDefinition,
|
||||
effective EffectiveArtifactSet,
|
||||
extraction map[string]ExtractionArtifactDefinition,
|
||||
) (*ArtifactCatalog, error) {
|
||||
catalog := NewArtifactCatalog()
|
||||
if err := catalog.RegisterBuiltIns(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := catalog.RegisterEffectiveConfiguredArtifacts(configured, effective); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := catalog.RegisterExtractionArtifacts(extraction); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return catalog, nil
|
||||
}
|
||||
|
||||
// Lookup returns one catalog entry by source ID.
|
||||
func (c *ArtifactCatalog) Lookup(sourceID string) (CatalogEntry, bool) {
|
||||
if c == nil {
|
||||
|
||||
Reference in New Issue
Block a user