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
    filters: |
        - 'deploy/tf/**'      

- run: terraform apply ...
  if: == '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.

Join the 80/20 DevOps Newsletter

If you're an engineering leader or developer, you should subscribe to my 80/20 DevOps Newsletter. Give me 1 minute of your day, and I'll teach you essential DevOps skills. I cover topics like Kubernetes, AWS, Infrastructure as Code, and more.

Not sure yet? Check out the archive.

Unsubscribe at any time.