dorny / paths-filter

Conditionally run actions based on files modified by PR, feature branch or pushed commits
MIT License
1.98k stars 230 forks source link

Exclude few folders in one filter #200

Open oleksandr-kinship opened 10 months ago

oleksandr-kinship commented 10 months ago

Hey, have repo that include two folders, for which I don't want to run some steps, tried following:

      - uses: dorny/paths-filter@v2
        id: changes
        with:
          filters: |
            ga:
              - '!.github/**'
            infra:
              - '!infrastructure/**'
            ga-infra:
              - '!.github/**'
              - '!infrastructure/**'`

Got this results:

Results:
Filter ga = true
  Matching files:
  infrastructure/src/resources/liquibase.ts [modified]
  src/main/java/com/.../file.java [modified]
Filter infra = true
  Matching files:
  .github/workflows/document_tests.yml [modified]
  src/main/java/com/.../file.java [modified] [modified]
Filter ga-infra = true
  Matching files:
  .github/workflows/document_tests.yml [modified]
  infrastructure/src/resources/liquibase.ts [modified]
  src/main/java/com/.../file.java [modified] [modified]

ga and infra looks good, expected that some folders not match, but in ga-infra I expected to see only src/main/java/com/.../file.java because other excluded Can you point me what I did wrong or this not possible to implement, tried to read picomatch not get answers ..

y-takebe commented 10 months ago

@oleksandr-kinship

I had the same problem recently, but it seems that the negation operator is not supported. Please also check the following related issue

I'd be happy if it's the same as GitHub's paths.

oleksandr-kinship commented 10 months ago

@oleksandr-kinship

I had the same problem recently, but it seems that the negation operator is not supported. Please also check the following related issue

I'd be happy if it's the same as GitHub's paths.

Thanks, it works for single rule but not in combination.. so I was tried another action, for me in general it's less comfortable, but at least it works fine so far, here is example

      - name: Get changes
        uses: tj-actions/changed-files@v38
        id: changes
        with:
          files_yaml: |
            non-infra:
              - '!.github/**'
              - '!infrastructure/**'

      - name: Log non-infra changes
        shell: bash
        run: |
          echo "Is there changes for non-infra: ${{ steps.changes.outputs.non-infra_any_changed}}"
          echo "List of all non-infra changed files: ${{ steps.changes.outputs.non-infra_all_changed_files }}"
Qix- commented 6 months ago

It appears that !foo is returning a list of files from the entire folder that do not match foo, instead of culling the existing filepaths from other lines. The underlying minimatch/picomatch libs are working as expected.

In our case, our filter was previously

- 'app-*/**'
- '!app-ui/**'

but I'm pretty sure that resulted in a union of:

resulting in a file list that includes everything in the folder as triggering a rebuild.

Instead, we changed to

- 'app-!(ui)/**'

which is what we wanted. That syntax is described on picomatch's docs, which is what this action uses.


Quick other note: make sure to put the strings in quotes since YAML treats *, ! and & and whatnot as special characters (anchors, tags, etc.)