Add support for parsing !reference tag in GitLab CI YAML files #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context
This change is required to enable parsing of the
!reference
tag, which is used in GitLab CI YAML files to optimize and reuse YAML content. Currently, theyaml-ast-parser
does not support parsing this tag, which leads to errors when validating GitLab CI files using Spectral. By adding support for!reference
, this update will allow Spectral to handle GitLab's YAML references properly, improving compatibility with GitLab CI configurations.Reference to the GitLab documentation: GitLab CI YAML Optimization Reference
Description
I have updated the
src/loader.ts
file to recognize the!reference
tag alongside the existing tags like!include
. The changes involve modifying the node kind and state when encountering!reference
to correctly parse and handle it as a scalar or reference node, based on its context. I have also updated theYAMLKind
enum insrc/yamlAST.ts
to include aREFERENCE_REF
value, allowing the AST parser to distinguish between different types of reference tags.How Has This Been Tested?
The changes have been tested locally by parsing multiple GitLab CI YAML files containing the
!reference
tag. These tests confirmed that the parser now properly recognizes and handles these tags without producing errors. Additionally, I have manually verified the behavior against Spectral rules that validate such files.Further automated tests will be implemented to cover a variety of cases where
!reference
tags are used in different contexts (e.g., scalar, sequence, mapping).Screenshot(s)/recording(s)
Not applicable.
Types of changes
Checklist