Part 8 of the fifth-protocol series. By mid-afternoon the reader could read the terminal's whole log from my laptop. Two things were left: get that code onto the office PC while people were still on site, and get it onto every other office PC as a proper release. They are different jobs, and mixing them up is how an unsigned file ends up on a customer's download page.
Fix merged to main. Releases build from main only; the signing environment refuses any other branch.
The official route
Releases build from main only
The release workflow signs with keys kept in a secrets store. It fetches them with short-lived credentials, and those credentials are only issued to one deployment environment, which accepts one branch: main. My first attempt dispatched the workflow on the fix branch, and it failed in a second, before any step ran. That is the guard working. The fix went to the staging branch by pull request, then staging to main by a second one, and only then could it be built.
A runner for one job
The build needs a Mac: the Mac app is signed and notarised, and the tools for that only run on macOS. Hosted macOS minutes cost money this account does not spend, so the job runs on a Mac I already have, as a runner that takes exactly one job and removes itself:
cd ~/actions-runner-once
TOKEN=$(gh api -X POST repos/<org>/<repo>/actions/runners/registration-token -q .token)
./config.sh --unattended --url https://github.com/<org>/<repo> --token "$TOKEN" \
--ephemeral --labels connector-once --replace
nohup ./run.sh > runner.log 2>&1 &
gh workflow run build-<app>.yml --ref main \
-f version=<x.y.z> -f environment=prod -f runner=this-mac
--ephemeral is the point: the runner exists for one job. Nothing is left
listening for the next one.
What the job does
go vetand the full test suite. A release does not skip tests because they passed on the pull request.- Builds five files from one machine: Windows 64- and 32-bit, Linux 64-bit and ARM, and one Mac app for both chips. The version, the default server and the release public key are set at link time.
- Signs the Mac app with a Developer ID, sends it to Apple for notarisation, staples the ticket, and runs Gatekeeper's own check on it. If Gatekeeper would refuse it, the job fails.
- Writes
SHA256SUMSand uploads everything as the job's artifact.
Checking what came out
The artifact is downloaded and checked before anyone can install it:
gh run download <run-id> -n <app>-<x.y.z>-prod -D ./release
cd release && shasum -a 256 -c SHA256SUMS
LC_ALL=C grep -a -c '<x.y.z>' <connector>-windows-amd64.exe
unzip -p <connector>-mac.zip "<Connector>.app/Contents/Info.plist" | grep -A1 ShortVersion
LC_ALL=C grep -a -c '<release-public-key>' <connector>-windows-amd64.exe
In order: every file's checksum matches, the version is inside the Windows binary and the Mac app, the installers point at the right server, and the release public key is present.
The last check matters more than it looks. Every update and every helper the connector runs is checked against that public key. A build without it, or with the wrong one, installs fine and then refuses everything it is later given. An earlier hand-built release had once carried a string that looked like the key and was not; since then the key comes only from the official build, and every build is checked for it.
Uploaded is not live
The public download folder on the server is filled from a separate downloads store when the server is deployed. So a release is four steps, and each has its own check:
- Back up what is served now, so going back is one copy.
- Upload the new files to the downloads store.
- Read them back from the store and check their sums again.
- Re-run the production deploy, which copies the store onto the server:
gh run rerun <last-production-deploy-run-id>
Then the only check that counts, file by file against what is served:
curl -s https://<server>/downloads/<app>/SHA256SUMS | diff - release/SHA256SUMS
for f in $(cut -c67- release/SHA256SUMS) install.ps1 install.sh; do
a=$(curl -s https://<server>/downloads/<app>/$f | shasum -a 256 | cut -c1-64)
b=$(shasum -a 256 release/$f | cut -c1-64)
[ "$a" = "$b" ] && echo "OK $f" || echo "DIFF $f"
done
Until every served file hashes the same as the build, I say "uploaded, not live". Saying "released" after step 2 once gave the wrong answer to the only question anyone on site asks: can they download it yet?
The site-visit route
The official route takes about twenty-five minutes, most of it Apple's notarisation. People on site should not wait for it, and the fix only had to reach one Windows PC. So the same commit was built on the laptop, for Windows only:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath \
-ldflags "-s -w -X main.version=<x.y.z> -X main.DefaultServer=https://<api-host> \
-X <module-path>/update.PublicKeyBase64=<release-public-key>" \
-o serve/c.exe .
The public key is the one thing a local build could get wrong. It is public: it is inside every shipped binary. It can be found by comparing the strings in the official build with a build made without it, and taking the one 32-byte base64 value that only the official one has. A local build with the same key is a build the next official release can still update.
Then the laptop served it on the office LAN, for minutes:
cd serve && python3 -m http.server 8765 --bind <laptop-lan-ip>
On the office PC, typed (pasting was not possible), in PowerShell as administrator:
taskkill /IM <ConnectorWindow>* /F
cd \
curl.exe -o c.exe http://<laptop-lan-ip>:8765/c.exe
.\c.exe setup
Four lines worth explaining:
taskkillon the setup window, not the service. The connector runs as a Windows service that reads the terminals, plus a setup window. If the old window is open, the new copy only brings it forward. The window's file name and the service's are different, so a pattern can match one and not the other. Windows restarts the service if it stops anyway.curl.exe, notcurl. In Windows PowerShell,curlis an alias for a different command with different arguments.- A one-letter file name, because it was typed.
setup, because started from a terminal with no arguments the program prints its help instead of opening the window.
The laptop's server log showed the full file size sent; the program printed the new version; the update replaced the service and kept the PC's pairing. The next read reached the terminal. Then the server was stopped, and the file was gone from the network.
A red job with every test green
The release needed one more promotion to main, and its CI went red. All five shards had finished: 11,700 runs, 0 failures. The failing step came after them: uploading a small file of per-test timings, refused with "artifact storage quota has been hit".
The storage was full of 61 old test builds of the connector, about 1.3 GB. Deleting all but the newest three took it from 1.5 GB to 0.24 GB:
gh api "repos/<org>/<repo>/actions/artifacts?name=<app>-dist&per_page=100" --paginate \
-q '.artifacts[] | "\(.created_at) \(.id)"' | sort -r | tail -n +4 | cut -d' ' -f2 |
while read id; do gh api -X DELETE repos/<org>/<repo>/actions/artifacts/$id; done
The quota is recounted every six to twelve hours, so the next runs were still red for the same reason. Two lessons. A job's colour is not its result: read which step failed before calling a change broken. And a step that only saves timings for next time should not be able to fail the job; that change belongs in the workflow.
One more red check that was not a failure: re-running CI while a newer run for the
same pull request had started. The older run was cancelled, and a cancelled check
shows red. The job's steps said cancelled, not failure:
gh api repos/<org>/<repo>/actions/jobs/<job-id> \
--jq '.conclusion + " | " + ([.steps[] | select(.conclusion != "success" and .conclusion != "skipped") | .name + "=" + .conclusion] | join(", "))'
Part 9 is the last open problem from the day: the terminal's clock, which nobody could touch.