Open Factory Flooropen source

Guides

The release gate

On this page

After a change is accepted it has still to be released. The release gate answers one question for a line: may what has been merged since the last release go out without a person?

It is in two parts. The rules (factory/release_gate.py) are handed the gate's settings and the facts of the moment, and answer. This page is about them. The gate at work (factory/release.py, running the release gate) gathers those facts from GitHub, runs in a repository's release workflow, and tells a person when a release is held. Neither releases anything: the repository's own workflow does that, when the gate says go.

#The settings

lines:
  - id: api
    feeds: [api/**, migrations/**]
    stations:
      - gate:
          unattended: true
          hold_when:
            - risk: high
            - changed: [migrations/**]
            - changed_release_path: true
            - open_action: release-failed
          release_path: [.github/workflows/deploy.yml, scripts/release/**]
          wait_while: previous_watch_running
KeyMeaning
feedsThe paths that are released by this line
unattendedfalse holds every release for a person. true lets one go unless a rule below holds it
hold_when: risk: highHold when a change that feeds this line touches a risk area
hold_when: changedHold when any of these paths changed, on this line or not
hold_when: changed_unless_removedAs changed, but a file that was only deleted does not hold (a rename still does). For a directory of plans or requests whose files are removed once they have been carried out. From version 0.28.0
hold_when: changed_release_pathHold when anything under release_path changed
release_pathThe release's own machinery: the workflow that releases and what it runs
hold_when: open_actionHold while an action of this kind is open (an earlier release that went wrong)
wait_whileRead and checked, not yet acted on

The review gate does not read lines, so a mistake here never stops reviews.

#The answer

One of three, with its reasons:

  • release: nothing holds it.
  • hold: a person must decide. When what changed is the cause, every rule that matched is given, with the files.
  • nothing: nothing merged since the last release is on this line, and no rule holds.

#How it decides

In this order; the first that applies is the answer (step 7 apart, which says what it adds).

  1. The facts are not a mapping, or the settings are not what the factory's own reader gives: hold. (This comes before everything, a person's start included.)
  2. A person started this release by hand: release. Starting it is the approval, and nothing below is looked at. The caller must be sure it was a person.
  3. Started by anything but a merge or a person: hold.
  4. The repository's switch for unattended releases is off, or cannot be read: hold.
  5. The line has no gate, or its gate says unattended: false: hold.
  6. No record of the last release on this line: hold. (The first release on a line is always started by hand.)
  7. The last release is not in the history being released, or that cannot be told: hold.
  8. The open actions cannot be read: hold. One of a kind named by open_action is open: hold, and steps 8 to 10 are still worked out, so that the answer gives every reason at once (from version 0.21.0). The person deciding whether to release by hand is told not only that an earlier problem is open but what in the held changes would have waited for them anyway.
  9. What changed since the last release cannot be worked out, the list is cut short, or a file's name in it is not a plain path: hold.
  10. A level of risk was handed over and is not of the right shape: hold. So does none being handed over when the factory file names a judge (given together with any rule in step 10 that matches).
  11. Any rule about what changed matches: hold, giving all that match.
  12. Nothing feeds this line: nothing.
  13. Otherwise: release.

Every unknown is a hold. There is no path from "not known" to "release" but the first, a person's own start. The gate does not raise errors: a fault inside it is a hold too, with the reason gate.failed.

#What always holds

Whatever hold_when says, a change to any of these holds: the factory file, the review standard it names, the repository's judge with its files, and, when the gate runs in a workflow, any file under .github/workflows/ or .github/actions/ that the gate's not_in_release does not name. They are the rules. A merge that loosens them must not be judged by the rules it loosened.

#What to know

  • It judges everything since the last release, not the newest merge: a release sends all of it. While a hold stands, later merges are judged together with what is held.
  • A renamed file is judged under both its names. A rename with no old name is not trusted, and holds.
  • Names must be plain paths: relative, forward slashes, no . or .., no outer spaces, no run of spaces, no character that does not print, at most 300 characters, and a status that is one of GitHub's. Two names are refused because a judge's reason could carry them without meaning a file: (pull request), and a 300-character name ending …. A release that includes a file named any other way holds, since a rule could miss it. GitHub can in fact list a file whose name breaks these (a trailing space, a backslash, a leading quote mark); a release that includes one waits for a person. Names are compared exactly, letter for letter: case and accents as git stores them.
  • Risk comes from the factory file's risk list, or, where the factory file names a judge, from the judge's answer for the same files, which the caller must hand over. With a judge the lists are not used: a file the lists call risky and the judge calls ordinary is released, and if a judge is named and no answer is handed over, every gate holds. A judge's reason names its file as the question named it; names are compared after the tidying every reason gets (outer spaces go, any run of spaces, tabs or line breaks becomes one space, and other characters that do not print are dropped).
  • A risk that cannot be placed holds, on every gate. A judge that failed, or said "high" and named no file, or named a file that is not among the changes, holds the line, whether or not the line's rules mention risk.
  • A path the review station skips has no risk here either, unless never_skip names it: a document or a test inside a risk area does not hold a release. If such a file is in fact released and matters (a template, a data file with a skipped ending), name it under changed.
  • risk holds only for what feeds the line, so feeds must be complete. A risky file the line releases but feeds leaves out is not held by risk. changed and changed_release_path hold wherever the file is: a database migration or a release script should hold a release even if it is not itself what is released.
  • unattended: true with no hold_when releases everything on the line but the rule files and a risk that cannot be placed. That is allowed, and is a decision.
  • An open action holds by its exact kind. release-failed is not Release-Failed.

#Settings that are refused

A lines section the gate cannot use is refused with the reason. So is one that looks like a slip that would quietly hold nothing:

  • A pattern that could never match a path: migrations/, /migrations/**, ./x.
  • A pattern that looks like a list or an exclusion: {a,b}, a leading !.
  • Square brackets that look like a set of characters: anything with a range in it ([0-9], [a-z0-9-]), a negation ([!x]), or a bracket inside brackets ([[], [[:digit:]]). A real folder name with a hyphen between letters or digits, such as [user-id], is refused with them, since it cannot be told from a range.
  • changed_release_path: true with no release_path, a review standard or judge file not named as a plain path, a gate's settings written under another station, a station called Gate or gates, a gate written beside stations and not under it, a key or a rule it does not know.

Only *, ** and ? are special. Square brackets match as themselves, so app/[id]/** names a real folder, and [mM]igrations is not "either letter". Where a path really has a brace, a leading ! or brackets of the refused kinds, put ? in that character's place (app/?user-id?/**), bearing in mind that ? matches any one character.

What the gate cannot see:

  • A set of characters with no range in it, such as [abc] or [0123456789]: it is taken as a name.
  • A key written twice. YAML keeps the last.
  • A folder written without /**. changed: [migrations] names one file called migrations, and holds nothing inside the folder.

#For whoever calls it

The decision is only as good as its facts. What gathers them (factory/release.py does; so must anything else that calls the rules) must:

  • say person only for a start that really was a person's;
  • take the last release only from a record it can trust, and pass None otherwise;
  • pass truncated: true whenever the list of changes may be incomplete (GitHub's comparison stops at 300 files);
  • when the factory file names a judge, always hand over its answer, worked out for these same files;
  • hand it the settings as config.parse and lines give them (lines raises GateError for settings it cannot use: that is a hold), and facts as plain values such as JSON gives;
  • treat anything but a returned release as "do not release", including its own errors and an interrupt.

#What is not built

  • Waiting while the previous release is watched (wait_while is read and checked, not acted on).
  • Events for holds and releases.
  • A repository's own judge deciding holds directly (it can already supply the risk).

This guide is docs/RELEASE_GATE.md in the repository, and this page is made from it. Something wrong or unclear? Open an issue or send a pull request. Next: Running the release gate.