How to Run a Workflow Only on Tags in GitHub Actions
A tags filter on the push event makes a workflow fire only for tag pushes, not branch commits.
Set on.push.tags to a glob such as v*. The workflow ignores branch pushes and runs only when a matching tag arrives.
Steps
- Under
on.push, add atags:glob (e.g.v*.*.*). - Omit
branches:so branch pushes do not trigger this workflow. - Read the tag from
github.ref_nameinside the job.
Workflow
.github/workflows/release.yml
on:
push:
tags:
- 'v*.*.*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "Releasing ${{ github.ref_name }}"Gotchas
- A push that creates both a branch and a tag fires once per matching filter.
- Tag globs use the fnmatch syntax, not full regex.
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 Schedule a Nightly Build in GitHub ActionsRun a nightly GitHub Actions build with on.schedule and a cron expression, useful for regression suites, depe…