How to Run Only on Changed Paths in GitHub Actions
A paths filter limits triggering to commits that touch the directories you care about.
Add paths: (or paths-ignore:) under the push/pull_request event. The workflow runs only when a changed file matches.
Steps
- Add
paths:globs underon.pushandon.pull_request. - Use
paths-ignore:for the inverse (docs-only changes). - Keep filters per workflow so each service builds independently.
Workflow
.github/workflows/api.yml
on:
push:
paths:
- 'services/api/**'
- '.github/workflows/api.yml'
jobs:
build-api:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: cd services/api && npm ci && npm testGotchas
- A skipped path-filtered required check can block merges; pair with a passing placeholder job.
- paths filters apply to push and pull_request, not to schedule or dispatch.
Related guides
How to Run a Job Only on Main in GitHub ActionsRestrict a GitHub Actions job to the main branch with an if condition on github.ref, so deploys and releases…
How to Dynamically Generate a Matrix in GitHub ActionsBuild a GitHub Actions matrix at runtime by emitting JSON from one job and feeding it to a downstream matrix…