Accept composed ConfigKit artifact definitions
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
@@ -24,7 +23,6 @@ type pipelineResolutionMetadata struct {
|
||||
ownership []pipelineFieldOwnership
|
||||
artifactFamilies map[string]ScriptoriumArtifactFamilyConfig
|
||||
artifactFamiliesExpanded bool
|
||||
publishDeclared bool
|
||||
configkitMetadata configkit.Metadata
|
||||
configkitSources []configkit.SourceInfo
|
||||
}
|
||||
@@ -262,12 +260,8 @@ func validatePipelineConfigKit(cfg *PipelineConfig, validation *configkit.Valida
|
||||
func pipelineMetadataFromConfigKit(cfg *PipelineConfig, result *configkit.Result[PipelineConfig], opts PipelineLoadOptions) (*pipelineResolutionMetadata, error) {
|
||||
sources := result.Sources()
|
||||
metadata := result.Metadata()
|
||||
if err := rejectDuplicateBaseDefinitions(metadata, sources); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolved := &pipelineResolutionMetadata{
|
||||
configkitMetadata: metadata, configkitSources: sources,
|
||||
publishDeclared: metadata.IsExplicit(configkit.Keys("publish")),
|
||||
}
|
||||
pathsByID := make(map[string]string, len(sources))
|
||||
for index, source := range sources {
|
||||
@@ -341,50 +335,6 @@ func ownershipSources(origin configkit.Origin, pathsByID map[string]string) []st
|
||||
return sources
|
||||
}
|
||||
|
||||
func rejectDuplicateBaseDefinitions(metadata configkit.Metadata, sources []configkit.SourceInfo) error {
|
||||
pathsByID := make(map[string]string, len(sources))
|
||||
for _, source := range sources {
|
||||
pathsByID[source.ID] = source.Path
|
||||
}
|
||||
// Enumerate retained declarations, not just surviving effective keys. Loading
|
||||
// the base separately would also resolve credentials removed by the overlay.
|
||||
// ConfigKit returns canonical JSON Pointers in deterministic order.
|
||||
for _, path := range metadata.HistoricalPaths() {
|
||||
parts := strings.Split(path.String(), "/")
|
||||
if len(parts) != 4 || parts[1] != "scriptorium" {
|
||||
continue
|
||||
}
|
||||
var kind string
|
||||
switch parts[2] {
|
||||
case "artifacts":
|
||||
kind = "artifact"
|
||||
case "artifact_families":
|
||||
kind = "artifact family"
|
||||
default:
|
||||
continue
|
||||
}
|
||||
seen := map[string]struct{}{}
|
||||
for _, change := range metadata.History(path) {
|
||||
if change.Origin.Layer != configkit.LayerBase {
|
||||
continue
|
||||
}
|
||||
for _, location := range change.Origin.Locations {
|
||||
seen[location.SourceID] = struct{}{}
|
||||
}
|
||||
}
|
||||
if len(seen) > 1 {
|
||||
claims := make([]string, 0, len(seen))
|
||||
for sourceID := range seen {
|
||||
claims = append(claims, pathsByID[sourceID])
|
||||
}
|
||||
sort.Strings(claims)
|
||||
key := strings.NewReplacer("~1", "/", "~0", "~").Replace(parts[3])
|
||||
return fmt.Errorf("pipeline Scriptorium %s %q is declared by multiple base files: %s", kind, key, strings.Join(claims, ", "))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func intPtr(value int) *int { return &value }
|
||||
func float64Ptr(value float64) *float64 { return &value }
|
||||
func boolPtr(value bool) *bool { return &value }
|
||||
|
||||
Reference in New Issue
Block a user