Files
pipelines/internal/pipeline/stage.go
T

45 lines
1.2 KiB
Go

package pipeline
import (
"maps"
"sort"
"strings"
"git.a-wan.net/alan/pipelines/internal/stage"
)
// StageDefinition adapts normalized/persisted graph data for type implementations.
// Copies keep implementations from accidentally modifying immutable graph history.
func StageDefinition(s Stage) stage.Definition {
blocks := maps.Clone(s.Blocks)
if blocks == nil {
blocks = map[string]string{}
}
delete(blocks, "input") // Retired contracts in historical graph JSON are ignored.
for name, value := range map[string]string{"output": s.Output, "prompt": s.Prompt} {
if value != "" {
blocks[name] = value
}
}
configs := maps.Clone(s.Configs)
keys := make([]string, 0, len(configs))
for key := range configs {
keys = append(keys, key)
}
sort.Strings(keys)
lines := []string{"type=" + stage.EffectiveType(s.Type)}
for _, key := range keys {
lines = append(lines, key+"="+configs[key])
}
blocks["configs"] = strings.Join(lines, "\n")
def := stage.Definition{Key: s.Key, Type: stage.EffectiveType(s.Type), Blocks: blocks, Configs: configs, Edges: maps.Clone(s.Edges)}
if s.Notify != nil {
for _, kind := range s.Notify.Artifacts {
if kind == "files" {
def.ReportFileArtifacts = true
}
}
}
return def
}