Skip to content

ci(publish): require the release PR to be merged before npm publish - #3989

Merged
dyoshikawa merged 1 commit into
mainfrom
resolve-issue-3804-publish-merged-only-gate
Nov 27, 2026
Merged

dyoshikawa merged 1 commit into
mainfrom
resolve-issue-3804-publish-merged-only-gate

Conversation

@dyoshikawa

Copy link
Copy Markdown
Owner

[needs maintainer review: workflow change]

Summary

Hardens the npm Publish gate in .github/workflows/publish.yml (follow-ups from #3800). Nothing that the gate allowed before is loosened: the job-level if: is unchanged, and a new first step adds a merged-only check.

Changes

  • Item 1 (merged-only): new first step "Verify the release PR was merged". Publish Assets runs on pull_request: closed with the PR's own workflow definition, so its merged == true condition can be rewritten by anyone who can push a release/v* branch and then close the PR unmerged. The step now requires github.event.workflow_run.head_sha to be reachable from main, using GET /repos/{repo}/compare/main...{head_sha} and accepting only behind or identical. It runs before checkout, the cicd-sensor, dependency install and pnpm publish, so nothing else runs when it fails.
    • The SHA is passed through env (no inline interpolation in run) and validated as 40 lowercase hex characters before it is used in the API path.
    • Any API error (for example 404 for an unknown commit) fails the step, because the default bash -e shell stops on the failing command substitution. The check fails closed.
    • It only needs contents: read, which the job already has (contents: write); no new permission and no repository settings change.
  • Item 2: the gate comment now says that head_repository.full_name == github.repository is what blocks forks (a fork editing publish-assets.yml in place keeps the same path), that the path check is a secondary guard, and that an unmerged same-repo PR is caught by the new step.

Verification

Run against the live API with the same call the step makes:

  • 3a36159b… (head of the merged release PR Release v43.15.0 #3974, the head_sha of the v43.15.0 Publish Assets run): behind → passes.
  • current main tip: identical → passes.
  • bea7bcd0… (head of a same-repo PR closed without merging): diverged → fails.
  • a SHA that is not in the repository: HTTP 404 → fails.
  • actionlint 1.7.11 passes on the file.

Checks

pnpm cicheck: lint, type checks and cicheck:content pass. A few wall-clock-budget tests (src/utils/glob.test.ts, shell-command-categories.test.ts, opencode-hooks.test.ts and similar) timed out at 5s because the machine was at load average ~70 on 8 cores; they pass when rerun alone or with --testTimeout=60000. This PR touches no src/ file, so their result does not depend on it.

Design decisions

  • Ancestor check instead of a protected environment. The triage recommended it: it needs no repository settings and adds no manual approval to every release. A protected npm-publish environment with required reviewers is still an option on top of this if wanted.
  • Compare API instead of a full-history checkout. git merge-base --is-ancestor would need fetch-depth: 0 on main; the compare endpoint answers the same question with the existing token and no extra clone.
  • Ancestor check instead of looking up the merged PR. Looking up the PR (mergedAt, headRefOid) would also work with squash merges, but needs pull-requests: read on a job that holds the npm OIDC token. Release PRs are merged with a merge commit (goal-release uses gh pr merge --admin --merge, and v43.13.0-v43.15.0 were merged that way), so the head commit is on main. Caveat: if a release PR is ever squash- or rebase-merged, its head commit is not on main, this step fails, and npm publishing has to be done by hand. The workflow comment says so.

Skipped items

Closes #3804

🤖 Generated with Claude Code

https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4

Publish Assets runs on pull_request: closed with the PR's own workflow
definition, so a same-repo collaborator could rewrite it and close a
release/v* PR unmerged to reach the npm Publish job. Check that
workflow_run.head_sha is reachable from main before anything else runs.
Also reword the gate comment: the head_repository check is what blocks
forks, and the path check is a secondary guard.

Refs #3804

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
@dyoshikawa
dyoshikawa merged commit 58fabc6 into main Nov 27, 2026
13 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-issue-3804-publish-merged-only-gate branch November 27, 2026 05:48
@dyoshikawa dyoshikawa mentioned this pull request Nov 29, 2026
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.

Follow-ups from #3800: npm Publish gate hardening

1 participant