Sub topic 2
Choosing what starts a release: tag pushes and manual runs
This chapter assumes you can read workflow YAML and know the difference between a branch and a tag in git. It covers the two triggers most release workflows use: pushing a version tag, and running the workflow by hand.
Why the trigger matters
A trigger decides who or what can cause a release. If the trigger is too broad, a stray tag or branch push publishes something you did not mean to ship. If it is too narrow, releasing becomes awkward. Most repositories use a tag push as the main path and a manual run as the fallback.
Starting a release with a tag push
A push trigger can be limited to tags with the tags filter. The filter uses glob patterns, not regular expressions.
on:
push:
tags:
- 'v*.*.*'In a glob, * matches any characters except /. The pattern v*.*.* therefore matches v1.2.0 and v1.3.0-rc.1. It also matches vfoo.bar.baz. A glob cannot check that the parts are numbers. Rejecting malformed tags needs a validation step, which a later chapter covers.
These details affect how tag-triggered workflows behave:
- Annotated and lightweight tags both trigger the workflow.
- On a tag push,
GITHUB_REF_NAMEis the tag name, such asv1.2.0, andgithub.ref_typeistag. - The workflow file used is the one stored in the tagged commit. If you tag an old commit that predates the workflow, nothing runs.
- GitHub does not create events for tags when more than three are pushed at once. Push release tags one at a time.
- If you list both
branchesandtagsunderpush, a match on either one starts the workflow.
Starting a release by hand
The workflow_dispatch trigger adds a Run workflow button to the Actions tab. You can also start it with gh workflow run. It accepts typed inputs, which is useful for re-releasing an existing tag after a failed run.
on:
workflow_dispatch:
inputs:
tag:
description: 'Existing tag to release, for example v1.2.0'
required: true
type: stringA manual run starts from a branch or tag that you select, and the workflow file must exist on the default branch for the button to appear. In a manual run, GITHUB_REF_NAME is the selected branch name, not a tag. Your steps therefore need the tag from the input instead.
Supporting both triggers in one workflow
This workflow accepts either trigger and works out the tag in one place. It then checks out exactly that tag.
name: Release trigger demo
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
tag:
description: 'Existing tag to release, for example v1.2.0'
required: true
type: string
jobs:
show:
runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.RELEASE_TAG }}
- name: Show what would be released
run: echo "Releasing $RELEASE_TAG (event: $GITHUB_EVENT_NAME)"On a tag push, inputs.tag is empty, so the expression falls back to github.ref_name. On a manual run, the input wins.
The input reaches the shell through an environment variable, not through ${{ inputs.tag }} written inside the run script. GitHub substitutes expressions into the script text before the shell runs it. A value such as v1.0.0"; curl ... would then become part of the command. An environment variable is read as data and avoids that problem.
Comparing the triggers
| Trigger | Started by | Tag name comes from | Best for |
|---|---|---|---|
| `push` with `tags` | Pushing a matching tag | `github.ref_name` | Normal releases |
| `workflow_dispatch` | A person or the CLI | A workflow input | Retrying a release, one-off cases |
Exercise
A teammate pushes the tag v2.0.0 and the workflow does not start. The workflow has on.push.tags: ['v*.*.*']. Name two causes you would check first.
Show answer
Check whether the tag was pushed together with more than three other tags, since GitHub creates no events in that case. Check whether the workflow file exists in the tagged commit, since the file at that commit is the one that runs. Another possible cause is a tag created by a workflow using GITHUB_TOKEN, which does not trigger other workflows.