firecow / gitlab-ci-local

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

feat: implement array input type #1261

Closed ANGkeith closed 2 weeks ago

ANGkeith commented 3 weeks ago

implements https://docs.gitlab.com/ee/ci/yaml/inputs.html#array-type and some refactoring

resolve #1249

PigeonF commented 3 weeks ago

Nice 👍

I was looking into this yesterday, and one weirdness with array inputs is if you pass objects. I think that GitLab will probably change the behaviour for this (I have not gotten around to searching their issue tracker yet, to find out if this is a known "issue" EDIT: found this issue).

Assuming you have

# component.gitlab-ci.yml
---
spec:
  inputs:
    array:
      type: array
---
test_job:
  image: docker.io/library/busybox
  script:
    - echo '$[[ inputs.array ]]'
# .gitlab-ci.yml
---
include:
  - local: component.gitlab-ci.yml
    inputs:
      array:
        - foo: bar
        - baz: 2
          quux: something

You get a ruby formatted hashmap in the output

Executing "step_script" stage of the job script 00:01
Using docker image sha256:65ad0d468eb1c558bf7f4e64e790f586e9eda649ee9f130cd0e835b292bbc5ac for docker.io/library/busybox with digest docker.io/library/busybox@sha256:50aa4698fa6262977cff89181b2664b99d8a56dbca847bf62f2ef04854597cf8 ...
$ echo '[{:foo=>"bar"}, {:baz=>2, :quux=>"something"}]'
[{:foo=>"bar"}, {:baz=>2, :quux=>"something"}]
ANGkeith commented 3 weeks ago

You get a ruby formatted hashmap in the output

it seemed like it's the intended behavior, https://gitlab.com/gitlab-org/gitlab/-/issues/407176#questions

In the current MR https://github.com/firecow/gitlab-ci-local/pull/1261/files#diff-abe2818e9c29aadf84401cb7ef8286c7cbce9253eba09f6fa52e22ca4e57b17eR317, gitlab-ci-local would behave slightly differently but i'm lazy and will leave it to be fixed for another day

PigeonF commented 3 weeks ago

I fully agree with your comment in https://github.com/firecow/gitlab-ci-local/blob/fac59de861c2ee4f7d7f8cbf208908d84b6cb2e2/src/parser.ts#L316 I think the effort required is not worth it (especially because you would have to deal with properly escaping stuff). I imagine gitlab will change this in the future to output valid yaml/json instead.

sonarcloud[bot] commented 3 weeks ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
85.4% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

firecow commented 2 weeks ago

@ANGkeith So this feature isn't implemented on Gitlab's side yet ?

ANGkeith commented 2 weeks ago

@ANGkeith So this feature isn't implemented on Gitlab's side yet ?

it is implmented on gitlab side already as per https://docs.gitlab.com/ee/ci/yaml/inputs.html#array-type