paths-filter icon indicating copy to clipboard operation
paths-filter copied to clipboard

Force Push Unexpected Behavior

Open 4r7if3x opened this issue 1 year ago • 2 comments

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?

4r7if3x avatar May 25 '24 09:05 4r7if3x

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: ./**/*

ajgon avatar Jul 03 '24 15:07 ajgon

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: ./**/*

I just had the same issue and this looks reasonable but wouldn't you want to use git fetch origin/main && git rev-parse origin/main instead of ${{ github.ref }} to diff against?

Time0o avatar Jan 28 '25 10:01 Time0o