How To Only Run GitHub Actions Steps If Files Change

If you want to conditionally run a GitHub Action step or job when files change, then you’ll want to use the paths changes filter action.

You can’t use GitHub’s built-in path filters because it only operates on entire workflows.

Here’s what it looks like:

- uses: dorny/paths-filter@v3
  id: changes
  with:
    filters: |
      tf:
        - 'deploy/tf/**'      

- run: terraform apply ...
  if: steps.changes.outputs.tf == 'true'

Like the above example, my most common use case for path filters is only to run my Terraform when there are changes.

Using path filters shaves off a minute or two off of my pipelines, which reduces cycle time and costs.


Master GitHub Actions with a Senior Infrastructure Engineer

As a senior staff infrastructure engineer, I share exclusive, behind-the-scenes insights that you won't find anywhere else. Get the strategies and techniques I've used to save companies $500k in CI costs and transform teams with GitOps best practices—delivered straight to your inbox.

Not sure yet? Check out the archive.

Unsubscribe at any time.