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

Force Push Unexpected Behavior #240

Open 4r7if3x opened 1 month ago

4r7if3x commented 1 month ago

I noticed the test would not work as expected when a force push happens, since the pushed commit is checked against itself, hence only the changes in comparison with the previous version of the commit are put into consideration. Although this looks to be the correct behavior, it can cause issues in some scenarios as I expected to detect the existence of the filter in the pushed commit.

Since I believe both behaviors can be beneficial to certain needs, can we have an additional option for this action to let us choose between the two? Or is it currently hackable through the current options?

ajgon commented 2 weeks ago

For everyone stumbling upon this problem (as I did), here is a workaround:


      - uses: actions/checkout@v4
        with:
          fetch-depth: 2  # important, to fetch previous commit

      # workaround for https://github.com/dorny/paths-filter/issues/240
      - id: previous-sha
        run: 'echo "sha=$(git rev-list -n 1 ${{ github.ref }}^)" >> $GITHUB_OUTPUT'

      - uses: dorny/paths-filter@v3
        id: filter
        with:
          base: "${{ steps.previous-sha.outputs.sha }}"
          filters: |
            myfilters: ./**/*