Hangar Floor
DemoDownloadGitHub

The gate

The gate is one command that runs each check a change must pass before its merge. The coordinator runs it on the test tree of each batch. A PR merges only after a full pass.

Why one command

The script

The gate is assets/gate.template.tcl. Copy it to tools/gate.tcl in the project. It needs a tclsh of Tcl 8.6 or later.

Some sandboxed Tcl runners start a program of exec with no environment. Then make, node, or cargo finds no PATH or HOME. Some of those runners give the full environment only when they run under the name tclsh (a link with that name to the runner). The gate stops with exit 2 when it sees no PATH, so this case is never a false failure.

Write the list

The list is in gate::checks. It has three fields for each check: the name, a program that the check needs ({} for none), and the command:

build   {}      {cargo build --locked}
fmt     {}      {cargo fmt --check}
unit    {}      {cargo test --locked}
web     node    {node tools/web-test.mjs}

Rules:

  1. Start from CI. Read each workflow file. Each job that can run on this machine becomes a check. A check that CI has and the gate lacks lets a failure through to main.
  2. One shell command for each check. It passes when it exits with 0. Use && for steps. Pipes work.
  3. Order by need. A build goes before the tests that use it. A slow check goes last, so --stop gives a fast failure.
  4. Name a need for an optional tool. A check with a need becomes a skip on a machine without that program. A skip names its reason, and the summary lists it. A skip is never silent.
  5. %L in a command is the folder of the logs, for a check that writes extra files.
  6. No network in a check when you can avoid it. A check that depends on the network fails for reasons that have nothing to do with the PR.
  7. No secret in a command. The command shows in --list and in logs.

Run it

tclsh tools/gate.tcl --list           # the names and the commands
tclsh tools/gate.tcl --logs ../gate-logs/batch-7
tclsh tools/gate.tcl --only unit,lint  # for a worker's quick check; never for a merge

Output:

ok    build            41 s
ok    unit             95 s
FAIL  lint             3 s   src/render.rs:88: unused variable `w`
skip  web              no node on the PATH
gate: 2 ok, 1 failed, 1 skipped (web)

Exit status: 0 when no check failed, 1 when a check failed, 2 for a bad option or a bad start.

The log for the floor

The floor shows the run of a gate from its output. Keep the output in a file:

mkdir -p ../gate-logs
tclsh tools/gate.tcl --logs ../gate-logs/batch-7 | tee ../gate-logs/batch-7.out

Make the folder first: tee opens its file before the gate makes the folder of --logs.

In tick.json, give the gate "log": "../gate-logs/batch-*.out": the newest file that matches is the log. The patterns that tick --init writes read this output: ^ok\s is a check done, ^FAIL\s+(\S+) is a failed check and its name, and ^gate: is the end of the run. The files of --logs have the output of each check, not these lines.

Pass rules

Extend it

Next: milestones.