firecow / gitlab-ci-local

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

fix(#1139): only add needs.need.pipeline and needs.need.project if the value exists #1140

Closed e-picas closed 4 months ago

e-picas commented 4 months ago

This fixes #1139

With the original YML in the ticket:

my_job:
  script:
    - echo 'test'

my_job2:
  needs:
    - my_job
  script:
    - echo 'test'

The rendering of the --preview option is now safe (no more needs.need.pipeline: null and needs.need.project: null):

$ node ../test-gitlab-ci-local/gitlab-ci-local/src/index.js --preview
---
stages:
  - .pre
  - build
  - test
  - deploy
  - .post
my_job:
  script:
    - echo 'test'
my_job2:
  needs:
    - job: my_job
      artifacts: true
      optional: false
  script:
    - echo 'test'

And it passes the ci/lint validation:

$ jq --null-input --arg yaml "$(node ../test-gitlab-ci-local/gitlab-ci-local/src/index.js --preview)" '.content=$yaml' \
| curl "https://gitlab.com/api/v4/projects/${PROJECT_ID}/ci/lint" \
    --header "Authorization: Bearer ${GITLAB_TOKEN}" \
    --header 'Content-Type: application/json' \
    --data @- | jq '.errors'

[]
firecow commented 4 months ago

@e-picas eslint is failing

e-picas commented 4 months ago

@firecow ok fixed