diff --git a/pkg/jobparser/model.go b/pkg/jobparser/model.go index 5418aa9..e7ca0df 100644 --- a/pkg/jobparser/model.go +++ b/pkg/jobparser/model.go @@ -276,9 +276,21 @@ func EvaluateConcurrency(rc *model.RawConcurrency, jobID string, job *Job, gitCt } evaluator := NewExpressionEvaluator(NewInterpeter(jobID, actJob, matrix, toGitContext(gitCtx), results, vars, inputs)) - group := evaluator.Interpolate(rc.Group) - cancelInProgress := evaluator.Interpolate(rc.CancelInProgress) - return group, cancelInProgress == "true", nil + var node yaml.Node + if err := node.Encode(rc); err != nil { + return "", false, fmt.Errorf("failed to encode concurrency: %w", err) + } + if err := evaluator.EvaluateYamlNode(&node); err != nil { + return "", false, fmt.Errorf("failed to evaluate concurrency: %w", err) + } + var evaluated model.RawConcurrency + if err := node.Decode(&evaluated); err != nil { + return "", false, fmt.Errorf("failed to unmarshal evaluated concurrency: %w", err) + } + if evaluated.RawExpression != "" { + return evaluated.RawExpression, false, nil + } + return evaluated.Group, evaluated.CancelInProgress == "true", nil } func toGitContext(input map[string]any) *model.GithubContext { diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index e3bae9b..f93623f 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -778,4 +778,22 @@ func decodeNode(node yaml.Node, out interface{}) bool { type RawConcurrency struct { Group string `yaml:"group,omitempty"` CancelInProgress string `yaml:"cancel-in-progress,omitempty"` + RawExpression string `yaml:"-,omitempty"` +} + +type objectConcurrency RawConcurrency + +func (r *RawConcurrency) UnmarshalYAML(n *yaml.Node) error { + if err := n.Decode(&r.RawExpression); err == nil { + return nil + } + return n.Decode((*objectConcurrency)(r)) +} + +func (r *RawConcurrency) MarshalYAML() (interface{}, error) { + if r.RawExpression != "" { + return r.RawExpression, nil + } + + return (*objectConcurrency)(r), nil }