firecow / gitlab-ci-local

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

`include:local:inputs` cannot include the same file multiple times #1121

Closed PigeonF closed 5 months ago

PigeonF commented 5 months ago

I was testing out the changes from #1115, but it looks like you cannot include the same file multiple times, even though it might be desirable.

Minimal .gitlab-ci.yml illustrating the issue

Given the following template.gitlab-ci.yml

# template.gitlab-ci.yml
---
spec:
  inputs:
    name:
      type: string
---
"$[[ inputs.name ]]":
  image: busybox:latest
  script:
    - echo "Hello from $[[ inputs.name ]]"

The following .gitlab-ci.yml works as expected

# .gitlab-ci.yml
---
include:
  - local: template.gitlab-ci.yml
    inputs:
      name: Foo
$ gitlab-ci-local --list
name  description  stage   when        allow_failure  needs
Foo               test    on_success  false  

But the following .gitlab-ci.yml only shows Foo, but there should be both Foo and Bar.

# .gitlab-ci.yml
---
include:
  - local: template.gitlab-ci.yml
    inputs:
      name: Foo
  - local: template.gitlab-ci.yml
    inputs:
      name: Bar
$ gitlab-ci-local --list
name  description  stage   when        allow_failure  needs
Foo               test    on_success  false  

I think the issue is the way excludedGlobs is built up when encountering include (since this means the file is ignored the second time the include is encountered).

https://github.com/firecow/gitlab-ci-local/blob/0e3602b530bbad48c96006f589022095ae6b58a6/src/parser-includes.ts#L72-L77