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
- CI runs after the merge, on
main. A failure there breaks every worker's next tree. The gate catches the same failure before the merge. - One command with one line for each result is easy to read, easy to quote in a merge comment, and the same for every batch.
- The logs stay in one folder, so the coordinator can show the exact lines to the worker.
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:
- 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. - One shell command for each check. It passes when it exits with 0. Use
&&for steps. Pipes work. - Order by need. A build goes before the tests that use it. A slow check goes last, so
--stopgives a fast failure. - 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.
%Lin a command is the folder of the logs, for a check that writes extra files.- 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.
- No secret in a command. The command shows in
--listand 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
- A merge needs exit 0 and no skip of a check that CI runs. A skip because a tool is missing means that the gate did not test that part. Install the tool (with the owner's word) or run that check on a machine that has it, and say so in the merge comment.
--onlyand--skipare for diagnosis. A run with either one is a partial check. No merge on a partial check.- The test tree must be the tree that merges. After the merge, compare the tree of
mainwith the tested tree. - A flaky check is a failure until you prove otherwise. See
troubleshooting.md.
Extend it
- Add a check in the same PR as the feature that needs it.
- When CI gets a new job, add the check to the gate in the same PR.
- A check that is too slow for each batch: keep it, and run the batch less often. Do not remove it.
- Keep the gate itself under review: a change to the gate goes through the loop like any other PR.
Next: milestones.