-
Notifications
You must be signed in to change notification settings - Fork 197
Add YAML anchor and alias support for GitHub Actions workflows #557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Implements two-pass YAML parsing to resolve anchors (&anchor) and aliases (*alias) before linting, matching GitHub Actions' native YAML support. - Add containsAnchorsOrAliases() to detect anchor usage - Add resolveYAMLAnchors() using unmarshal/marshal strategy - Modify Parse() to resolve anchors when present - Add comprehensive test suite covering various anchor scenarios - Preserve backward compatibility for workflows without anchors - Maintain error detection and line number reporting after resolution Fixes workflows that previously failed with "alias node but mapping node is expected" errors when using YAML anchors supported by GitHub Actions.
|
Please note that both lint and test FAIL but they also FAIL on |
| // containsAnchorsOrAliases recursively checks if a YAML node tree contains any anchors or aliases | ||
| func containsAnchorsOrAliases(node *yaml.Node) bool { | ||
| if node.Anchor != "" || node.Alias != nil { | ||
| return true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had added anchor support in nektos/act yaml validator a while back at nektos/act#5893
e.g. https://github.com/nektos/act/blob/5e62222f80b8847de5dfced0527eaaeca3303168/pkg/schema/schema.go#L241C1-L243C3 I then traverse over alias and just handle it as if there were no alias.
Some suggestions from my side, using yaml.Node also heavily.
Just do *node = node.Alias and skip a lot of serializing / deserializing?
Otherwise assign node.Alias where you read this node pointer.
if node.Anchor != ""
just do node.Anchor = "" or remove the assert that require this to be cleared if any.
If I didn't produce a big bug in act, then this improves the code in my opinion
Otherwise use yaml.Node.Encode() and yaml.Node.Decode to replace marshall and unmarshall, this would avoid generating a text representation of the yaml that is not needed.
Serializing the yaml.Node into an interface may break diagnostic features of actionlint regardless if you use yaml.Node or text as medium for reading the yaml again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for the help, those are good tips!
|
Any idea of when this could be merged and released? |
b249531 to
bdb47a5
Compare
|
I'm closing and reopening this PR to kick CI workflows because GitHub seemed to dismiss 'Approve CI' button. |
|
Can you fix the failing checks? @alexaandru |
Implements two-pass YAML parsing to resolve anchors (&anchor) and aliases (*alias) before linting, matching GitHub Actions' native YAML support.
Fixes workflows that previously failed with "alias node but mapping node is expected" errors when using YAML anchors supported by GitHub Actions.
Fixes #133
The support for this just landed: actions/runner#1182