Repository navigation
ci: harden the release and CI workflows - #62
Conversation
- Release: runs only for refs/heads/main and in the npm-publish environment, so the npm trusted publisher can be bound to it. Default token permissions are empty, and the job gets only contents: read and id-token: write. - Checkout no longer persists credentials into .git/config. The release-App token is minted just before semantic-release, limited to contents/issues/ pull-requests, and passed only to that step (semantic-release builds its own authenticated push URL from GITHUB_TOKEN). - All actions are pinned to the commit SHAs their current major tags point to, and Bun is pinned to 1.4.4 in both workflows. - Corrected the comment: semantic-release pushes the version commit and tag before npm publish, so a failed publish leaves the tag. Co-Authored-By: Claude Opus 5.5 <[email protected]>
abogartz
left a comment
There was a problem hiding this comment.
Request changes. Most of this is good hygiene that I verified independently and would merge on its own. Two of the four justifications are wrong, and the setup instructions as written cannot be carried out — so the parts that touch the release path should be re-scoped.
Verified accurate (keep as-is)
- SHA pins. All four verified against their tags with
gh api:actions/checkout@11d5960…=v4.4.0,oven-sh/setup-bun@0c5077e…=v2.2.0,actions/setup-node@49933ea…=v4.4.0,actions/create-github-app-token@fee1f7d…=v2.2.2. No behaviour change, and job names are unchanged so the ruleset's required contexts (lint,test,smoke) keep matching. - Token on disk.
actions/checkoutdefaults topersist-credentials: true, so passing the App token there does leave it in the runner's git config for every later step in a job that also holdsid-token: write.persist-credentials: falseis the right fix. - Excess default permissions.
contents/issues/pull-requests: writeat workflow level were unused, since all writes go through the App token. x-access-token:claim. Verified insemantic-release/lib/get-git-auth-url.js(~line 69): underGITHUB_ACTION,GITHUB_TOKENis turned into anx-access-token:-prefixed push URL. So dropping persisted checkout credentials and passing the App token to thenpx semantic-releasestep is the documented path.- The comment you corrected. Run
40015784259logsCreated tag v0.8.0beforeStart step "publish" of "@semantic-release/npm", so the old sentence was wrong and yours is right. The corroborating evidence also checks out:v0.3.4andv0.4.0exist as git tags but appear in neither the npm version list nor the GitHub releases. - Your own CI run on this PR exercises the
ci.ymlhalf on a real runner (lint/test/smoke all pass with Bun 1.4.4 andpersist-credentials: false), so that file is not merely "parses". Onlyrelease.ymlis untested end-to-end.
Requested change 1: the "any branch can publish" premise is false
.releaserc.json pins "branches": ["main"], and semantic-release checks the head branch against that config before it does anything publishable (semantic-release/index.js:65-73):
This test run was triggered on the branch <x>, while semantic-release is configured to only publish from main, therefore a new version won't be published.
A workflow_dispatch on another branch therefore reaches semantic-release and stops. if: github.ref == 'refs/heads/main' is still worth having as drift protection (if .releaserc.json's branches ever widens, or a second publish path appears) — please reframe it as defence-in-depth rather than a fixed hole, because the framing is what justifies the risky half below.
Requested change 2: the npm steps are not executable, and the ordering is unsafe
Per npm's current trusted-publishing docs:
- "Existing trusted publisher connections cannot be changed. The provider and required fields for a connection are fixed once it's created. To change them, delete the connection and create a new one." → step 2's "edit the trusted publisher … add environment
npm-publish" cannot be done. - "A newly created trusted publisher configuration must complete its first successful publish within 2 days… If the configuration is not validated within 2 days, it expires and can no longer be used or edited."
Combined with your ordering ("merge this, then do step 2; until then the existing no-environment entry still matches runs in npm-publish"), the merge bets the next release on a claim that neither npm's docs nor any test in this PR establishes: whether a trusted publisher configured without an environment still matches a job whose OIDC token carries one. If it does not, the first merge-to-main after this lands fails, and if the replacement config is then created and also mismatches, it expires in 2 days and the package has no working publisher at all.
Please re-sequence so no release is ever dependent on unverified matching:
- Create the
npm-publishenvironment with deployment branches restricted tomain. - Add a second trusted-publisher entry (up to 10 are allowed) with environment
npm-publish, leaving the existing entry untouched. - Merge, let a normal merge-to-
mainrelease run, and confirm the provenance statement names the environment. - Only then delete the no-environment entry.
Optionally gate step 1–2 behind keeping environment: out of the YAML until the environment exists, so the workflow is never pointing at a not-yet-created environment.
Requested change 3: drop the approval-recommendation paragraph
"Also worth considering in the Main ruleset: require at least one approval"
This repo is solo-authored and GitHub forbids approving your own PR, which is why the ruleset is deliberately at 0 approvals with PR-required + required checks. As written this advice is unusable; either drop it or restate it as something achievable (a second maintainer account, or code owners).
Nits
bun-version: 1.4.4is a good pin; note local dev here is Bun 1.4.3, so consider a comment saying CI pins the version deliberately and where to bump it (this repo has pinned-Bun behaviour notes, e.g. theBun.write({append:true})truncation trap).mint App token → semantic-releaseis the right ordering. Consider alsopermission-contents/issues/pull-requests: writebeing narrowed — confirm the App's installation permissions actually include all three, otherwiseverifyConditionsfails later than it would today.
Review follow-up for abogartz#62: .releaserc.json already restricts publishing to main, so the job guard is documented as defence in depth. The Bun pin is commented as deliberate, with all four pins to be bumped together. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, you were right on both counts. Pushed c817f39 and rewrote the description:
|
abogartz
left a comment
There was a problem hiding this comment.
Approving — merge deferred to a later cycle.
The revision addresses everything I asked for, and I re-verified the new claims independently rather than taking the description at face value:
- Pins unchanged: the same four SHAs I verified against their tags last cycle (
checkout@11d5960…=v4.4.0,setup-bun@0c5077e…=v2.2.0,setup-node@49933ea…=v4.4.0,create-github-app-token@fee1f7d…=v2.2.2). Required contexts (lint/test/smoke) still match the ruleset. - The
x-access-tokenclaim is true. I inspected the pinned semantic-release:lib/get-git-auth-url.jsbuilds thex-access-token:-prefixed push URL fromGITHUB_TOKENwhenGITHUB_ACTIONis set, so dropping persisted checkout credentials does not strand the release push. - Framing is now honest: the guard comment says plainly that
.releaserc.jsonbranches: ["main"]is what stops other branches today, and the guard/environment are defence in depth. That is exactly right. - Setup steps 1–4 are executable in the order given.
Not merging this cycle: the npm-publish environment and the second trusted publisher do not exist yet, and I want the first release through the new workflow to happen deliberately right after they do. Approval stands; if nothing is pushed to the branch, this PR is ready to merge any time I do the setup.
…ment The trusted publisher on npmjs.com is configured for the workflow file alone; an environment would change the OIDC subject and break the next publish until npm is reconfigured. Environment gating can be revisited together with the npm-side change.
|
Dropped |
Publish plugins run in .releaserc.json order (npm -> git -> github), so an npm publish failure means no bump commit, no tag, and no GitHub release — the statement inverted in abogartz#62 said the opposite.
|
🎉 This PR is included in version 0.9.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This tightens
release.ymlandci.yml. I found these issues while reviewing 0.8.0. Updated after your review: the branch guard is now described as defence in depth, the npm steps follow your sequence, and the approvals paragraph is gone.The problem:
actions/checkout. By default checkout writes it into.git/config, where every later step can read it. Those steps include unpinned third-party actions andbun-version: latest, in a job that also hasid-token: write.GITHUB_TOKENgetscontents/issues/pull-requests: write, which the job never uses, because all writes go through the App token.npm publish. A failed publish leaves the tag, which may be how v0.3.4 and v0.4.0 ended up as tags with no npm release..releaserc.json'sbranches: ["main"]already stops semantic-release on any other branch, so aworkflow_dispatchelsewhere can't publish today. Themainguard and environment just mean that protection no longer rests on that one config line. They'd still hold if the branch list ever widens or a second publish path appears.Change:
if: github.ref == 'refs/heads/main'(with a comment saying it's defence in depth) andenvironment: npm-publish;permissions: {}, with the job getting onlycontents: readandid-token: write;persist-credentials: false.x-access-token:push URL fromGITHUB_TOKENonce checkout no longer persists credentials.bun-versionlines together.Setup, in your order, so no release ever depends on unverified matching. Steps 1 and 2 come before the merge:
npm-publishenvironment, and under deployment branches allow onlymain.opencode-self-improvement(ownerabogartz, repoopencode-self-improvement, workflowrelease.yml, environmentnpm-publish). Leave the existing no-environment entry untouched. Existing entries can't be edited, and a new one expires if it hasn't published within 2 days.ci:commit is not a releasable type, so its own merge won't publish. The first real test is the nextfix:/feat:merge, so do step 2 when you're ready to merge one of the fix PRs soon after this one; that keeps you inside the 2-day window. Check that its provenance statement names thenpm-publishenvironment.If the environment doesn't exist when this merges, GitHub would create it automatically with no branch restriction. That's why step 1 comes first.
App permissions. The token now requests exactly contents, issues and pull-requests write. Before, it inherited everything the installation had. I can't see your App's installation settings. If any of the three is missing,
create-github-app-tokenfails at the mint step, before semantic-release starts, so nothing is half-released. It's worth a glance at the App's settings before merging.Checks:
uses:is a full 40-character SHA, and I verified each one against its tag withgh api.ci.ymlhalf on a real runner (lint/test/smoke pass with Bun 1.4.4 andpersist-credentials: false).release.ymlcan't be exercised end to end without a real release. Step 3 is that test.Merge order: one of six PRs from the same review. This one doesn't conflict with the others.
🤖 Generated with Claude Code