Skip to content
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

Add support for parsing !reference tag in GitLab CI YAML files #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

chussenot
Copy link

@chussenot chussenot commented Sep 12, 2024

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, the yaml-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 the YAMLKind enum in src/yamlAST.ts to include a REFERENCE_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

  • New feature (non-breaking change which adds functionality)

Checklist

  • This PR's code follows as closely as possible the coding style/guidelines of this project.
  • [] I have added error reporting and followed the error reporting guidelines.
  • I have updated any relevant documentation accordingly to reflect this PR's changes.
  • [] I have added automated tests (unit/integration/e2e/other) to cover my changes.
  • [] All new and existing tests pass locally (excluding flaky CI tests).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant