Skip to content

ci: harden the release and CI workflows - #62

Merged
abogartz merged 5 commits into
abogartz:mainfrom
WhollyMindless:fix/release-hardening
Oct 25, 2026
Merged

abogartz merged 5 commits into
abogartz:mainfrom
WhollyMindless:fix/release-hardening

Conversation

@WhollyMindless

@WhollyMindless WhollyMindless commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

This tightens release.yml and ci.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:

  • Token stored on disk. The release-App token, which is a bypass actor on the Main ruleset, is passed to actions/checkout. By default checkout writes it into .git/config, where every later step can read it. Those steps include unpinned third-party actions and bun-version: latest, in a job that also has id-token: write.
  • Excess permissions. The default GITHUB_TOKEN gets contents/issues/pull-requests: write, which the job never uses, because all writes go through the App token.
  • Wrong comment. The comment says "If the npm step fails, no tag or GitHub release is created". Your v0.8.0 run (40015784259) shows semantic-release pushing the version commit and tag before 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.
  • Defence in depth, not a live hole. As you pointed out, .releaserc.json's branches: ["main"] already stops semantic-release on any other branch, so a workflow_dispatch elsewhere can't publish today. The main guard 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:

  • Release job:
    • if: github.ref == 'refs/heads/main' (with a comment saying it's defence in depth) and environment: npm-publish;
    • top-level permissions: {}, with the job getting only contents: read and id-token: write;
    • checkout with persist-credentials: false.
  • App token:
    • Minted just before semantic-release, requesting only contents, issues and pull-requests write, and passed only to that step.
    • semantic-release builds its own x-access-token: push URL from GITHUB_TOKEN once checkout no longer persists credentials.
  • Both workflows: every action is pinned to the commit SHA its current major tag points to (checkout v4.4.0, setup-node v4.4.0, create-github-app-token v2.2.2, setup-bun v2.2.0), so behaviour is unchanged. Bun is pinned to 1.4.4, with a comment explaining the pin is deliberate and saying to bump all four bun-version lines together.
  • Comment: corrected to describe what actually happens. Release semantics are unchanged.

Setup, in your order, so no release ever depends on unverified matching. Steps 1 and 2 come before the merge:

  1. Create the npm-publish environment, and under deployment branches allow only main.
  2. On npmjs.com, add a second trusted publisher for opencode-self-improvement (owner abogartz, repo opencode-self-improvement, workflow release.yml, environment npm-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.
  3. Merge. This PR's ci: commit is not a releasable type, so its own merge won't publish. The first real test is the next fix:/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 the npm-publish environment.
  4. Only then delete the no-environment entry.

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-token fails 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:

  • Both files parse.
  • Every uses: is a full 40-character SHA, and I verified each one against its tag with gh api.
  • This PR's own CI run exercises the ci.yml half on a real runner (lint/test/smoke pass with Bun 1.4.4 and persist-credentials: false).
  • release.yml can'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

- 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 abogartz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/checkout defaults to persist-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 holds id-token: write. persist-credentials: false is the right fix.
  • Excess default permissions. contents/issues/pull-requests: write at workflow level were unused, since all writes go through the App token.
  • x-access-token: claim. Verified in semantic-release/lib/get-git-auth-url.js (~line 69): under GITHUB_ACTION, GITHUB_TOKEN is turned into an x-access-token:-prefixed push URL. So dropping persisted checkout credentials and passing the App token to the npx semantic-release step is the documented path.
  • The comment you corrected. Run 40015784259 logs Created tag v0.8.0 before Start step "publish" of "@semantic-release/npm", so the old sentence was wrong and yours is right. The corroborating evidence also checks out: v0.3.4 and v0.4.0 exist 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.yml half on a real runner (lint/test/smoke all pass with Bun 1.4.4 and persist-credentials: false), so that file is not merely "parses". Only release.yml is 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:

  1. Create the npm-publish environment with deployment branches restricted to main.
  2. Add a second trusted-publisher entry (up to 10 are allowed) with environment npm-publish, leaving the existing entry untouched.
  3. Merge, let a normal merge-to-main release run, and confirm the provenance statement names the environment.
  4. 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.4 is 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. the Bun.write({append:true}) truncation trap).
  • mint App token → semantic-release is the right ordering. Consider also permission-contents/issues/pull-requests: write being narrowed — confirm the App's installation permissions actually include all three, otherwise verifyConditions fails 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]>
@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Thanks, you were right on both counts. Pushed c817f39 and rewrote the description:

  • The main guard is now described, in the PR and in a YAML comment, as defence in depth behind .releaserc.json's branches: ["main"].
  • The npm steps follow your sequence: create the environment, add a second publisher, merge, verify provenance on the next real release, and only then delete the old entry. One wrinkle: this PR's ci: commit won't trigger a release, so step 2's 2-day window needs a fix:/feat: merge soon after. The description says so.
  • The approvals paragraph is gone.
  • Nits: there's a comment explaining that the Bun pin is deliberate (bump all four together). On the App permissions: if the installation lacks any of the three, create-github-app-token fails at the mint step, before semantic-release starts, so nothing is half-released. I can't see your installation settings, so that's worth a glance.

@abogartz abogartz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-token claim is true. I inspected the pinned semantic-release: lib/get-git-auth-url.js builds the x-access-token:-prefixed push URL from GITHUB_TOKEN when GITHUB_ACTION is set, so dropping persisted checkout credentials does not strand the release push.
  • Framing is now honest: the guard comment says plainly that .releaserc.json branches: ["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.
@abogartz

Copy link
Copy Markdown
Owner

Dropped environment: npm-publish (7e60dd6) per maintainer decision: the npm trusted publisher is configured for the workflow file alone, and an environment name enters the OIDC subject claims — merging with it would break the next publish until npmjs.com is reconfigured. The rest of the hardening stands as reviewed; environment gating can return as its own change bundled with the npm-side update. Header comment updated to match.

@abogartz
abogartz merged commit db80da9 into abogartz:main Oct 25, 2026
3 checks passed
WhollyMindless pushed a commit to WhollyMindless/opencode-self-improvement that referenced this pull request Oct 25, 2026
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.
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.9.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@WhollyMindless
WhollyMindless deleted the fix/release-hardening branch October 26, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants