dorny / paths-filter

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

How to get intuitive usage when mixing file paths and ignore paths? #184

Open ross-nordstrom opened 1 year ago

ross-nordstrom commented 1 year ago

I found when I use "exclude paths", then my filter always produces a false positive causing my workflow to do the wrong thing.

Example:

      - uses: dorny/paths-filter@v2
        id: services
        with:
          filters: |
            ui:
              - 'ui/**'
              - '!ui/README.md'
              - '!ui/cypress/**'

I see this is "expected" in the docs: image

Use Case

I'm using this for a build matrix to only build services with code changes. I'm making use of the slick .changes property you produce for that:

  check-run-flags:
    outputs:
      services: ${{ steps.services.outputs.changes }}
  build:
    needs:
      - check-run-flags
    strategy:
      matrix:
        # See: https://stackoverflow.com/a/65434401/18401629
        node: ${{ needs.check-run-flags.services }}

Workaround

To make this work, I've switched my filters to ONLY use "include paths."

          filters: |
            ui:
              - 'ui/package*.json'
              - 'ui/angular.json'
              - 'ui/Dockerfile'
              - 'ui/Dockerfile'
              - 'ui/nginx.conf'
              - 'ui/src/**'
              - 'ui/ui/**/*.{yml,yaml}'

Expectation

When ! paths (exclude paths) are in the filter, the filter should be true iff any(include_paths) && all(exclude_paths).

Maybe my expectation is actually possible, and I'm just missing an option somewhere??

makenosound commented 1 year ago

I have exactly the same use-case described here, and would love to see it as a native option in the action.

ja-leo commented 1 year ago

same here, it would be great to see this working with the excludes flag

francisInfact commented 1 year ago

Also have the same issue - expectation would be that the filter would be true if all rules match.

DavidVaness commented 7 months ago

I ran into this today, really cumbersome for us because I have 2 files per app per filter I need to ignore (package.json & CHANGELOG.md) in our monorepository. The consequence of targeting all subdirectories and files to ignore these, is a bit problematic because it if a dev adds a new file / directory it will be ignored then, very brittle this approach.

@dorny any ideas how to solve this? 🙏🏼

hintron commented 2 months ago

I think this can be solved by changing the predicate-quantifier to 'every' (added in #224). The only problem is that it seems to be in a broken state, and the maintainer has not yet merged in the fix in #225.