ci(release): only release commits that are on main

Merged
JW
9d ago
+82-3

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-main runs gh api repos/$GITHUB_REPOSITORY/compare/$SHA...main --jq .status on github.sha and accepts only ahead or identical, the same check as instacloud-platform deploy-prod.yml. It also covers workflow_dispatch runs, which use the dispatched ref's head.
  • build, release and publish-npm all needs: require-main directly, 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 stubbed gh (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
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-main job that every other release job depends on directly; it fails unless GitHub's compare of the release commit against main returns ahead or identical, covering both tag pushes and workflow_dispatch runs.
  • Adds a regression test that verifies all release jobs depend on the gate and runs the gate script against stubbed gh responses, 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-pinned workflow_run publish would close it in CI as well.