Skip to content

Commit cd57d48

Browse files
support yaml anchors (#65)
1 parent 8ae335c commit cd57d48

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

pkg/schema/schema.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ func (s *Node) UnmarshalYAML(node *yaml.Node) error {
238238
if node != nil && node.Kind == yaml.DocumentNode {
239239
return s.UnmarshalYAML(node.Content[0])
240240
}
241+
if node.Kind == yaml.AliasNode {
242+
node = node.Alias
243+
}
241244
def := s.Schema.GetDefinition(s.Definition)
242245
if s.Context == nil {
243246
s.Context = def.Context

pkg/schema/schema_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,30 @@ jobs:
9090
}).UnmarshalYAML(&node)
9191
assert.NoError(t, err)
9292
}
93+
94+
func TestYAMLAnchors(t *testing.T) {
95+
var node yaml.Node
96+
err := yaml.Unmarshal([]byte(`
97+
on: push
98+
jobs:
99+
job-with-condition:
100+
runs-on: &label
101+
self-hosted
102+
if: success() || success('joba', 'jobb') || failure() || failure('joba', 'jobb') || always() || cancelled()
103+
steps: &steps
104+
- run: exit 0
105+
then:
106+
runs-on: *label
107+
steps:
108+
- run: exit 0
109+
110+
`), &node)
111+
if !assert.NoError(t, err) {
112+
return
113+
}
114+
err = (&Node{
115+
Definition: "workflow-root-strict",
116+
Schema: GetWorkflowSchema(),
117+
}).UnmarshalYAML(&node)
118+
assert.NoError(t, err)
119+
}

0 commit comments

Comments
 (0)