Running the release gate
On this page
The release gate's rules answer whether what has been merged since the last release may go out without a person. This page is about putting them to work: where the gate sits in a release workflow, where its facts come from, and what a person sees when it holds.
The gate releases nothing. It answers go or not. Your own workflow deploys, and must do so only when the answer is exactly true.
#What the gate is, and is not
It is a control on what goes out without a person looking: it makes sure that a risky change, a change to the rules, a change it cannot read, or anything after a release that went wrong, waits for someone. It is built so that no accident, no fault in its own inputs, and nobody without write access to the repository can turn a hold into a release.
It is not a barrier against a person or an agent who has write access to the repository and sets out to get round it. Such an account can start a release by hand, which is allowed. It can also do things the gate cannot see or stop: change the release workflow, name jobs to look like the gate's, delete the record of a run, move a tag. The gate holds on those it can detect, which is most (below), and the guide says which it cannot. What actually keeps a determined insider from releasing is what keeps them from pushing to the releasing branch: branch protection, review, and production credentials tied to that branch. Set those first.
#In your release workflow
on:
push:
branches: [main]
workflow_dispatch:
inputs:
release: { description: 'Type "release" to release by hand', required: false, default: "" }
jobs:
staging:
...
gate:
needs: staging
permissions: { contents: read, issues: write, actions: read }
uses: theaiengineers/factory/.github/workflows/release-gate.yml@<commit>
with:
factory_ref: <the same commit>
line: api
typed: ${{ inputs.release }} # an input by another name: say so on the line, `release_input: <name>` (spec/factory-file.md)
production:
needs: gate
if: needs.gate.outputs.go == 'true'
concurrency: { group: release-api, cancel-in-progress: false }
permissions: { contents: read, issues: write }
steps:
- ... deploy ...
- name: Close the waiting issue, if there is one
run: python3 -m factory.release released --line api
- name: Say that it did not finish
if: failure() || cancelled()
run: python3 -m factory.release failed --line api
The last two steps need Open Factory Floor checked out and its one dependency installed, as the reusable workflow does, and GITHUB_TOKEN in their environment. Check it out to its own folder (path: .factory, then PYTHONPATH=.factory), so that a folder called factory in your own repository cannot stand in for it.
Nothing has to be set up to record releases: the run is the record (below).
#Where each fact comes from
| Fact | From |
|---|---|
| Who started it | A push to the releasing branch is a merge. workflow_dispatch on the releasing branch with exactly release typed, by an account that is not a bot, is a person. Anything else is neither, and holds |
| The switch | The repository variable FACTORY_UNATTENDED_RELEASES. Unset, on, true, 1, yes, enabled: on. off, false, 0, no, disabled, stop: off. Anything else is not understood, and holds |
| The settings | factory.yml at the commit being released. It is on the releasing branch, so it has been reviewed; and a change to it always holds |
| The last release | GitHub's own account of this workflow's earlier runs: the newest that was a release (below) |
| What changed since | GitHub's comparison of the last release with this commit. It lists at most 300 files: at 300 the list is treated as cut short, and holds |
| The level of risk | The factory file's risk list; or, when it names a judge, the judge's answer for everything since the last release. The judge is read from the commit being released, as the factory file is |
| Earlier problems | Open issues carrying this line's went-wrong mark. With a thousand or more open issues the gate cannot be sure it has seen them all, and holds |
What cannot be found out is handed to the rules as not known, which holds, and is noted in the run's summary.
#How the last release is known
The gate keeps no record of its own, and believes nobody else's. It asks GitHub for the recent runs of the workflow it is running in, and takes the newest earlier one that GitHub says was a release:
- a run of this same workflow file, in this repository, on the releasing branch, started by a push or by hand;
- that has finished, and succeeded as a whole;
- in which the job
factory-release-gate-go (<line>)succeeded, once, beside the gate's own job. That job is part of Open Factory Floor's reusable workflow and runs only when the gate has said go, or that nothing on the line needed releasing. In a run where the gate held, it is skipped.
So a held run is not a release, a run whose production failed is not a release, and a release started by hand is one. Nobody can write a run as they can write a note: GitHub makes it. And nothing in the factory file says which runs count, so a merged change to the settings cannot change it.
Two things a run's record does depend on, and what the gate does about each:
- A run can be deleted by anyone with write access. Deleting the last release's run would make the one before look like the last. A workflow's runs are numbered without gaps, so the gate checks that no number is missing between its own run and the release it rests on; if one is, the last release is "not known" and a person releases by hand. (So deleting any recent run of the release workflow, even a failed one, costs one hand release.)
- A run is recognised by the names of its jobs: the go job, once, beside the gate's own job, with no gate job lacking its go job. A later attempt of the same run in which the gate held does not undo a release that an earlier attempt made and finished cleanly; an attempt in which any job failed or was cancelled is not a release, whatever a later attempt shows. One exception: in the newest attempt of a run that succeeded, a job that failed without failing the run (one marked
continue-on-error, such as a closing step that tidies an issue) does not unmake the release. Only a job that endedfailureis passed over so. One that hit its time limit, was cancelled, or whose machine never started still unmakes the release, a closing job's too: GitHub's account of a job says its name and how it ended, not which job releases, so a closing job that timed out cannot be told from a production job cancelled half way. The cost is that the next gate judges a longer stretch than it need. And it means the job that releases must never be the one allowed to fail (see What to know). But a workflow file gives its jobs their names, and if your release workflow names any job from data (a matrix read from a file, an input typed at a hand start), that data can spell the gate's job names. Do not name jobs in the release workflow from anything but the workflow's own text.
What can change it is a change to a workflow file: jobs of your own given those names, or a production job that no longer waits for the gate. So a change to any file under .github/workflows/ or .github/actions/ holds, whether or not the factory file lists it under release_path, and a person is told. (The one exception is a file you have named as taking no part in a release: see below.) This is also what makes the run record sound. GitHub reports a tag's name where it reports a branch's, so a run on a tag called main looks like a run on the branch main, and a tag can point at a commit whose workflow files nobody reviewed. But a release goes out unattended only when every workflow file (bar those named as taking no part in a release) is the same at the last release as at the commit being released, which is on the reviewed branch: so a run of unreviewed workflow files is never what an unattended release rests on.
Workflows that take no part in a release need not hold. In a busy repository the workflow that runs the tests, or one that publishes a site, changes often, and holding every release for it teaches people to wave holds through. Name those under the gate's not_in_release (from version 0.19.0):
- gate:
unattended: true
not_in_release: [.github/workflows/tests.yml, .github/workflows/publish-site.yml, ".github/actions/lint/**"]
Each entry is one workflow by its exact file name, or one local action (a file in it, or its folder and /**). There are no patterns across workflows: *.yml would read as narrow and take in every workflow, the ones your release calls among them. A change to a file named there does not hold. Everything not named still does, a workflow added later included, and so do the release workflow itself and the line's watch workflow whatever is named. Name only what the release workflow does not call and what cannot release: if it uses: a local workflow or action, that one is part of the release. The list is in the factory file, so changing it holds the next release for a person to look. A named file renamed to another named file, or moved out of those folders, does not hold.
Forbid tags named like your releasing branch with a repository rule all the same: with data-named jobs, or with workflows called from another repository, that argument no longer covers a run on such a tag. And be clear about the limit: a workflow file can name its jobs anything and can release without asking the gate at all, so a change to it that review has let through can undo everything here, including that hold at the next merge. The gate cannot protect a release from its own workflow. Review changes to that file as what they are, and list under release_path the scripts it runs.
What to know about it:
- A line's first release is started by hand, since there is no earlier run to go from. That is also the way out whenever the last release is "not known".
- If the run taken for the last release is at a commit that is not in the branch's history (a run on a tag named like the branch, at a commit that was never merged), every release holds as "the last release is not in the history" until a person releases by hand.
- The workflow's 99 most recent runs are looked through, of every kind and on every branch, since that is how GitHub numbers them. If no release is among them, the last release is not known and a person releases by hand. A workflow that also runs for pull requests fills that window quickly: keep the release workflow for releases (pushes to the releasing branch and hand starts).
- A missing run number is taken for a deleted run, whatever its cause. If a number is missing between the newest run and the last release, the gate holds. One hand release clears it.
- Two merges close together each start a run. If the earlier run's gate decides after the later run has released, it holds ("the last release is not in the history"): an older commit is not released over a newer one. Nothing need be done; the later run carried the change out.
- "Nothing to release" counts as a release point. Everything up to that commit was judged, and none of it was on the line or matched a rule.
- One line to a workflow is simplest. With two lines in one workflow, a run counts for a line only if the whole run succeeded: if the other line's production fails, this line's release is not counted, and the next gate judges a longer stretch than it need. That errs towards holding.
- A production job that is skipped for a reason of your own (an extra
if:) in a run where the gate said go still counts: those changes were judged and allowed out. - Re-running an old release run really does release that old commit again, and GitHub then reports that run as the most recently started. So the gate takes that old commit as the last release, and judges again everything merged since it. That is right: it is what production now lacks. It holds only while that old run is still among the 99 in view and has not been deleted; roll back by re-running a run older than that, and the gate does not know of it. After any rollback, make the next release by hand.
- Two lines in one workflow: a run counts for a line only if the whole run succeeded and no gate in it held, so a hold or a failure on one line stops the other's release being counted too.
This trusts GitHub's account of its own runs. It does not replace protecting the releasing branch: the workflow, the factory file and the judge are all read from the commit being released, so the gate is only as sound as the rule that nothing reaches that branch unreviewed. Tie your production credentials to the releasing branch (a GitHub environment restricted to it): a run started by hand on some other branch reads that branch's factory file, which can name itself the releasing branch.
#What a person sees
When the gate holds, one issue, assigned to the people under people.action_needed in the factory file:
What is stopped: the release of line
api. Commit1a2b3c4passed everything before the gate and was not released. If you do nothing: it stays unreleased, and so does everything merged after it. What to do: read the reasons below. If it should go out, start the release by hand: run the workflow.github/workflows/deploy.ymlonmainand typerelease.
then each reason with its files. A later merge that is also held brings the same issue up to date and adds a comment; there is never a second. The release that follows closes it. A start that is neither a merge nor a person's (the workflow run by hand without the word, say) holds too, and leaves the issue as it is.
If the factory file names nobody, or GitHub will not accept the names or the label, the issue is still opened, with a warning in the run's log that nobody is notified by it.
When a release does not finish, the run fails, so it is not counted as a release; and failed opens an issue that holds every unattended release on the line while it is open. A person finds out what state things were left in, puts it right, and closes it. Nothing closes it automatically; a later failure adds a comment to it. For this to hold the line, the gate's hold_when must include open_action: release-failed: without it failed still opens the issue and warns in the log that it holds nothing. A hand-started release does not close it either. If the repository has a workflow that closes stale issues, exempt the labels release-held and release-went-wrong.
#What to know
gois writtenfalsebefore the gate does anything, andtrueonly as its last act. A gate that fails part-way leavesfalse, and the job fails. Useif: needs.gate.outputs.go == 'true'exactly: not!= 'false', and notsuccess().- A hold whose issue could not be written still holds, and the job fails so that someone notices.
- The issues are anyone's to open. Someone who can open an issue can hold a line by writing a went-wrong mark in it. That costs a person's time; it cannot cause a release. The gate treats as its own only an issue written by the workflow's account (
github-actions[bot]), under exactly the title the gate gives it, with the gate's mark as its last line: it never updates, closes or counts as "already open" any other. Every workflow in a repository writes as that account, so the title is part of the test; a workflow that let a visitor choose both an issue's title and its last line could still imitate one. A workflow that runs the gate with another account's token would not find its own issues again, and would open a new one each time. - A person is an account that is not a bot. A workflow's own token or an app starting the release workflow with the word typed is refused. An agent acting with a person's own token cannot be told from that person: whether agents may release by hand is for the repository to rule on.
- Re-running. Re-running a run that a person started is that person's start again, at the old commit. "Re-run failed jobs" on a run whose gate said go re-uses that answer and does not ask the gate again.
releasedis a courtesy, not a record: it closes the waiting issue. Left out, the release still counts and the issue stays open until someone closes it. If the step runs and fails, though, it fails its job like any step: the run did not succeed, so it is not counted, and the next gate judges from the release before. Give itcontinue-on-error: trueif you would sooner an unclosed issue than that.- Never put
continue-on-erroron the job that releases, nor on a step in it that releases. The gate takes the run's word for it. A production job marked so, that fails, leaves the run a success with the go job succeeded, and that run is counted as a release that was done: what it carried is not judged again and nobody is told. The same goes for a releasing step marked so, whose job then ends a success with nothing to show the failure at all. Keepcontinue-on-errorfor what comes after the release and cannot undo it (thereleasedstep, a tidy-up job), and give those a job or a step of their own. - The judge, if the factory file names one, is run here as it is for reviews, with no token in its environment; here it is fetched from the commit being released. See the judge's guide for what that does and does not protect.
- Pin what the release workflow calls. A workflow or action called from another repository by a branch or a tag can change without any file here changing, and the hold on workflow files cannot see it. Pin them to commit ids, Open Factory Floor's own workflow included (
uses:andfactory_ref). A local action kept outside.github/actions/is not covered either: list it underrelease_path. - The switch can be turned on as well as off by anyone who may edit the repository's variables. It is a convenience for stopping unattended releases, not a lock.
- Releases on one line should not overlap. Give the releasing job a
concurrencygroup in your workflow; the gate does not serialise them.
#When the watch runs in a workflow of its own
A line that names watch: in the factory file has its watch in a separate workflow (the watch, "A workflow of its own"). For such a line the gate, having found that a merge may be released unattended, waits until the watch after the previous release has ended, then asks everything again. It waits up to watch_wait_minutes (75 unless said, on the with: of the gate's workflow), then holds. The gate's job may therefore run for that long.
#Beside a release process you already have
If your repository already decides its own releases, you can watch what this gate would have said for a while before relying on it. Nothing changes in your release process, and the gate decides nothing.
Add one small workflow that starts when your release workflow finishes and calls release-gate-beside.yml (the file's first lines show how). Tell it the line, the run that just finished, and the exact name of the job that releases: the job that runs when you release and is skipped when you hold.
For each finished run that a merge started, it writes to the run's summary:
- what your workflow did: released (that job succeeded) or did not (it was skipped);
- what this gate would have said, with its reasons;
- THE SAME or DIFFERENT. "Nothing to release" beside a run that released nothing is the same: neither would send anything out. "Nothing to release" beside a run that did release is different: your workflow released for the line, and the factory file's
feedssay nothing on it changed. - The last release is looked for in the 100 runs before the one compared. If none of them released, the gate's answer says the last release could not be worked out, and why.
It also prints one line starting BESIDE, for collecting the answers over many runs.
What to know about it:
- It writes nothing. No issue is opened for a hold, no status is set, and its token can only read.
- The last release is taken from your own runs: the newest earlier run of the same workflow, on the releasing branch, in which the releasing job succeeded. This is a simpler reading than the gate's own, and it is good enough for comparing. Nothing is released on the strength of it. It looks back through 30 earlier runs.
- Some runs are not compared: a run a person started by hand (that is the person's decision), a run that did not succeed (your own gate may never have been reached), and a run with no single job of the name you gave.
- The gate's own went-wrong issues are the only ones it knows. If your process holds releases on issues of its own, or waits while an earlier release is watched, this gate cannot see that, and will say "release" where yours held. Expect those differences.
- Differences are the point. Each one is either a rule to add to the factory file, a rule of yours you no longer want, or a place where the two processes mean different things by the line.
#What is not built
- Waiting while the previous release is watched, other than by a
concurrencygroup (the watch says how). Watching a release and undoing one are built: see that page. - A check again just before production, for a release that waited in a queue.
- More than 300 changed files, or 1,000 open issues: both hold.
This guide is docs/RELEASE.md in the repository, and this page is made from it. Something wrong or unclear? Open an issue or send a pull request. Next: The watch after a release.