GitHub Actions can skip a workflow when a push or pull request changes no relevant files. You do this with the paths or paths-ignore filters on the trigger. This page explains the example above and fixes it: GitHub rejects a workflow that sets both paths and paths-ignore on the same event. It then covers negation patterns, testing, and the required-status-check problem that path filters cause.
Explanation:
on.push.paths: Specifies the directories/files that should trigger the workflow. In this case, changes in thesrc/orscripts/directories will trigger the build.on.push.paths-ignore: Specifies the directories/files that should not trigger the workflow. If changes are only in thedocs/ortests/directories, the build will be skipped.
How path filters decide whether a workflow runs
When a push or pull_request event fires, GitHub compares the list of changed files against the path filter on that event. If the event also has a branches filter, both filters must match before the workflow starts.
| Filter | Workflow runs when | Typical use |
|---|---|---|
paths | At least one changed file matches a pattern and a later ! pattern does not exclude it | Build only when src/ or scripts/ changes |
paths-ignore | At least one changed file does not match any pattern | Build on everything except docs-only changes |
paths with ! patterns | A changed file matches a positive pattern that a later negative pattern does not cancel | Include src/ but ignore Markdown files inside it |
Patterns are globs. * matches any characters except /, and ** matches across directory levels. So src/* matches only files directly inside src/, while src/** matches everything below it. Always quote patterns in YAML, because * and ! have special meanings there.
Corrected workflow
The gist above defines paths and paths-ignore under the same push event. GitHub does not allow this and marks the workflow file as invalid with an error saying that you may not define both paths and paths-ignore for the same event. The workflow never runs. The fix is to keep only paths and add exclusions as ! patterns inside the same list.
name: Conditional Build
on:
push:
branches:
- main
paths:
- 'src/**'
- 'scripts/**'
- 'package.json'
- 'package-lock.json'
- '.github/workflows/conditional-build.yml'
# Exclusions must come AFTER the patterns they override
- '!src/**/*.md'
pull_request:
branches:
- main
paths:
- 'src/**'
- 'scripts/**'
- 'package.json'
- 'package-lock.json'
- '.github/workflows/conditional-build.yml'
- '!src/**/*.md'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Node.js
uses: actions/setup-node@v5
with:
node-version: '22'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run build
run: npm run buildCode language: PHP (php)
- The
docs/andtests/exclusions from the original are gone. Oncepathslists onlysrc/andscripts/, a change limited todocs/ortests/cannot match anyway. package.json, the lockfile and the workflow file itself are included, so dependency upgrades and pipeline edits also trigger a build.'!src/**/*.md'shows the correct way to exclude files: put a negative pattern after the positive pattern it overrides. Order matters. A positive pattern placed after a negative one adds the matching files back.- The
pull_requesttrigger has its own filter, so pull requests get the same treatment as pushes tomain. npm ciinstalls exactly what the lockfile specifies, andcache: 'npm'reuses the npm cache between runs.
Note: Node.js 16 reached end of life in 2023, and runners have stopped supporting actions that run on old Node runtimes. Use a current LTS release of Node.js for your build, and current major versions of actions/checkout and actions/setup-node.
Using paths-ignore on its own
If you want to build on almost every change and skip only documentation-style edits, paths-ignore is simpler than a long paths list. Use it on its own, never together with paths on the same event.
on:
push:
branches:
- main
paths-ignore:
- 'docs/**'
- '**/*.md'
- '.github/ISSUE_TEMPLATE/**'Code language: JavaScript (javascript)
With this filter, a commit that touches only docs/guide.md is skipped. A commit that touches docs/guide.md and src/app.js still runs, because one changed file falls outside the ignore list.
Testing the filter
- Commit the workflow to
.github/workflows/conditional-build.ymlonmain. The workflow file is in thepathslist, so this commit triggers a run. - Change a file only under
docs/and push. No new run should appear in the Actions tab. - Change a file under
src/and push. A new Conditional Build run should start. - Change only a Markdown file under
src/and push. The!src/**/*.mdexclusion should prevent a run. - Confirm the results from the terminal with GitHub CLI, as shown below.
gh run list --workflow conditional-build.yml --limit 5
# Example output
# STATUS TITLE WORKFLOW BRANCH EVENT ID ELAPSED AGE
# โ Update app logic Conditional Build main push 1234567890 42s 2mCode language: PHP (php)
If gh is not installed yet, see How to Install GitHub CLI (gh).
Common problems and fixes
| Symptom | Cause | Fix |
|---|---|---|
| Workflow never runs and the Actions tab reports an invalid workflow file | Both paths and paths-ignore are set on one event | Keep one of them and use ! patterns for exclusions |
| Pull request stuck on "Expected โ Waiting for status to be reported" | A required status check comes from a workflow that path filtering skipped | Use job-level filtering (next section) so the check always reports |
| Exclusion has no effect | The ! pattern comes before the positive pattern it should override | Move negative patterns to the end of the list |
src/* misses nested files | * does not cross / | Use src/** |
| Workflow runs on tag pushes despite filters | Path filters are not evaluated for tag pushes | Restrict triggers with branches or handle tags in a separate workflow |
| Large pushes behave unexpectedly | GitHub evaluates only a limited number of changed files (300) when applying path filters | Keep pushes smaller, or run a job-level check that computes the diff itself |
Job-level filtering for required checks and monorepos
Trigger-level filters skip the whole workflow, so no status is reported. If branch protection requires that check, the pull request cannot be merged. A common workaround is to let the workflow always start and decide per job. A job skipped through if: reports as skipped, and GitHub treats a skipped job as passing for required checks. The third-party dorny/paths-filter action is widely used for this. Review it like any other third-party action, and consider pinning it to a commit SHA.
on:
pull_request:
branches: [main]
jobs:
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
app: ${{ steps.filter.outputs.app }}
steps:
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
app:
- 'src/**'
- 'scripts/**'
- 'package*.json'
build:
needs: changes
if: needs.changes.outputs.app == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npm run buildCode language: JavaScript (javascript)
In a monorepo, the same approach scales: define one filter per service (for example api and web) and attach a separate job to each output.
Best practices
- Include the workflow file and dependency manifests in
paths, or pipeline and dependency changes will go untested. - Avoid path filters on security scans and release workflows that must always run.
- Keep the
pushandpull_requestfilters identical so the two triggers don't drift apart. - Add
workflow_dispatch:so you can run a filtered workflow manually when needed. - Set a minimal
permissions:block on each workflow.
For a broader introduction to triggers, jobs and runners, see GitHub Actions Essentials โ Learn CI/CD in 2 Hours.
Frequently asked questions
Can I use paths and paths-ignore together in GitHub Actions?
Not on the same event. GitHub rejects the workflow file. Use paths with ! negation patterns instead, or use paths on one event and paths-ignore on another.
Why does my pull request wait forever for a required check when the workflow was skipped?
A workflow that trigger-level path filters skip never reports a status, so the required check stays pending. Run the workflow on every pull request and skip individual jobs with if: conditions. Skipped jobs satisfy required checks.
Do path filters work for workflow_dispatch or scheduled runs?
No. paths and paths-ignore apply to push, pull_request and pull_request_target. Manual and scheduled runs always start.
What is the difference between src/* and src/** in a path filter?
src/* matches only files directly inside src/. src/** matches all files at any depth below src/.
Does the order of patterns in paths matter?
Yes. Patterns are evaluated in order, so a ! exclusion only takes effect if it comes after the positive pattern it should override.
Related tutorials
- GitHub Actions Essentials โ Learn CI/CD in 2 Hours
- GitHub Actions โ CI/CD Automation & DevOps Engineering
- GitHub Repository Settings Essentials โ 2-Hour Tutorial
- More GitHub tutorials
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals