Repository navigation
Automate Homebrew tap sync + drift guard - #2157
Conversation
homebrew-nodespace's cask was hand-maintained: version and two per-architecture sha256 digests, edited by hand in a separate repo on every release, with nothing checking or reminding. It silently drifted for two months (v0.1.6 while v0.2.0 shipped) before anyone noticed. Adds scripts/update-homebrew-cask.ts: - Resolves per-architecture digests from the actual release assets (gh release view --json assets), downloads each .dmg, and hashes it with node:crypto -- never types or copies a digest. - Renders Casks/nodespace.rb in either shape depending on what the release actually published: on_arm/on_intel when both macOS architectures exist, or a single depends_on-arch-scoped cask when only one does (the current real case -- v0.2.0 has no Intel .dmg, see #2154). Missing architectures are a loud warning, not a crash. - `<version> [--push]`: dry run by default (prints the generated cask); --push commits and pushes it to homebrew-nodespace's main branch, gated on HOMEBREW_TAP_TOKEN (a token scoped to that repo -- secrets.GITHUB_TOKEN can't push cross-repo). - `drift-check`: compares the tap's live cask version (fetched from the tap's raw Casks/nodespace.rb) against the latest published release (via `gh release list --json isLatest`, not a raw tag scan -- the naive default trips over this repo's own review-* tooling tags). Exits non-zero with the exact fix command on drift. Wires it into release.yml as `sync-homebrew-cask`, gated on the ARM macOS build (the one leg that must succeed -- Intel is best-effort per #2154) and `github.event_name == 'release'`. Added to notify-failure's needs so a failed push also opens a GitHub issue, not just a red run. Not exercised by this PR -- HOMEBREW_TAP_TOKEN doesn't exist as a repo secret yet; someone with admin on this repo needs to add one (a PAT with contents:write on homebrew-nodespace) before the job can succeed. Until then it fails loudly and notify-failure surfaces it, which is a correct, visible failure mode rather than a silent no-op. Adds .github/workflows/homebrew-drift-check.yml: a standalone daily + workflow_dispatch check, independent of the release flow, per the issue's ask for drift to be "detectable even if a sync step is bypassed." Opens a GitHub issue on drift, same pattern as release.yml's notify-failure. scripts/update-homebrew-cask.test.ts covers the offline, deterministic logic (digest hashing against a known fixture, cask rendering for both single- and dual-architecture shapes, the drift comparison predicate) -- the GitHub-talking functions are intentionally untested here since this suite runs as part of the pre-push gate and must stay network-free. Verified live against the real repos (read-only): drift-check correctly reports the tap's actual current drift (v0.1.6 vs v0.2.0, exit 1); a dry run against v0.2.0 reproduces the exact sha256 (b19edf95...) computed by hand for NodeSpaceAI/homebrew-nodespace#1, and its rendered cask passes `brew style` clean in an isolated Homebrew prefix. Companion fix (separate repo, already opened): NodeSpaceAI/homebrew-nodespace#1 bumps the cask to v0.2.0 by hand as the immediate one-off fix this automation would have produced.
Three real bugs found by review, all verified against real tooling before and after the fix: - homebrew-drift-check.yml had no `permissions:` block, so its failure step's `gh issue create` would very likely 403 -- release.yml's sibling notify-failure job declares issues:write for the identical reason, this one didn't. Added contents:read + issues:write. - drift-check couldn't distinguish "genuine tap drift" from "the check itself failed to run" (network blip, gh/auth error) -- both hit the same exit-1 path with the same generic filed-issue body, so an operator triaging it couldn't tell which happened without opening the raw run log. checkTapDrift() is now wrapped so a thrown error produces a clearly distinct "DRIFT CHECK ERROR (not necessarily drift...)" message instead of reading as a TAP DRIFT report, and the workflow now tees the step's real output into the filed issue body instead of a fixed generic sentence. - The dual-architecture (on_arm/on_intel) render path in renderCask was unverified against real `brew style` -- unlike the single-arch path, which was checked against the actual hand-verified companion cask. Tested it directly: a real `brew style` run in the isolated Homebrew prefix flagged a missing blank line between the nested sha256/url stanzas (Cask/StanzaGrouping applies inside on_arm/ on_intel blocks too, not just at the top level). Fixed and re-verified clean. Added a regex assertion to the dual-arch test so this can't silently regress. Also, defense in depth on a lower-severity finding (HOMEBREW_TAP_TOKEN embedded in the git remote URL for the push): wrapped the clone call so any thrown error has the token scrubbed from its message before surfacing, and added a comment documenting the accepted residual risk (argv visibility on the runner during the clone/push window, and the temp credential URL living in workDir/.git/config until the existing finally-block cleanup runs) -- git's own error output already redacts credentials from URLs (verified empirically), so this closes the one gap that wasn't already covered. Added a top-level try/catch around main(), matching test-gate.ts's established error-handling convention in this repo -- previously any uncaught rejection printed a raw Bun stack trace/ShellError dump instead of an operator-facing message.
|
Adversarial review (sub-agent, ran `gh pr diff` for real and independently verified against a live isolated Homebrew prefix) found 3 real bugs and 2 nits:
Nits also addressed: scrubbed `HOMEBREW_TAP_TOKEN` from any thrown clone error before it could surface (git's own error output already redacts it, verified empirically, but added defense in depth + documented the accepted residual risk), and added a top-level try/catch in `main()` matching `test-gate.ts`'s established error-handling convention in this repo. All fixed in 043d6cb. Full `bun run test:scripts` (103/103) and the pre-push gate (frontend + Rust + e2e) pass. Re-verified the dual-arch fix against a real `brew style` run and the single-arch path's exact byte-for-byte match to the hand-verified companion cask (NodeSpaceAI/homebrew-nodespace#1) still holds. Self-approving and merging — small, additive, no Rust changes (clippy/fmt not applicable to this diff), no hosted CI on this repo by design. |
Closes #2114
Problem
homebrew-nodespace's cask (Casks/nodespace.rb) was hand-maintained:versionand two per-architecturesha256digests, edited by hand in a separate repo on every release, with nothing in the release flow updating it and nothing checking or reminding. It silently drifted for two months (cask pinned to v0.1.6 while v0.2.0 shipped 2026-06-25) before anyone noticed —brew install nodespacewas serving a stale build the whole time.Immediate fix (separate repo, already opened)
NodeSpaceAI/homebrew-nodespace#1 bumps the cask to v0.2.0 by hand, as the one-off this automation would have produced. Digest computed by downloading the real release asset and running
shasum -a 256on it (cross-checked against the digest GitHub's own release-assets API reports). Verified withbrew style,brew audit --cask --online, and an actualbrew install --cask+nodespace --versionin an isolated Homebrew prefix — full details in that PR. That PR is open but I don't have write access to homebrew-nodespace (confirmed:push: falsevia the repo's permissions API) — it needs someone with write access to merge.While fixing it, found the current release only ships an Apple Silicon
.dmg— no Intel/x64 macOS build exists in v0.2.0 despite CI appearing to build one. Filed #2154 to track that separately; it's why the cask (and this automation) currently render an arm64-only cask rather than the two-architectureon_arm/on_intelshape.Automation (this PR)
scripts/update-homebrew-cask.ts:gh release view --json assets), downloads each.dmg, hashes withnode:crypto— never types or copies a digest.Casks/nodespace.rbin whichever shape the release actually supports:on_arm/on_intelwhen both macOS architectures exist, or a singledepends_on arch:-scoped cask when only one does (today's real case). A missing architecture is a loud warning, not a silent gap or a crash.<version> [--push]— dry run by default;--pushcommits and pushes tohomebrew-nodespace'smain, gated onHOMEBREW_TAP_TOKEN(a repo secret that doesn't exist yet — see below).drift-check— compares the tap's live cask version against the latest published release (viagh release list --json isLatest, not a raw tag scan, which would trip over this repo's ownreview-*tooling tags). Exits non-zero with the fix command on drift.Wired into
.github/workflows/release.ymlas a newsync-homebrew-caskjob, gated on the ARM macOS build succeeding (the one leg that must succeed; Intel is best-effort per #2154) andgithub.event_name == 'release'. Added tonotify-failure'sneedsso a failed push also opens a GitHub issue instead of failing silently.This job cannot succeed yet —
HOMEBREW_TAP_TOKENisn't configured as a repo secret (it needscontents: writeonhomebrew-nodespace;secrets.GITHUB_TOKENcan't push cross-repo, and I don't have admin rights to add repo secrets here). Until someone with admin access adds it, the job fails loudly on the next real release andnotify-failuresurfaces that — a correct, visible failure mode rather than a silent no-op. Noting this explicitly since it's the one manual step left to make this fully automatic.Also adds
.github/workflows/homebrew-drift-check.yml: a standalone daily +workflow_dispatchcheck, independent of the release flow, per the issue's ask for drift to be "detectable even if a sync step is bypassed." Opens a GitHub issue on drift, same pattern asrelease.yml'snotify-failure.scripts/update-homebrew-cask.test.tscovers the offline, deterministic logic (digest hashing against a known fixture, cask rendering for both cask shapes, the drift-comparison predicate). The GitHub-talking functions are intentionally untested there — that suite runs as part of the pre-push gate (bun run test:scripts/test:all) and must stay network-free.Verification
bun test scripts/update-homebrew-cask.test.ts— 10/10 pass.bun run test:scripts(full suite) — 103/103 pass.bun run scripts/update-homebrew-cask.ts 0.2.0correctly detects the missing Intel.dmg, warns, and computessha256 b19edf95...— the exact same digest computed by hand for homebrew-nodespace#1.drift-checkagainst the real repos right now: correctly reports the tap's actual current drift (v0.1.6 vs v0.2.0) and exits 1.brew styleclean in an isolated Homebrew prefix (a separateHomebrew/brewclone outside/opt/homebrew, so nothing touched this machine's real Homebrew install)..github/workflows/release.ymland the newhomebrew-drift-check.ymlvalidated as syntactically-valid YAML.Follow-ups filed