Open Factory Flooropen source

Guides

Setup guide: the release half

On this page

Stage 1 stops a change merging until it is tested and reviewed. This guide adds what comes after a merge: a decision on whether the change may be released without a person, the release, a watch afterwards that can undo it, and a record of it all.

It is written for an agent setting it up with the repository's owner. A person can follow it too. Do stage 1 first: this guide builds on its factory.yml.

Read the parts that are yours before you start. The factory decides, watches and records. The release itself, the trial run before it, and the two commands that look at and undo the live system are the project's own, and most of the work here is writing them.

#Rules for whoever runs it

  1. The owner decides; you propose. Marked Owner decides below: which rung to start on, what always waits for a person, and switching unattended releases on.
  2. Everything goes in by pull request.
  3. Do not weaken anything already there. If the repository already releases by automation, do not replace it: run the factory's gate beside it first.
  4. Start with every release waiting for a person. unattended: false until step 7.
  5. Never handle a credential. If the release or the check needs a cloud role or a secret, the owner adds it; you say which and where.
  6. Say what you did not do in the hand-over.

#Step 1. Which rung

Owner decides. Ask what exists today:

The project hasStart onYou will add
Nothing liveStage 1 only. Stop hereNothing yet
One live environment (or one pre-production environment and no customers yet)One environmentSteps 2 to 8, without the trial run
A place to release to, set up but never released to (a host switched on, an address that answers "not found")One environmentSteps 2 to 8, without the trial run. The first release in step 6 is its first ever
A test copy and a live systemThe whole lineSteps 2 to 8

With one environment there is no rehearsal, so two things matter more: an undo that works (step 5), and holding risky changes for a person (step 2).

#Step 2. Describe the line in factory.yml

A line is one place the repository releases to, and the paths that feed it. Add to factory.yml:

lines:
  - id: app                          # letters, digits, - and _
    feeds: [src/**, migrations/**]   # every path whose change should cause a release
    workflow: release.yml            # the release workflow's file name (step 3)
    watch: release-watch.yml         # the watch workflow's file name (step 5)
    stations:
      - gate:
          unattended: false          # every release waits for a person, until step 7
          hold_when:
            - risk: high             # the risk areas stage 1 already names
            - changed: [migrations/**]            # paths that always wait for a person
            - changed_release_path: true
            - open_action: release-failed         # a release that did not finish holds the next
            - open_action: watch-failed           # so does one the watch found unwell
          release_path: [scripts/release/**, scripts/live_check.sh, scripts/undo_release.sh]   # what your release runs, and the watch's two scripts
          not_in_release: [.github/workflows/tests.yml]   # optional: workflows that take no part in a release

people:
  action_needed: [the-owners-login]  # who is assigned, and so emailed, when a line stops

Owner decides what goes under changed: paths where a change should always wait for a person even though it is not risky code, such as database migrations. Leave the rule out if there are none. The three path settings do different jobs:

  • release_path: the scripts your release and your watch run (not the product's own code, even if the release builds it). A change to them always holds.
  • not_in_release: optional. Any workflow change holds a release. Name here the workflows that take no part in one, such as the one that runs the tests, to stop them holding. Leave it out and every workflow change holds, which is the cautious start.
  • changed: anything else that should always wait. What each key means: the factory file. What the rules do with them: the release gate.

Use Open Factory Floor version 0.21.0 or later for everything in this guide (the starter files for the release half arrived in 0.20.0, and were corrected in 0.21.0), and the same version in every workflow that reads factory.yml, stage 1's included: an older version refuses keys it does not know.

#Step 3. The release workflow

Copy starter/factory-release.yml to .github/workflows/release.yml. Replace COMMIT everywhere with the full commit id of the Open Factory Floor version, and CHANGE-line-id with the line's id.

Then write the two jobs that are yours:

  • production: replace the placeholder step with your release, and add what the job needs to reach your host (more permissions, an environment). See the release for what it must do, above all: end it by confirming the release arrived, not by asking whether the system is well. Leave its if: and the factory steps after it as they are.
  • staging: on the whole line, replace the placeholder with your trial run (what a good one proves). On one environment, delete the job and the line needs: staging.

Both placeholders fail on purpose until you replace them, so a half-finished copy releases nothing and says so.

#Step 4. The live check

Copy starter/scripts/live_check.sh to scripts/live_check.sh and write it: exit 0 when the live system is well, 10 when it is not, anything else when it could not tell. Ask only whether the system is well, never whether it is the release being watched (why). Run it by hand against the live system and see 0; on a project that has never released, expect "not well" or "could not tell" now, and see 0 after the first release in step 6.

#Step 5. The undo, and the watch

Copy starter/scripts/undo_release.sh to scripts/undo_release.sh and write it. Copy starter/factory-release-watch.yml to .github/workflows/release-watch.yml and replace COMMIT and CHANGE-line-id.

If the two scripts need to reach the live system, the watch workflow needs the same access your release has. Where that is a secret or a cloud role, the owner adds it; where it is a permission on the job, you add it and the review sees it. If your release is done by a workflow's own steps and not by a command, read the undo: the undo is then a second workflow, and the watch's job needs actions: write.

Try the undo before you rely on it, somewhere a mistake costs little. With one environment there is nowhere else, and nothing to put back until there have been two releases: the test at the end of step 7 is then its first real run, so do not skip it.

How the watch decides, and every setting: the watch.

#Step 6. Merge, and release once by hand

Open one pull request with steps 2 to 5. It changes workflows and the factory file, so it needs a person's or a fresh agent's review.

After it merges, its own run holds: every release on this line waits for a person (unattended: false). That is right. An issue titled "[ACTION NEEDED] Release of ... is waiting for a person" is opened and assigned to the people you named.

The held run itself shows green: a hold is an answer, not a failure. The issue, and the skipped production job, are how you see it.

The owner releases once by hand: Actions, the release workflow, "Run workflow" on the releasing branch, type release (or gh workflow run release.yml --ref main -f release=release). That run is the first release on record; the issue closes when it succeeds. Then the watch starts by itself and runs for its 30 minutes.

While unattended is false, every merge to the releasing branch is held, a change to prose included, and each adds a comment to the same waiting issue. A release by hand sends out everything merged so far and closes it.

#Step 7. See each thing happen

Do these on changes that do not matter, one at a time, and look at the result before the next. Let each release's watch end before you start the next row (30 minutes, unless you set another). A release by hand does not wait for the watch before it, so rows done back to back leave several watches running at once, each looking at a system that a later release has changed. So this step takes two to three hours, nearly all of it waiting: plan for it, and do something else between rows.

Do thisExpect
Merge a small change to a path under feedsHeld (every release waits). Release it by hand
Owner decides: set unattended: true, merge that change (it holds: the rules changed), release by handThe line is now unattended
Merge another small change under feedsReleased with nobody starting it; the watch runs and ends well. If the watch after the release before is still going, the gate waits for it first (up to 75 minutes): leave it, do not cancel the run
Merge a change to a path under changed, or to a script under release_pathHeld, with the reason in the issue. (Before version 0.21.0, an open issue about a release that went wrong was the only reason given while it was open)
Make the live check answer 10 for one release (on a system where that is safe): merge a small change that is wrong on purpose in a way the check notices and the tests do not, saying so in its description so that its reviewer reviews it as the test it isThe undo runs, an issue is opened, and the next merge is held until a person closes it. Afterwards revert the change (its release is held by that issue: release it by hand), and the owner closes the issue

Then ask the factory how it went:

cd "$FACTORY" && GITHUB_REPOSITORY=OWNER/REPO GITHUB_TOKEN=$(gh auth token) .venv/bin/python -m factory.status

$FACTORY is the copy of Open Factory Floor from stage 1's step 2, at the version you are using now. Make it again if it has gone or is older; the command is run from inside it.

The report has a section for the line: what was released, held and undone, and, when an issue about a release that went wrong is open, that the line is stopped and by which issue.

#Step 8. Hand over

Tell the owner, in plain words:

  • which rung the project is on, and what it has no net for (on one environment: no rehearsal);
  • what always waits for a person, and how to release by hand;
  • what the undo puts back and what it does not;
  • the switch: the repository variable FACTORY_UNATTENDED_RELEASES set to off makes every release wait for a person;
  • what you could not check.

#Keeping it running

  • Closing an alert is the owner's. An agent doing the setup does not close an issue about a release that went wrong, even one it knows to be a false alarm: it says what it found and the owner closes it. That issue is what holds the line.
  • An alert means a line is stopped. An issue about a release that went wrong holds the line until a person closes it. An issue about a release waiting for a person closes by itself when that release, or a later one, goes out. Each says what to do.
  • Moving up a rung (adding a test copy) is adding the staging job back and needs: staging under gate. Nothing else changes.
  • A new Open Factory Floor version: change COMMIT in every workflow at once.
  • A new workflow holds releases when it changes, until you name it under not_in_release (only if it takes no part in a release).

#What the release half does not do

  • It does not release. Your production job does.
  • It does not know whether your trial run is any good, or whether there is one.
  • It does not undo anything your undo command does not undo.
  • It works on GitHub only.

This guide is docs/SETUP_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: Review standard.