Sub topic 10
Why tags and releases made by GITHUB_TOKEN do not start other workflows
This chapter assumes you can read workflow YAML, know how a tag push starts a workflow, and have seen the permissions block from the earlier chapters. It explains one rule that surprises many people, and how to work around it.
The rule
When a workflow uses the built-in GITHUB_TOKEN to do something, GitHub does not start new workflow runs from the events that action creates. GitHub does this to stop accidental loops, where a workflow creates an event that starts a workflow that creates another event.
The exceptions are workflow_dispatch and repository_dispatch. Events from those two do start new runs.
Here are some cases where the rule applies:
- A job pushes a tag with
GITHUB_TOKEN. A workflow withon: push: tagsdoes not run. - A job runs
gh release createwithGITHUB_TOKEN. A workflow withon: release: types: [published]does not run. - A job opens a pull request with
GITHUB_TOKEN. Thepull_requestworkflows do not run on it.
The rule matters most for release automation. A common design has one workflow that creates a tag and a second one that builds and publishes on that tag. With GITHUB_TOKEN, the second workflow never starts, and nothing reports an error.
A broken example
This workflow tags the latest commit on main. The tag is created, but the release workflow from the earlier chapter does not run.
name: Tag on merge
on:
push:
branches:
- main
permissions:
contents: write
jobs:
tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Push tag
run: |
git tag v1.2.0
git push origin v1.2.0The actions/checkout step stores GITHUB_TOKEN as the git credential by default, so the push counts as made by that token. If you look at the Actions tab, you see the tag in the repository and no run for it.
Fix 1: do the work in the same workflow
Often you do not need a second workflow. Put the build and release steps in the workflow that creates the tag. The gh release create command can also create the tag itself when it does not exist yet. Pass --target to choose the commit.
- name: Create tag and release
env:
GH_TOKEN: ${{ github.token }}
run: gh release create v1.2.0 --target "$GITHUB_SHA" --generate-notesThis is the simplest option, and it needs no extra credentials.
Fix 2: call the second workflow explicitly
Give the release workflow a workflow_dispatch trigger, or make it reusable with workflow_call. Then start it from the first workflow. Events created by GITHUB_TOKEN through the dispatch API are allowed to start runs. The caller needs actions: write.
permissions:
contents: write
actions: write
steps:
- name: Start the release workflow
env:
GH_TOKEN: ${{ github.token }}
run: gh workflow run release.yml --ref v1.2.0Fix 3: use a different credential
A personal access token (PAT) or a GitHub App token acts as a user or an app, not as GITHUB_TOKEN. Events made with it start workflows normally. A GitHub App token is the better choice for a team, because it is not tied to one person's account and you can limit it to one repository.
Pass the credential to checkout so that the push uses it:
- uses: actions/checkout@v4
with:
token: ${{ secrets.RELEASE_TOKEN }}How to choose
| Situation | Option |
|---|---|
| Tag and release can happen in one workflow | Fix 1 |
| A separate workflow must run, and you control both | Fix 2 |
| Another tool or workflow listens to tag or release events | Fix 3 |
This rule also affects release-please, covered in the next chapters. Its release pull request is opened with GITHUB_TOKEN by default, so your pull_request checks do not run on it. Merging the pull request creates the tag and release, and workflows that listen for those events do not start either. Giving release-please a PAT or app token fixes both problems.
Exercise
A workflow with on: push: tags: ['v*'] builds and uploads binaries. Another workflow creates the tag v2.0.0 using git push after actions/checkout with its default settings. The tag appears, but the build workflow never runs. Why, and name two ways to fix it.
Show answer
The push was made with GITHUB_TOKEN, and events created by that token do not start new workflow runs (except workflow_dispatch and repository_dispatch). Fixes: do the build and release in the same workflow that creates the tag; start the build workflow with gh workflow run (using workflow_dispatch and actions: write); or pass a PAT or GitHub App token to checkout so the push is made with that identity.