firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.03k stars 115 forks source link

`default` is incorrectly applied to shared YAML references #1277

Closed hverlin closed 1 day ago

hverlin commented 3 days ago

Minimal .gitlab-ci.yml illustrating the issue

---
default:
  cache:
    key: 'my-key'
    paths:
      - my-file

.some-shared-yaml:
  if: "$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH"

my-job:
  script: 'echo test'
  rules:
    - !reference [.some-shared-yaml]

fails validation.

Invalid .gitlab-ci.yml configuration!
        • 'cache' property is not expected to be here at my-job.rules.0
        • '0' property type must be string at my-job.rules.0

Indeed, gitlab-ci-local generates an invalid internal pipeline definition image

stages:
  - .pre
  - build
  - test
  - deploy
  - .post
default:
  cache:
    key: my-key
    paths:
      - my-file
.some-shared-yaml: &ref_0
  if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
  cache:
    - &ref_1
      key: my-key
      paths:
        - my-file
      policy: pull-push
      when: on_success
my-job:
  script:
    - echo test
  rules:
    - *ref_0
  cache:
    - *ref_1

Expected behavior image

image

The expected behavior is that the shared-yaml object should not extend default as it's not a job actually:

.some-shared-yaml:
  if: "$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH"

Additional context

This issue was not an issue before json-schema-validation got introduced, as using --json-schema-validation=false does run the job correctly

❯ gcl my-job --json-schema-validation=false
parsing and downloads finished in 49 ms.
[19:45:42 1.45 ms] my-job starting shell (test)
[19:45:42 8.31 ms] my-job $ echo test
[19:45:42 8.48 ms] my-job > test
[19:45:42 9.27 ms] my-job finished in 9.27 ms

 PASS  [9.27 ms] my-job