Repository navigation
ci(publish): require the release PR to be merged before npm publish - #3989
Merged
Merged
Conversation
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
3 tasks
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[needs maintainer review: workflow change]
Summary
Hardens the npm
Publishgate in.github/workflows/publish.yml(follow-ups from #3800). Nothing that the gate allowed before is loosened: the job-levelif:is unchanged, and a new first step adds a merged-only check.Changes
Publish Assetsruns onpull_request: closedwith the PR's own workflow definition, so itsmerged == truecondition can be rewritten by anyone who can push arelease/v*branch and then close the PR unmerged. The step now requiresgithub.event.workflow_run.head_shato be reachable frommain, usingGET /repos/{repo}/compare/main...{head_sha}and accepting onlybehindoridentical. It runs before checkout, the cicd-sensor, dependency install andpnpm publish, so nothing else runs when it fails.env(no inline interpolation inrun) and validated as 40 lowercase hex characters before it is used in the API path.bash -eshell stops on the failing command substitution. The check fails closed.contents: read, which the job already has (contents: write); no new permission and no repository settings change.head_repository.full_name == github.repositoryis what blocks forks (a fork editingpublish-assets.ymlin place keeps the samepath), that thepathcheck 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, thehead_shaof the v43.15.0Publish Assetsrun):behind→ passes.maintip:identical→ passes.bea7bcd0…(head of a same-repo PR closed without merging):diverged→ fails.actionlint 1.7.11passes on the file.Checks
pnpm cicheck: lint, type checks andcicheck:contentpass. A few wall-clock-budget tests (src/utils/glob.test.ts,shell-command-categories.test.ts,opencode-hooks.test.tsand 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 nosrc/file, so their result does not depend on it.Design decisions
environment. The triage recommended it: it needs no repository settings and adds no manual approval to every release. A protectednpm-publishenvironment with required reviewers is still an option on top of this if wanted.git merge-base --is-ancestorwould needfetch-depth: 0onmain; the compare endpoint answers the same question with the existing token and no extra clone.mergedAt,headRefOid) would also work with squash merges, but needspull-requests: readon a job that holds the npm OIDC token. Release PRs are merged with a merge commit (goal-releaseusesgh pr merge --admin --merge, and v43.13.0-v43.15.0 were merged that way), so the head commit is onmain. Caveat: if a release PR is ever squash- or rebase-merged, its head commit is not onmain, 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