Sub topic 12
Making releases safe: concurrency, approvals and protected tags
This chapter assumes you have read the earlier chapters. You should know the tag-triggered release workflow, the permissions key, and how gh release create works. Those pieces make releasing easy. This chapter covers three controls that keep a release from going wrong: concurrency, environment approvals, and protected tags.
What can go wrong
A tag-triggered workflow publishes whatever a tag points to. Three problems follow from that.
- Two tags pushed close together start two runs that race. They may upload assets or edit the release at the same time.
- Anyone with write access can push a
v*tag, which publishes immediately. - A tag can be moved or deleted after the release exists. The release page then no longer matches the code.
Each problem has a matching control.
| Problem | Control | Where you set it |
|---|---|---|
| Overlapping runs | `concurrency` | Workflow file |
| Unreviewed publishing | Environment with required reviewers | Repository settings and `environment:` in the job |
| Tags rewritten or created by anyone | Tag ruleset | Repository settings, Rules |
Serialize releases with concurrency
A concurrency group lets only one run in the group execute at a time. Use a fixed group name so that all release runs share one queue.
concurrency:
group: release
cancel-in-progress: falseKeep cancel-in-progress set to false. If it were true, a newer tag would cancel a release that is half uploaded. With false, a second run waits for the first to finish. If a third run arrives while the second is still waiting, the third replaces the second in the queue. The replaced run is cancelled, so a tag can be skipped. For releases this is usually acceptable because you can re-run the skipped tag by hand.
Do not use group: release-${{ github.ref }}. The ref is the tag name, so every tag would get its own group and nothing would be serialized.
Require approval with an environment
An environment is a named deployment target that has its own rules. Create one called production under Settings, Environments. Add required reviewers. You can also restrict which branches or tags may deploy to it. A job that names the environment pauses until a reviewer approves.
name: Release
on:
push:
tags:
- 'v*.*.*'
permissions:
contents: write
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "$GITHUB_REF_NAME" --generate-notes --verify-tagWhen you push v1.2.0, the run starts and shows "Waiting for review". Nothing in the job executes until a reviewer approves. Secrets stored in the environment are also released only after approval, so you can keep publishing credentials there instead of at repository level.
Protect tags with a ruleset
Approvals protect the workflow. They do not stop someone from moving an existing tag. A tag ruleset does that.
- Open Settings, then Rules, then Rulesets, and create a new tag ruleset.
- Set the target pattern to
v*. - Enable restrictions on creation, update and deletion.
- Add a bypass list containing only the people or roles who may cut releases.
With this ruleset in place, git push --force origin v1.2.0 is rejected for everyone outside the bypass list. Published versions then stay fixed.
Common mistakes
- Setting
cancel-in-progress: trueon a release workflow, which can abort a run during asset upload. - Putting
environment:on a job but never creating the environment with reviewers. GitHub creates an empty environment automatically, and it requires no approval. - Protecting branches but not tags. Branch protection does not apply to tag pushes.
- Leaving a wide bypass list on the ruleset, which removes the protection.
Exercise
A team uses group: release-${{ github.ref }} with cancel-in-progress: false on a tag-triggered release workflow. They push v1.4.0 and v1.4.1 within a minute, and both runs execute at the same time. Why, and what is the fix?
Show answer
In a tag-triggered run, github.ref is the tag, such as refs/tags/v1.4.0. The two tags produce two different group names, so the runs are not in the same group and are not serialized. The fix is to use a fixed group name, such as group: release.