Skip to content

Automate Homebrew tap sync + drift guard - #2157

Merged
mstomar125 merged 2 commits into
mainfrom
issue-2114-homebrew-cask
Aug 19, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-2114-homebrew-cask

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Closes #2114

Problem

homebrew-nodespace's cask (Casks/nodespace.rb) was hand-maintained: version and two per-architecture sha256 digests, 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 nodespace was 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 256 on it (cross-checked against the digest GitHub's own release-assets API reports). Verified with brew style, brew audit --cask --online, and an actual brew install --cask + nodespace --version in 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: false via 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-architecture on_arm/on_intel shape.

Automation (this PR)

scripts/update-homebrew-cask.ts:

  • Resolves per-architecture digests from the actual published release assets (gh release view --json assets), downloads each .dmg, hashes with node:crypto — never types or copies a digest.
  • Renders Casks/nodespace.rb in whichever shape the release actually supports: on_arm/on_intel when both macOS architectures exist, or a single depends_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; --push commits and pushes to homebrew-nodespace's main, gated on HOMEBREW_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 (via gh release list --json isLatest, not a raw tag scan, which would trip over this repo's own review-* tooling tags). Exits non-zero with the fix command on drift.

Wired into .github/workflows/release.yml as a new sync-homebrew-cask job, gated on the ARM macOS build succeeding (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 instead of failing silently.

This job cannot succeed yet — HOMEBREW_TAP_TOKEN isn't configured as a repo secret (it needs contents: write on homebrew-nodespace; secrets.GITHUB_TOKEN can'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 and notify-failure surfaces 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_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 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.
  • Live dry run against the real v0.2.0 release: bun run scripts/update-homebrew-cask.ts 0.2.0 correctly detects the missing Intel .dmg, warns, and computes sha256 b19edf95... — the exact same digest computed by hand for homebrew-nodespace#1.
  • Live drift-check against the real repos right now: correctly reports the tap's actual current drift (v0.1.6 vs v0.2.0) and exits 1.
  • The generator's rendered cask passes brew style clean in an isolated Homebrew prefix (a separate Homebrew/brew clone outside /opt/homebrew, so nothing touched this machine's real Homebrew install).
  • .github/workflows/release.yml and the new homebrew-drift-check.yml validated as syntactically-valid YAML.
  • Did not trigger any GitHub Actions workflow or cut a real release — all verification above is read-only against already-published data, or against an isolated local Homebrew instance.

Follow-ups filed

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.
@mstomar125

Copy link
Copy Markdown
Contributor Author

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:

  1. `homebrew-drift-check.yml` had no `permissions:` block — 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). Fixed: added `contents: read` + `issues: write`.
  2. Drift-check couldn't distinguish genuine drift from the check itself failing (network/gh/auth blip) — both hit the same exit-1 path with the same generic issue body. Fixed: `checkTapDrift()` errors now produce a clearly distinct "DRIFT CHECK ERROR (not necessarily drift...)" message, and the workflow tees the step's real output into the filed issue body instead of a fixed sentence.
  3. The dual-architecture (`on_arm`/`on_intel`) render path was unverified against real `brew style` — unlike the single-arch path (checked against the actual hand-verified companion cask). Tested it directly against a real isolated `brew style` run: it was missing a blank line between the nested `sha256`/`url` stanzas (`Cask/StanzaGrouping` applies inside `on_arm`/`on_intel` blocks too). Fixed and re-verified clean; added a regression test.

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.

@mstomar125
mstomar125 merged commit 14a67bd into main Aug 19, 2026
@mstomar125
mstomar125 deleted the issue-2114-homebrew-cask branch August 19, 2026 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Homebrew tap is two months stale (v0.1.6 vs v0.2.0): cask is hand-maintained instead of generated on release

1 participant