Share catalog-independent pipeline layout
This commit is contained in:
@@ -344,32 +344,16 @@ func Binding(module string) ModuleBinding {
|
||||
}
|
||||
|
||||
func ResolvePipeline(profile PipelineProfile, options ResolveOptions, catalog ModuleCatalog) (ResolvedPipeline, error) {
|
||||
pipelineID := strings.TrimSpace(profile.ID)
|
||||
if pipelineID == "" {
|
||||
return ResolvedPipeline{}, fmt.Errorf("pipeline id must not be empty")
|
||||
}
|
||||
|
||||
explicitSteps := profile.Steps != nil
|
||||
if len(profile.Artifacts) > 0 && explicitSteps {
|
||||
return ResolvedPipeline{}, fmt.Errorf("pipeline %q must not declare both artifacts and steps", pipelineID)
|
||||
}
|
||||
if explicitSteps && len(options.Only) > 0 {
|
||||
return ResolvedPipeline{}, fmt.Errorf("pipeline %q lane selection is not supported for explicit ordered steps", pipelineID)
|
||||
}
|
||||
steps := profile.Steps
|
||||
if !explicitSteps {
|
||||
steps = []PipelineStepProfile{{ID: "default", Artifacts: profile.Artifacts}}
|
||||
}
|
||||
if explicitSteps && len(steps) == 0 {
|
||||
return ResolvedPipeline{}, fmt.Errorf("pipeline %q must declare at least one ordered step", pipelineID)
|
||||
}
|
||||
if len(steps) == 0 {
|
||||
return ResolvedPipeline{}, fmt.Errorf("pipeline %q must declare at least one artifact lane", pipelineID)
|
||||
}
|
||||
configuredLaneIDs, err := configuredProfileLaneIDs(pipelineID, steps)
|
||||
layout, err := LayoutPipeline(profile)
|
||||
if err != nil {
|
||||
return ResolvedPipeline{}, err
|
||||
}
|
||||
pipelineID, explicitSteps := layout.ID, layout.ExplicitSteps
|
||||
if explicitSteps && len(options.Only) > 0 {
|
||||
return ResolvedPipeline{}, fmt.Errorf("pipeline %q lane selection is not supported for explicit ordered steps", pipelineID)
|
||||
}
|
||||
steps := layout.Steps
|
||||
configuredLaneIDs := layout.ConfiguredLaneIDs
|
||||
|
||||
input, err := resolveBinding(profile.Input, "", fmt.Sprintf("pipeline %q input reference slot", pipelineID))
|
||||
if err != nil {
|
||||
@@ -408,9 +392,9 @@ func ResolvePipeline(profile PipelineProfile, options ResolveOptions, catalog Mo
|
||||
}
|
||||
} else {
|
||||
allLanes := make(map[string]ArtifactLaneProfile)
|
||||
for _, step := range profile.Steps {
|
||||
for _, step := range layout.Steps {
|
||||
for laneID, lane := range step.Artifacts {
|
||||
allLanes[strings.TrimSpace(laneID)] = lane
|
||||
allLanes[laneID] = lane
|
||||
}
|
||||
}
|
||||
if err := validatePipelineReferenceDefaults(pipelineID, profile.References, chunkSpec, allLanes, catalog); err != nil {
|
||||
@@ -455,23 +439,14 @@ func ResolvePipeline(profile PipelineProfile, options ResolveOptions, catalog Mo
|
||||
}
|
||||
resolved.ValidatorChains = append(resolved.ValidatorChains, chunkValidatorChain)
|
||||
outputCapabilities := capabilities.clone()
|
||||
seenResolvedLanes := make(map[string]string)
|
||||
seenResolvedSteps := make(map[string]struct{}, len(steps))
|
||||
|
||||
for _, step := range steps {
|
||||
stepID := strings.TrimSpace(step.ID)
|
||||
if stepID == "" {
|
||||
return ResolvedPipeline{}, fmt.Errorf("pipeline %q step id must not be empty", pipelineID)
|
||||
}
|
||||
if _, exists := seenResolvedSteps[stepID]; exists {
|
||||
return ResolvedPipeline{}, fmt.Errorf("pipeline %q step id %q is duplicated after trimming", pipelineID, stepID)
|
||||
}
|
||||
seenResolvedSteps[stepID] = struct{}{}
|
||||
stepID := step.ID
|
||||
laneOptions := ResolveOptions{}
|
||||
if !explicitSteps {
|
||||
laneOptions = options
|
||||
}
|
||||
lanesByID, selectedLaneIDs, err := selectedArtifactLanes(pipelineID, step.Artifacts, laneOptions)
|
||||
lanesByID := step.Artifacts
|
||||
selectedLaneIDs, err := selectedLayoutLaneIDs(pipelineID, step, laneOptions)
|
||||
if err != nil {
|
||||
return ResolvedPipeline{}, err
|
||||
}
|
||||
@@ -487,10 +462,6 @@ func ResolvePipeline(profile PipelineProfile, options ResolveOptions, catalog Mo
|
||||
stepReferences := mergeReferenceMaps(profile.References, step.References)
|
||||
resolvedStep := ResolvedPipelineStep{ID: stepID}
|
||||
for _, laneID := range selectedLaneIDs {
|
||||
if previousStep, exists := seenResolvedLanes[laneID]; exists {
|
||||
return ResolvedPipeline{}, fmt.Errorf("pipeline %q artifact lane id %q is duplicated across steps %q and %q", pipelineID, laneID, previousStep, stepID)
|
||||
}
|
||||
seenResolvedLanes[laneID] = stepID
|
||||
laneProfile := lanesByID[laneID]
|
||||
lane, validatorChains, laneCapabilities, err := resolveArtifactLane(pipelineID, stepID, laneID, laneProfile, stepReferences, options, capabilities, catalog)
|
||||
if err != nil {
|
||||
@@ -532,29 +503,6 @@ func ResolvePipeline(profile PipelineProfile, options ResolveOptions, catalog Mo
|
||||
return resolved, nil
|
||||
}
|
||||
|
||||
// configuredProfileLaneIDs validates the complete configured lane identity
|
||||
// set before invocation-level selection removes legacy-profile lanes.
|
||||
func configuredProfileLaneIDs(pipelineID string, steps []PipelineStepProfile) ([]string, error) {
|
||||
seen := make(map[string]string)
|
||||
var laneIDs []string
|
||||
for _, step := range steps {
|
||||
_, ids, err := selectedArtifactLanes(pipelineID, step.Artifacts, ResolveOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
stepID := strings.TrimSpace(step.ID)
|
||||
for _, laneID := range ids {
|
||||
if previous, ok := seen[laneID]; ok {
|
||||
return nil, fmt.Errorf("pipeline %q artifact lane id %q is duplicated across steps %q and %q", pipelineID, laneID, previous, stepID)
|
||||
}
|
||||
seen[laneID] = stepID
|
||||
laneIDs = append(laneIDs, laneID)
|
||||
}
|
||||
}
|
||||
sort.Strings(laneIDs)
|
||||
return laneIDs, nil
|
||||
}
|
||||
|
||||
func resolveArtifactLane(
|
||||
pipelineID string,
|
||||
stepID string,
|
||||
@@ -1455,36 +1403,19 @@ func resolveBindings(bindings []ModuleBinding, defaultModule string, referenceSl
|
||||
return resolved, nil
|
||||
}
|
||||
|
||||
func selectedArtifactLanes(pipelineID string, artifacts map[string]ArtifactLaneProfile, options ResolveOptions) (map[string]ArtifactLaneProfile, []string, error) {
|
||||
lanesByID := make(map[string]ArtifactLaneProfile, len(artifacts))
|
||||
for rawLaneID, lane := range artifacts {
|
||||
laneID := strings.TrimSpace(rawLaneID)
|
||||
if laneID == "" {
|
||||
return nil, nil, fmt.Errorf("pipeline %q artifact lane id must not be empty", pipelineID)
|
||||
}
|
||||
if _, ok := lanesByID[laneID]; ok {
|
||||
return nil, nil, fmt.Errorf("pipeline %q artifact lane %q is duplicated after trimming", pipelineID, laneID)
|
||||
}
|
||||
lanesByID[laneID] = lane
|
||||
}
|
||||
|
||||
func selectedLayoutLaneIDs(pipelineID string, step PipelineLayoutStep, options ResolveOptions) ([]string, error) {
|
||||
if len(options.Only) == 0 {
|
||||
keys := make([]string, 0, len(lanesByID))
|
||||
for laneID := range lanesByID {
|
||||
keys = append(keys, laneID)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
return lanesByID, keys, nil
|
||||
return step.LaneIDs, nil
|
||||
}
|
||||
|
||||
selected := make(map[string]struct{}, len(options.Only))
|
||||
for _, rawLaneID := range options.Only {
|
||||
laneID := strings.TrimSpace(rawLaneID)
|
||||
if laneID == "" {
|
||||
return nil, nil, fmt.Errorf("pipeline %q selected artifact lane id must not be empty", pipelineID)
|
||||
return nil, fmt.Errorf("pipeline %q selected artifact lane id must not be empty", pipelineID)
|
||||
}
|
||||
if _, ok := lanesByID[laneID]; !ok {
|
||||
return nil, nil, fmt.Errorf("pipeline %q selected artifact lane %q is not declared", pipelineID, laneID)
|
||||
if _, ok := step.Artifacts[laneID]; !ok {
|
||||
return nil, fmt.Errorf("pipeline %q selected artifact lane %q is not declared", pipelineID, laneID)
|
||||
}
|
||||
selected[laneID] = struct{}{}
|
||||
}
|
||||
@@ -1494,7 +1425,7 @@ func selectedArtifactLanes(pipelineID string, artifacts map[string]ArtifactLaneP
|
||||
keys = append(keys, laneID)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
return lanesByID, keys, nil
|
||||
return keys, nil
|
||||
}
|
||||
|
||||
func resolvedPipelineDigest(resolved ResolvedPipeline) (string, error) {
|
||||
|
||||
Reference in New Issue
Block a user