support yaml anchors (#65)

This commit is contained in:
ChristopherHX
2025-08-04 16:57:51 +02:00
committed by GitHub
parent 8ae335c273
commit cd57d482c3
2 changed files with 30 additions and 0 deletions

View File

@@ -238,6 +238,9 @@ func (s *Node) UnmarshalYAML(node *yaml.Node) error {
if node != nil && node.Kind == yaml.DocumentNode {
return s.UnmarshalYAML(node.Content[0])
}
if node.Kind == yaml.AliasNode {
node = node.Alias
}
def := s.Schema.GetDefinition(s.Definition)
if s.Context == nil {
s.Context = def.Context

View File

@@ -90,3 +90,30 @@ jobs:
}).UnmarshalYAML(&node)
assert.NoError(t, err)
}
func TestYAMLAnchors(t *testing.T) {
var node yaml.Node
err := yaml.Unmarshal([]byte(`
on: push
jobs:
job-with-condition:
runs-on: &label
self-hosted
if: success() || success('joba', 'jobb') || failure() || failure('joba', 'jobb') || always() || cancelled()
steps: &steps
- run: exit 0
then:
runs-on: *label
steps:
- run: exit 0
`), &node)
if !assert.NoError(t, err) {
return
}
err = (&Node{
Definition: "workflow-root-strict",
Schema: GetWorkflowSchema(),
}).UnmarshalYAML(&node)
assert.NoError(t, err)
}