Sub topic 15
Why GITHUB_TOKEN pushes do not start new runs
This chapter assumes you can read workflow YAML and know how push and pull_request triggers work. It covers a rule that surprises many people: some events created by a workflow do not start other workflows.
The rule
When a workflow uses the built-in GITHUB_TOKEN to create an event, such as pushing a commit, opening a pull request or creating a tag, that event does not start a new workflow run. Two events are exceptions: workflow_dispatch and repository_dispatch.
GitHub does this to prevent recursion. Without the rule, a workflow that pushes a commit would trigger itself, which would push again, and so on.
Seeing it happen
This workflow formats a file and pushes the result back. The push succeeds, but the CI workflow does not run for the new commit.
name: Update changelog
on:
workflow_dispatch:
permissions:
contents: write
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Commit a change
run: |
date -u > last-run.txt
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add last-run.txt
git commit -m "Update last-run.txt"
git pushThe permissions block gives the token write access to repository contents. Without it, the push can fail on repositories whose default token permissions are read-only.
A common symptom is a pull request opened by a workflow whose required checks stay at "Expected" forever. The pull_request event was created by GITHUB_TOKEN, so no checks started.
Ways to get a new run
Pick the option that fits your security needs:
| Option | How it works | Trade-off |
|---|---|---|
| GitHub App token | Generate a short-lived installation token and use it to push | Most setup, but least privilege and no personal account involved |
| Personal access token | Store it as a secret and pass it to `actions/checkout` | Simple, but tied to a user and often broadly scoped |
| `workflow_dispatch` call | Run `gh workflow run ci.yml` with `GITHUB_TOKEN` and `actions: write` permission | Allowed by the exception, but the target workflow needs a `workflow_dispatch` trigger |
For the personal access token option, pass the secret at checkout so later git push calls use it:
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.BOT_TOKEN }}Avoiding loops once you bypass the rule
A personal access token or app token removes the safety net. If the pushed commit triggers the same workflow, you get an endless loop. Guard against it with a path filter on files the workflow itself changes, or with a condition such as if: github.actor != 'my-bot'. Adding [skip ci] to the commit message also works for push and pull_request events.
Exercise
A workflow creates a pull request with GITHUBTOKEN. Your repository requires the `pullrequest` workflow "CI" to pass, but it never starts. Why, and name one fix.
Show answer
Events created with GITHUBTOKEN do not start new workflow runs, so the pullrequest event from the bot is ignored. Create the pull request with a GitHub App token or a personal access token instead. Alternatively, trigger CI with workflowdispatch, which GITHUBTOKEN is allowed to start.