Guides / Filter by branch, tag and path
Filter by branch, tag and path
Filters decide what runs for an event. Filters on on: decide whether
a workflow starts at all.
Filters on a workflow entry decide whether one job in a started workflow runs. This guide uses both to set up a monorepo with an API and a web app.
Prerequisites
Section titled “Prerequisites”- A repository with
api/andweb/directories, or your own layout.
-
Give each part its own workflow with a path filter
Section titled “Give each part its own workflow with a path filter”pathsstarts a workflow only when a changed file matches. Put shared files in both lists:.hatchrun/config.yml jobs:api-test:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v5- run: make -C api testweb-test:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v5- run: npm --prefix web ci- run: npm --prefix web testworkflows:api:on:push:branches: [main]paths: ['api/**', 'go.mod']pull_request:paths: ['api/**', 'go.mod']jobs:- api-testweb:on:push:branches: [main]paths: ['web/**', 'package-lock.json']pull_request:paths: ['web/**', 'package-lock.json']jobs:- web-testA pull request that touches only
web/startsweband notapi. -
Skip docs-only changes
Section titled “Skip docs-only changes”paths-ignoreis the inverse. The workflow starts unless every changed file is ignored:.hatchrun/config.yml jobs:test:runs-on: ubuntu-lateststeps:- run: make testworkflows:ci:on:pull_request:paths-ignore: ['docs/**', '**.md']jobs:- testA trigger takes
pathsorpaths-ignore, never both. -
Release on tags
Section titled “Release on tags”A push filter with only
tagsstarts on tag pushes and never on branch pushes:.hatchrun/config.yml jobs:release:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v5- run: ./release.sh "$GITHUB_REF_NAME"workflows:release:on:push:tags: ['v[0-9]+.[0-9]+.[0-9]+']jobs:- release[0-9]+means one or more digits, sov1.2.3andv10.0.1match andv1.2.3-rc1does not. -
Run one job only on main
Section titled “Run one job only on main”In a workflow that starts for every branch,
brancheson an entry limits one job:.hatchrun/config.yml jobs:test:runs-on: ubuntu-lateststeps:- run: make testpublish-docs:runs-on: ubuntu-lateststeps:- run: make docs-publishworkflows:ci:on:push: {}jobs:- test- publish-docs:requires: [test]branches: [main]On a push to
feature/x, the run planstestonly. -
Validate
Section titled “Validate”Terminal window hatchrun validatevalidatechecks the filters’ syntax and plans each workflow for the branchmain. It cannot tell which events will match.
How patterns match
Section titled “How patterns match”| Pattern | Matches |
|---|---|
main |
Only main |
release/* |
release/1.0, not release/1.0/hotfix |
release/** |
Everything under release/ |
!release/**-alpha |
Excludes what an earlier pattern included |
**.md |
Any path ending in .md, in any directory |
Patterns apply in order and the last one that matches decides. A name no pattern matches does not pass. The full rules are in Triggers and filter patterns.
Path filter rules
Section titled “Path filter rules”- Only the first 300 changed files are checked. A change past the first 300 does not start a workflow.
- When the list of changed files is empty or unknown, path filters pass.
- Tag pushes skip path filters.