feat(linter): propagate workflow:rules:variables: into job rule evaluation
workflow:rules: can define variables: on matching rules (GitLab CI 15.0+).
These variables are now injected into the evaluation context before job
rules:if: expressions are evaluated, making patterns like:
workflow:
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
variables:
DEPLOY_TARGET: production
deploy:
rules:
- if: '$DEPLOY_TARGET == "production"'
work correctly with glint check --branch main.
Changes:
- model.Rule: add Variables map[string]any field (yaml:"variables")
- cicontext.Context: add pinned map tracking which vars must not be
overwritten; New() pins all shortcut and --var variables; add
Inject(key, value) which writes only when key is not pinned
- cicontext.ExtractStringVars: shared helper that converts map[string]any
variable blocks (plain string or {value:...} form) to map[string]string
- cicontext.EvalWorkflow: returns (bool, map[string]string) — the vars of
the matching workflow rule alongside the runs/no-runs result
- cmd/glint/main.go: enrichContext() injects pipeline-level variable
defaults then workflow-rule variables before printContext; applied in
both cmdCheck and cmdGraph
Injection priority (highest wins):
--var CLI overrides > --branch/--tag/--source shortcuts
> workflow-rule variables > pipeline variables: defaults
Adds 15 unit tests (TestEvalWorkflow, TestContextInject,
TestExtractStringVars, TestWorkflowVarsJobEval) and a testdata fixture
(workflow_vars.yml) validated across four branch contexts.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -65,6 +65,14 @@ tasks:
|
||||
ignore_error: false
|
||||
- cmd: ./{{.BINARY}} check --branch feat/x testdata/rules_if_expr.yml
|
||||
ignore_error: false
|
||||
- cmd: ./{{.BINARY}} check testdata/workflow_vars.yml
|
||||
ignore_error: false
|
||||
- cmd: ./{{.BINARY}} check --branch main testdata/workflow_vars.yml
|
||||
ignore_error: false
|
||||
- cmd: ./{{.BINARY}} check --branch develop testdata/workflow_vars.yml
|
||||
ignore_error: false
|
||||
- cmd: ./{{.BINARY}} check --branch feat/x testdata/workflow_vars.yml
|
||||
ignore_error: false
|
||||
- cmd: ./{{.BINARY}} check samba-testdata/.gitlab-ci.yml
|
||||
ignore_error: false
|
||||
- cmd: ./{{.BINARY}} check samba-testdata/.gitlab-ci-coverage.yml
|
||||
|
||||
Reference in New Issue
Block a user