Implement ordered pipeline step resolution
This commit is contained in:
@@ -133,6 +133,7 @@ func normalizeReferenceSlots(slots []contracts.ReferenceSlot) []contracts.Refere
|
||||
slot.Name = strings.TrimSpace(slot.Name)
|
||||
slot.Description = strings.TrimSpace(slot.Description)
|
||||
slot.AcceptedMediaTypes = normalizeStringSet(slot.AcceptedMediaTypes)
|
||||
slot.AcceptedArtifactKinds = normalizeArtifactKinds(slot.AcceptedArtifactKinds)
|
||||
normalized = append(normalized, slot)
|
||||
}
|
||||
sort.SliceStable(normalized, func(i, j int) bool {
|
||||
@@ -141,6 +142,34 @@ func normalizeReferenceSlots(slots []contracts.ReferenceSlot) []contracts.Refere
|
||||
return normalized
|
||||
}
|
||||
|
||||
func normalizeArtifactKinds(values []contracts.ArtifactKind) []contracts.ArtifactKind {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
seen := make(map[contracts.ArtifactKind]struct{}, len(values))
|
||||
containsEmpty := false
|
||||
for _, value := range values {
|
||||
value = normalizeArtifactKind(value)
|
||||
if value != "" {
|
||||
seen[value] = struct{}{}
|
||||
} else {
|
||||
containsEmpty = true
|
||||
}
|
||||
}
|
||||
if len(seen) == 0 && !containsEmpty {
|
||||
return nil
|
||||
}
|
||||
result := make([]contracts.ArtifactKind, 0, len(seen))
|
||||
for value := range seen {
|
||||
result = append(result, value)
|
||||
}
|
||||
if containsEmpty {
|
||||
result = append(result, "")
|
||||
}
|
||||
sort.Slice(result, func(i, j int) bool { return result[i] < result[j] })
|
||||
return result
|
||||
}
|
||||
|
||||
func normalizeStringSet(values []string) []string {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
@@ -178,6 +207,11 @@ func validateReferenceSlots(slots []contracts.ReferenceSlot) error {
|
||||
if slot.MaxBytes < 0 {
|
||||
return fmt.Errorf("slot %q max_bytes must not be negative", slot.Name)
|
||||
}
|
||||
for _, kind := range slot.AcceptedArtifactKinds {
|
||||
if normalizeArtifactKind(kind) == "" {
|
||||
return fmt.Errorf("slot %q accepted artifact kind must not be empty", slot.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user