ci(release): only release commits that are on main
Why
release.yml runs on any v* tag push and publishes to npm with --provenance and id-token: write. Nothing checks that the tagged commit is on main, so anyone with write access could tag an unreviewed commit and ship it to npm and to the GitHub Release that install.sh and insta upgrade serve. Found in a security audit.
Change
- New first job
require-mainrunsgh api repos/$GITHUB_REPOSITORY/compare/$SHA...main --jq .statusongithub.shaand accepts onlyaheadoridentical, the same check as instacloud-platformdeploy-prod.yml. It also coversworkflow_dispatchruns, which use the dispatched ref's head. build,releaseandpublish-npmallneeds: require-maindirectly, so an off-main commit gets no build, no GitHub Release and no npm publish. Everything else works as before.test/release-workflow.test.ts: parses the workflow, checks every other job depends on the gate, and runs the gate script against a stubbedgh(ahead/identical pass; behind/diverged/empty fail).- Dev skill: the release section now describes the gate and the new
v*tag ruleset, plus two new gotcha rows.
Separately (repo setting, not in this diff): a repository ruleset on refs/tags/v* now lets only repo admins create, update or delete release tags.
Testing
npm run typecheck && npm test: 108 files, 2279 passed, 1 skipped.- The new test passes 7 of 7.
- actionlint was not run here (the local sandbox blocked it). The YAML parses in the new test, and CI will exercise it.
🤖 Generated with Claude Code
![Autofix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.
Summary by cubic
Fixes a release security gap where any v* tag push (or workflow dispatch) let a write-permission holder publish an unreviewed commit to the GitHub Release served by install.sh and insta upgrade, and to npm with a provenance attestation.
- Adds a
require-mainjob that every other release job depends on directly; it fails unless GitHub's compare of the release commit againstmainreturnsaheadoridentical, covering both tag pushes andworkflow_dispatchruns. - Adds a regression test that verifies all release jobs depend on the gate and runs the gate script against stubbed
ghresponses, asserting the exact exit code and refusal message so a script crash can't pass as a refusal. - Documents the gate and the new
v*tag ruleset in the dev skill; the ruleset is a separate repo setting that limits release tag creation to repo admins. - Limits: a tag push runs the tagged commit's own
release.yml, so an off-main commit without the gate isn't stopped by this job. The admin-only tag ruleset closes that path, and a main-pinnedworkflow_runpublish would close it in CI as well.