firecow / gitlab-ci-local

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

Preview validation fails because of the `needs.need.pipeline: null` and `needs.need.project: null` (actual master, not released yet) #1139

Closed e-picas closed 6 months ago

e-picas commented 6 months ago

Minimal .gitlab-ci.yml illustrating the issue

With the following YML:

my_job:
  script:
    - echo 'test'

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

I have the following --preview rendering:

$ 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
      pipeline: null
      project: null
  script:
    - echo 'test'

Which does not pass the ci/lint GitLab API route validation because needs.need.pipeline and needs.need.project can only be a string:

$ 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'

[
  "jobs:my_job2:needs:need config contains unknown keys: optional, pipeline",
  "jobs:my_job2:needs:need project should be a string",
  "jobs:my_job2:needs:need project can't be blank",
  "jobs:my_job2:needs:need ref should be a string",
  "jobs:my_job2:needs:need ref can't be blank"
]

Expected behavior

The needs.need.pipeline and needs.need.project should not be rendered if they do not have a (string) value.

I can see in the code it's quite a recent new feature: https://github.com/firecow/gitlab-ci-local/blame/master/src/data-expander.ts#L88. I think a simple verification of the existence of the value can be enough to fix this.

Host information

Ubuntu gitlab-ci-local master (not released for now)

firecow commented 6 months ago

Should

stages:
  - .pre
  - build
  - test
  - deploy
  - .post

be printed?

Right now the most complex form of objects are rendered in in --preview

e-picas commented 6 months ago

Hello @firecow yes, the stages can be displayed without breaking anything (as far as I know).