1 Commits
Author SHA1 Message Date
w3cjandClaude Opus 5.5 00e5ea59f4 feat(cosign): the run, which makes and publishes each release CI hands over
devvm-cosign's run (Cosigner.Run), its command (cmd/devvm-cosign, Main)
and the maintainer's commands, devvm-cosign retry, ack and failed.

CI's token can only read the repo, so CI hands each build over as a
workflow artifact, and only the co-signer, and the maintainer by hand,
can make or publish a release. For each release CI handed over that it
hasn't published, oldest first, from the newest successful run of the
pinned release workflow for each tag, of this repo's own:

- its version is newer than the newest it signed, or one it signed, with
  the same SHA256SUMS; an older one is an alert, as a replay, until the
  maintainer acks it, unless it was published before the state began;
- CI's artifact is staged (stage/, which no build can reach) and
  checked: SHA256SUMS, CI's signature with CI's key and devvm-release
  <version>, and exactly the files it lists, each with its SHA-256; its
  files are deleted before the build and downloaded again after a match,
  so none of CI's bytes is on disk while a container could be live;
- a run builds once, so the podman service, which lives for the run,
  lives for one build, and anything that escaped a container is gone
  before the next build's host git and release.sh run; the next release
  or base waits for the next run;
- the build's finished files go in a folder of the state's src/, which
  release.sh copies to and the co-signer reads, where no container can
  swap a file or the folder;
- the tag's commit has to be the commit CI's run built, and the
  co-signer's own build has to match every file and SHA256SUMS; it
  renders the tap's formulas itself from the tag's template and the
  signed SHA256SUMS (formula.go, as release.sh's formula function does),
  and the build's own formulas have to be the same bytes, so neither
  builder's container decides what Homebrew installs. The formulas and
  the notes, the tag's CHANGELOG.md entry, are kept in kept/<v>/ with
  their SHA-256s in the state, and checked again before the tap;
- it signs, makes the draft itself, titled devvm <version> with the
  tag's notes, and uploads SHA256SUMS, both signatures and CI's files,
  each hashed as it's sent, keeping an asset only when its size and
  GitHub's digest are right and deleting any other;
- while the bridge lasts it waits for the old key's signature on the
  draft, failing each run so the maintainer hears of it, and downloading
  nothing again while it waits;
- it publishes only when the draft is exactly what it made, its tag,
  title and notes (but for line endings and the space at either end),
  and its assets by ID, size and digest, and the tag still names the tag
  object its rebuild checked; then checks the published release again,
  and finishes the tap.

Alerts and refusals:

- init records the highest release ID GitHub showed and the drafts there
  were then; IDs only go up, so any release published since that isn't a
  draft the co-signer made is an alert, whatever its tag or version, by
  <tag>#<ID>, so another release of an acked tag is alerted on again;
  each run also reads GitHub's latest release, wherever the list puts it.
- A published release that differs from what it checked, its own draft
  published without it seeing the answer that then doesn't check out,
  and a tap formula newer than any release it signed, by
  tap:<formula>@<version>, are alerts; the tap is updated only for a
  release it published and checked after.
- A rebuild that doesn't match is a refusal, which isn't downloaded or
  rebuilt again, even for CI's run again; devvm-cosign retry <tag> lets
  the next run rebuild it once more. Nothing retries on its own.
- Every run fails (exit 1) while an alert or refusal waits, until
  devvm-cosign ack or retry. A run records in last-failure.txt that it
  started, then what failed, or removes it when it succeeds; devvm-cosign failed, which the units' OnFailure=
  runs for any failure, a killed or timed-out run's or a config that
  won't load included, runs notify, the maintainer's command, with it on
  its stdin, a fixed environment and a minute of its own, whatever ended
  the run's context.

Bases go the same way, from the newest successful run of the base
workflow on main, made at the index's commit and never GitHub's latest.

Main makes the process non-dumpable (prctl PR_SET_DUMPABLE 0) before
anything else, so no process of its user can read its memory, where the
keys and token are, and reads the keys from systemd's credentials when
CREDENTIALS_DIRECTORY is set. A run empties the build folder's work/
and the state's stage/ and src/ in place, never making them again.

Tests, each fix reverted once to see it fail: TestPublishedBySomeoneElse
(a release published by someone else, whatever its tag or version, the
same tag again after an ack, a draft from before init published since,
and GitHub's latest past where the list stops; one from before the state
left alone), TestOneBuildPerRun (the build's files in the state, none of
CI's on disk during the build, and the next release left for the next
run), TestFormulas (a build's formula of
its own; a kept formula changed on disk), TestRenderFormula,
TestPrereleasePublished (a tap formula newer than any release signed),
TestDraftChangedBeforePublish (a swapped file, a retag, other notes),
TestTagMovedBeforePublish, TestAlertAfterPublish and
TestLostPublishChecked, TestMismatchSignsNothing (a failure every run,
and retry), TestReplayedOlderVersion (an alert, then acked),
TestNotify, TestLegacyBridge (a failure every run, with no download),
TestRunPagesReleases, TestInitPaged (init past ten pages of bases, which
fails with a page check that stops at its first unfinished entry),
TestRunsChecked, TestArtifactChecked, TestUploadChangedOnDisk,
TestBaseIndexChecked (a re-signed base on a 61-day snapshot),
TestBasePublishChecked, TestBasePublishedElsewhere (an expired base still
counts in checkBehind), TestWorkEmptiedInPlace, TestCommandLine (retry
and ack read no key file), and on Linux TestUndumpable.

A build that fails, rather than differs, is built again at the next
run, but the third failure in a row refuses it, with a report holding
the last failure (buildFailed), so a build that keeps failing no longer
takes every run's one build and holds up each newer release and base;
retry builds it again, and a build stopped with its run isn't counted.
Refusing rather than rotating past it keeps releases oldest first, as
versions only go up, and keeps the failure in front of the maintainer
through held and notify. buildRelease and buildBase are the build and
its comparison, apart from what's recorded. And GitHub's latest release
has to be the one init saw or one the co-signer published, not one of
its own older than another it published: anything else is an alert,
latest:<tag>#<ID> (staleLatest), as the install script's default
downloads it; so is the one init saw, once it's older than one the
co-signer published. The co-signer makes a release GitHub's latest only
when it's newer than every release it published, so publishing an older
release after a newer one, as when the old key signs the newer draft
first, never moves the latest back itself. And a release's run counts
only when a tag's push started it (PushEvent, which the structure
test's nameFree lets name "push"). Tests, each failing before its code:
TestFailingBuildRefused, TestBaseRefused's base that keeps failing,
TestLatestChecked, TestOlderReleaseNotLatest, TestRunsChecked's run by
hand.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 21:36:37 -07:00