How to Trigger Only on Changed Paths in GitHub Actions
A paths filter limits triggering to commits that touch files matching your globs, so each service builds only when its code moves.
Add paths: under the push or pull_request event to run only on matching changes, or paths-ignore: to skip changes that touch only certain files.
Steps
- Add
paths:underon.pushwith the directories that matter. - Use
paths-ignore:instead to skip docs-only pushes. - Keep one workflow per service so each has its own filter.
Workflow
.github/workflows/api.yml
on:
push:
paths:
- 'services/api/**'
- '!services/api/**/*.md'
jobs:
build-api:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: cd services/api && npm ci && npm testGotchas
- You cannot combine
pathsandpaths-ignorein the same event; pick one and use negations. - A skipped path-filtered required check can block a merge; add a placeholder job that always passes.
Related guides
How to Trigger a Workflow Only When a File Glob Matches in GitHub ActionsFire a GitHub Actions workflow only when changed files match a specific glob, such as SQL migrations or Terra…
How to Trigger a Workflow on Push to Specific Branches in GitHub ActionsRun a GitHub Actions workflow only when commits are pushed to named branches using on.push.branches, so featu…