package workflow import ( "fmt" "strings" "gopkg.in/yaml.v3" ) type Job struct { After []string `yaml:"after"` Steps []Step `yaml:"steps"` // Error is the action taken when a step fails. Error ErrorAction `yaml:"error"` } type ErrorAction string func (er ErrorAction) MarshalYAML() (interface{}, error) { return er.String(), nil } func (ea *ErrorAction) UnmarshalYAML(value *yaml.Node) error { if value.IsZero() { *ea = ErrorActionStopJob return nil } var s string if err := value.Decode(&s); err != nil { return err } trimmed := strings.TrimSpace(s) lowered := strings.ToLower(trimmed) switch lowered { case "continue": *ea = ErrorActionContinue case "", "stop-job": *ea = ErrorActionStopJob case "stop-action": *ea = ErrorActionStopAction case "stop-run": *ea = ErrorActionStopRun default: return &yaml.TypeError{ Errors: []string{fmt.Sprintf("invalid job error action: %q", trimmed)}, } } return nil } func (ea ErrorAction) String() string { if ea == ErrorActionStopJob { return "stop-job" } return string(ea) } const ( ErrorActionStopJob ErrorAction = "" // default case ErrorActionContinue ErrorAction = "continue" ErrorActionStopAction ErrorAction = "stop-action" ErrorActionStopRun ErrorAction = "stop-run" )