firecow / gitlab-ci-local

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

Cannot override CLI args that have default values using `.gitlab-ci-local-env` file #1233

Closed PigeonF closed 1 month ago

PigeonF commented 1 month ago

Minimal .gitlab-ci.yml illustrating the issue

---
job:
  image: docker.io/busybox
  script:
    - echo "Hello" > hello.txt
  artifacts:
    paths:
      - hello.txt

Compare the following ways to run gitlab-ci-local

  1. Using a CLI arg (this works as expected)
$ gitlab-ci-local --no-artifacts-to-source
$ ls hello.txt
"hello.txt": No such file or directory
  1. Using environment variable override (this works as expected)
$ GCL_ARTIFACTS_TO_SOURCE=false gitlab-ci-local
$ ls hello.txt
"hello.txt": No such file or directory
  1. Using an environment variable override in .gitlab-ci-local-env (this does not work)
$ cat .gitlab-ci-local-env
ARTIFACTS_TO_SOURCE=false
$ gitlab-ci-local
$ ls hello.txt
hello.txt

As far as I can tell, the issue is that the command line option gets a default value assigned in index.ts

https://github.com/firecow/gitlab-ci-local/blob/d44cedb180f718c4af09870809124d4b44546b03/src/index.ts#L213-L218

and then in argv.ts the value is only overriden if it was undefined before

https://github.com/firecow/gitlab-ci-local/blob/d44cedb180f718c4af09870809124d4b44546b03/src/argv.ts#L71-L73

This should apply to all command line options with a default value.

firecow commented 1 month ago

Yup, we cannot use yargs default values, when doing overrides like we do.