dorny / paths-filter

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

Override option to set all Filters to true #204

Open TooManyCarbs opened 11 months ago

TooManyCarbs commented 11 months ago

I am using a changes job to construct a list of lambda names which is passed to a lambda deployment job using a matrix strategy.

There are some cases where we would like to run all lambda deployments, regardless of whether or not they have changed. If there were an option to essentially mock as if all filters have detected changes, that would make this scenario very easy to deal with.

Is there a way to do this? Grateful for any advice.

hilja commented 7 months ago

It would be nice if we could append a string in the commit message to skip all check. e.g. [skip changed check], or with a trailer skip-changed-check: true etc.

This is handy when tweaking CI.

hilja commented 7 months ago

Turns this was easy to implement, I had no idea you get access to the commit message from the github context: github.event.head_commit.message.

This example uses [skip checks], add it somewhere in the last commit message.

Something like this:

skipChanges:
  name: ⏭️ Skip changes check
  runs-on: ubuntu-22.04
  outputs:
    isSkip: ${{ steps.skip.outputs.skip }}
  steps:
    - id: skip
      run: |
        echo "skip=$(echo ${{ contains(github.event.head_commit.message, '[skip checks]') }})" >> $GITHUB_OUTPUT

changes:
  name: 🗂️ Check changed files
  runs-on: ubuntu-22.04
  needs: skipChanges
  # Add it in the condition
  outputs:
    foo:
      ${{ needs.skipChanges.outputs.isSkip && 'true' || steps.filter.outputs.foo }}
  steps:
    - uses: actions/checkout@v4.1.1
      with:
        fetch-depth: 20
    - uses: dorny/paths-filter@v3
      id: filter
      with:
        base: ${{ github.ref }}
        filters: |
          foo:
            - 'foo/**/*.(ts|tsx)'

# Use `needs.changes.outputs` like you would normally
typecheck:
  name: Typecheck foo
  needs: changes
  if: ${{ needs.changes.outputs.foo == 'true' }}
  runs-on: ubuntu-22.04
  steps:
    - uses: actions/checkout@v4.1.1
    - uses: wyvox/action-setup-pnpm@v3
      with:
        args: '-F=foo'
    - run: pnpm -F=foo run typecheck

That checks the latest commit but you can check all commits too:

contains(join(github.event.commits.*.message, ' '), '[skip checks]')