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 `image.docker.user: null` (actual master, not released yet) #1137

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:
  image: node:lts
  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:
  image:
    name: node:lts
    docker:
      user: null
  script:
    - echo 'test'

Which does not pass the ci/lint GitLab API route validation because docker.user can only be a string (and it's comprehensible, linux user null can not exist):

$ 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_job:image executor opts '/docker/user' must be a valid 'string'"
]

Expected behavior

The image.docker.user should not be rendered if it does not have a (string) value.

I can see in the code it's a recent new feature: https://github.com/firecow/gitlab-ci-local/blame/master/src/data-expander.ts#L166. 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)