dorny/paths-filter is a GitHub Action that checks which files changed in a pull request or push. It sets a true/false output for each named filter, so later steps or jobs run only when relevant code changed. This guide explains the examples above, fixes the bugs in them (including an exclusion pattern that never excludes anything), and adds complete workflows for v3 of the action.
Example 1 – Using paths-filter in Seprate file
Example 2
setup-env:
runs-on: ${{ github.event.pull_request.user.login == 'dependabot[bot]' && 'arc-runners-dependabot' || 'arc-runners-platform' }}
if: ${{ !contains(github.event.pull_request.labels.*.name, 'gha-skip-preclean') }}
timeout-minutes: 20
steps:
- name: Clean environment
run: |
kubectl delete ns ${{ env.NAMESPACE }} || true
- name: Checkout Platform
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Enable build based on the changes
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
build:
- 'cpp/**'
- 'docker/**'
- 'golang/**'
- 'jenkins/**'
- 'portal/**'
- 'supd2/**'
- 'tools/**'
- '!tools/dir1/**'
- '!tools/dir2/**'
- '!**/*.jpeg'
- '!**/*.md'Code language: JavaScript (javascript)
Example 3
Example 4
Example 5
https://gist.github.com/devops-school/9f911252a34f632ad96f10a8454b557dReference
Why use paths-filter instead of on.paths
GitHub Actions already supports on.push.paths and on.pull_request.paths, but those filters decide whether the whole workflow runs. paths-filter runs inside the workflow, so one workflow can decide separately for each job or step. This matters in monorepos and wherever branch protection depends on required checks.
| Need | on.paths | dorny/paths-filter |
|---|---|---|
| Skip the entire workflow when nothing relevant changed | Yes | Possible, but more work |
| Run different jobs or steps for different folders | No | Yes, one output per filter |
| Required status checks when the workflow is skipped | The check stays pending and blocks the merge | Jobs report as skipped and the check can still pass |
| React only to added, modified or deleted files | No | Yes, for example added|modified: '**/*.py' |
| Get the list of matching files for linters | No | Yes, with list-files |
| Build a matrix from the changed packages | No | Yes, with the changes output |
Inputs and outputs you will actually use
| Input | Purpose |
|---|---|
filters | Inline YAML, or the path to a YAML file in the repository (as in Example 1) |
token | Defaults to github.token. On pull requests it is used to read the changed files from the GitHub API |
base / ref | The git refs to compare. You need base for events such as workflow_dispatch or schedule |
list-files | none (the default), csv, json, shell or escape. Adds a <filter>_files output |
predicate-quantifier | some (the default) or every. Controls how the patterns inside one filter are combined |
working-directory | The directory where git commands run, for push events |
initial-fetch-depth | How many commits to fetch at first when the action has to find the merge base |
| Output | Value |
|---|---|
<filter> | 'true' or 'false' as a string |
<filter>_count | Number of changed files that match the filter |
<filter>_files | Matching files, in the list-files format (only when list-files is enabled) |
changes | JSON array of the names of every filter that matched, for example ["backend"] |
Note: Outputs are strings. Always compare against 'true', as in steps.filter.outputs.backend == 'true'. Do not rely on a bare steps.filter.outputs.backend: the string 'false' is not empty, so the expression treats it as truthy.
How the change list is built depends on the event. On pull_request, the action calls the GitHub API, so checkout is optional, but the job needs pull-requests: read. On push, it uses git, so you must run actions/checkout first. On a feature branch it compares against the merge base with the default branch. On the default branch or another long-lived branch, it compares against the commit before the push.
A complete job-level workflow
The gist examples are fragments, and examle.yaml mixes two snippets with broken indentation, so it does not parse. The workflow below is complete. One job detects changes and exposes them as job outputs. The other jobs read those outputs through needs.
name: ci
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
pull-requests: read
jobs:
changes:
runs-on: ubuntu-latest
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
steps:
- uses: actions/checkout@v4 # required for push events
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
backend:
- 'backend/**'
- 'requirements*.txt'
frontend:
- 'frontend/**'
- 'package*.json'
backend:
needs: changes
if: needs.changes.outputs.backend == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "run backend build and tests here"
frontend:
needs: changes
if: needs.changes.outputs.frontend == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "run frontend build and tests here"Code language: PHP (php)
The outputs: mapping on the changes job is required. Step outputs are not visible to other jobs until you map them to job outputs. If you forget this, needs.changes.outputs.backend is an empty string and the dependent jobs never run. The files-changed job in Example 1 does this mapping correctly.
Exclusions and predicate-quantifier: fixing Example 2
Example 2 has two problems. First, the step and the pattern list are indented with tab characters. YAML does not allow tabs for indentation, so GitHub rejects the workflow file. Second, there is a logic bug. With the default predicate-quantifier: 'some', a file matches a filter if it matches any one pattern in the list. A negated pattern such as '!**/*.md' matches every file that is not Markdown. A change to README.md still matches '!tools/dir1/**', so build comes out true for almost every change, and the exclusions do nothing.
To fix this, set predicate-quantifier: 'every', so a file must match all the patterns. Then put the included folders into one brace pattern, because a single file cannot be inside both cpp/ and docker/.
setup-env:
runs-on: ${{ github.event.pull_request.user.login == 'dependabot[bot]' && 'arc-runners-dependabot' || 'arc-runners-platform' }}
if: ${{ !contains(github.event.pull_request.labels.*.name, 'gha-skip-preclean') }}
timeout-minutes: 20
outputs:
build: ${{ steps.filter.outputs.build }}
steps:
- name: Clean environment
run: kubectl delete ns "${{ env.NAMESPACE }}" --ignore-not-found
- name: Checkout Platform
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Enable build based on the changes
uses: dorny/paths-filter@v3
id: filter
with:
predicate-quantifier: 'every'
filters: |
build:
- '{cpp,docker,golang,jenkins,portal,supd2,tools}/**'
- '!tools/dir1/**'
- '!tools/dir2/**'
- '!**/*.jpeg'
- '!**/*.md'Code language: JavaScript (javascript)
predicate-quantifierapplies to every filter in that step. If other filters needsomebehaviour, put them in a separatepaths-filterstep.--ignore-not-foundreplaces|| true. It still lets a realkubectlerror, such as a bad kubeconfig, fail the step instead of hiding it.- The
buildjob output lets later jobs useif: needs.setup-env.outputs.build == 'true'. - The
runs-onexpression selects a runner label for Dependabot pull requests. Runner scale sets like these are explained in What Is GitHub Actions Runner Controller?.
Filters in a separate file, anchors and change types
Example 1 sets filters: .github/file-filters.yml. The action then reads the filters from a file in the repository, so the repository must be checked out first. The file file-filters.yml uses standard YAML anchors (&backend_src) and aliases (*backend_src) to build larger filters from smaller ones. The action flattens the nested lists, so backend_all contains every pattern from backend_src plus its own patterns.
You can also restrict a pattern to certain change types: added, modified, deleted, renamed, copied or unchanged. Combine them with |, for example added|modified: '**/*.py'. This is how the Sentry lint job avoids linting files that were deleted.
Example 1 still pins getsentry/paths-filter, which is a fork of v2, and actions/checkout v2, and it runs on ubuntu-20.04. GitHub has retired that hosted runner image. Older action majors also run on Node.js runtimes that GitHub has deprecated. For a new workflow, use dorny/paths-filter@v3, a current actions/checkout major and ubuntu-latest or ubuntu-24.04. If your security policy requires it, pin each action to a full commit SHA, as Sentry does.
Passing changed files to linters safely
The py_linter.yml gist puts ${{ steps.filter.outputs.py_scripts_filter_files }} directly into a run script. File names in a pull request are controlled by the person who opened it. Placing them directly into a script is a script-injection risk, and a very long list can exceed the shell's argument limit. A safer pattern is to request JSON, pass it through an environment variable and expand it with jq:
- uses: dorny/paths-filter@v3
id: filter
with:
list-files: json
filters: |
py:
- added|modified: '**/*.py'
- name: Lint changed Python files
if: steps.filter.outputs.py == 'true'
env:
PY_FILES: ${{ steps.filter.outputs.py_files }}
run: |
echo "Linting ${{ steps.filter.outputs.py_count }} file(s)"
echo "$PY_FILES" | jq -r '.[]' | xargs -r -d '\n' python -m black --checkCode language: PHP (php)
Also, py_linter.yml sets on.paths: "**.py" and also runs paths-filter. That combination is valid: the trigger skips runs that do not touch Python files, and the filter supplies the file list. Remember, though, that the on.paths trigger causes the pending required-check problem described in the first section.
Dynamic matrix from the changes output
Example 4 builds a matrix from the changes output. The idea is sound, but there are two problems. First, the pattern src/package1 matches only a file at exactly that path, not the files inside the folder, so you need src/package1/**. Second, when no filter matches, changes is [], and a matrix with no values fails the workflow. Guard the job with an if:
jobs:
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
packages: ${{ steps.filter.outputs.changes }}
steps:
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
package1: 'src/package1/**'
package2: 'src/package2/**'
build:
needs: changes
if: needs.changes.outputs.packages != '[]'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
package: ${{ fromJSON(needs.changes.outputs.packages) }}
steps:
- uses: actions/checkout@v4
- run: make -C "src/${{ matrix.package }}" buildCode language: JavaScript (javascript)
Note: This job has no checkout step before paths-filter, so it only works on pull_request events. If the workflow also runs on push, add actions/checkout before the filter step.
Required status checks with skipped jobs
When a job is skipped by its if condition, GitHub reports it as successful for branch protection. However, check names change with matrix values, and keeping a long list of required checks up to date is fragile. Example 1 solves this with one aggregator job, backend-required-check. Make that job the only required check:
ci-ok:
if: always()
needs: [changes, backend, frontend]
runs-on: ubuntu-latest
steps:
- name: Fail if any dependency failed or was cancelled
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: exit 1Code language: PHP (php)
Without if: always(), the aggregator job would itself be skipped whenever a job it depends on fails, which hides the failure. For more on configuring required checks, see GitHub Repository Settings Essentials.
Common errors and fixes
| Symptom | Cause | Fix |
|---|---|---|
| Workflow file is invalid, with a YAML error | Tabs or mixed indentation, as in Example 2 | Indent with spaces only, and run yamllint locally |
Filter is always true | Negated patterns with the default some quantifier | Use predicate-quantifier: 'every' and a brace pattern for the included folders |
Filter is never true | Pattern without /**, or paths written relative to the wrong directory | Use dir/**. Patterns are matched against paths from the repository root |
| Dependent job never runs | Step outputs not mapped to job outputs: | Add an outputs: block to the detection job |
Resource not accessible by integration | Token cannot read the pull request | Grant pull-requests: read |
| Git errors on push events | No checkout before the filter | Add actions/checkout before paths-filter |
Error saying base is required | Event with no base branch, such as workflow_dispatch or schedule | Set base: explicitly, for example base: main |
| Matrix error when nothing changed | fromJSON('[]') gives an empty matrix | Add if: needs.changes.outputs.packages != '[]' |
To debug a filter, open the step log. The action prints the list of changed files and the result of each filter. You can also print steps.filter.outputs.<name>_count in a later step.
Frequently asked questions
Does dorny/paths-filter need actions/checkout?
Not for pull_request events, as long as the filters are inline. In that case it reads the changed files from the GitHub API and needs pull-requests: read. For push events, or when filters points to a file in the repository, you must run actions/checkout first.
How do I exclude files or folders in paths-filter?
Add negated patterns such as '!**/*.md' and set predicate-quantifier: 'every', so a file must match all patterns. With the default some, a negated pattern matches almost every file, so the filter comes out true for nearly any change.
Why is my paths-filter output always false in another job?
Step outputs are not shared across jobs automatically. Map them under the detection job's outputs: key, then read them with needs.<job>.outputs.<name> == 'true'.
What is the difference between on.paths and paths-filter?
on.paths decides whether the whole workflow is triggered. paths-filter runs inside the workflow and can switch individual jobs or steps on or off. Because the workflow always runs, required status checks are still reported.
Which version of paths-filter should I use?
Use dorny/paths-filter@v3. It runs on a current Node.js runtime and supports predicate-quantifier. Older v2 tags and forks run on Node.js versions that GitHub Actions has deprecated.
Related tutorials
- GitHub Actions Essentials โ Learn CI/CD in 2 Hours
- GitHub Actions โ CI/CD Automation & DevOps Engineering
- What Is GitHub Actions Runner Controller?
- 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