Skip to content

Commit ad052dc

Browse files
ivndev001ivndev001claude
authored
ci(release): publish to npm with OIDC trusted publishing and provenance (#9)
* ci(release): publish to npm with OIDC trusted publishing and provenance Release-triggered (plus a dry-run-by-default workflow_dispatch) publish of @developerz.ai/claudes. No NPM_TOKEN: id-token: write + provenance. Same SHA-pinned actions as ci.yml, bun 1.4.3, bin/check before publish, and a guard that the release tag equals v + package.json version. npm pinned to 12.2.0: the packed-bundle sigstore regression (npm/cli#9722) was fixed by npm/cli#9740 (merged 2026-07-10). Closes #6 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(release): close the publish paths both review lenses found - workflow_dispatch is dry-run only; only a published release publishes - split jobs: build (no id-token) packs + verifies the tarball and runs the tag==version and release-commit-on-main guards; publish (needs build, environment npm, id-token) ships only that artifact; dry-run job has no id-token - no registry-url anywhere, so a missing OIDC exchange fails loudly - npm 12.2.0 installed from a sha512-verified tarball, version asserted - concurrency grouped per event, so a dry run cannot displace a release - upload/download-artifact pinned by SHA (v7.0.2, v8.0.2) - header documents the npm trusted-publisher fields incl. environment npm Repo settings applied alongside: environment npm restricted to v* tags, tag ruleset release-tags (admins only create/update/delete v*). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(release): document the mandatory npm environment; guards first - header: the npm trusted-publisher environment field is mandatory here (blank = any ref of release.yml may publish); allow `npm publish` explicitly; 2-day first-publish window; exact `npm trust github` command - tag and release-on-main guards now run right after checkout, before any project code - npm version and sha512 defined once in workflow env - guard message names the real package.json version; fetch-depth comment corrected Repo setting alongside: environment npm can_admins_bypass=false. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(release): verify the publish landed; least-privilege publish job - publish job grants id-token only (no checkout, so no contents) - after publishing, poll npm view for the exact version (60s) so a stage-only trusted publisher cannot report a green release that installs nothing - install step names no longer hard-code the npm version Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(release): token-free, re-runnable registry check; empty dry-run perms - the "is it installable" check moves out of the publish job into its own verify job (needs publish, permissions {}): re-running it can never re-run the immutable publish, and it runs with no token at all - its message names the real cause (registry lag), waits 5 minutes, and says to re-run only verify; the wrong "stage-only" diagnosis is gone - dry-run job now has permissions {}, matching publish minus id-token - install step names show the pinned npm version Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(release): refuse GitHub pre-releases; no bun cache in the build job - a release flagged pre-release fails in build before anything else runs (it would otherwise move npm's latest dist-tag) - setup-bun in the job that builds the provenance-signed artifact uses no-cache, so a cache written by another workflow can never be restored Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(release): pre-release refusal gives a remediation that works Converting a published pre-release fires 'released', not 'published', and a re-run replays the original payload, so 'untick pre-release' was a dead end. The message now says to delete and re-create the release from the same tag. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: ivndev001 <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent f8b800a commit ad052dc

1 file changed

Lines changed: 232 additions & 0 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
name: Release
2+
3+
# ---------------------------------------------------------------------------
4+
# npm trusted publishing (OIDC) settings this workflow depends on.
5+
#
6+
# On npmjs.com, the @developerz.ai/claudes package must have a trusted
7+
# publisher configured with exactly:
8+
# organization: developerz-ai
9+
# repository: claudes
10+
# workflow: release.yml
11+
# environment: npm
12+
# allowed: npm publish (configs created after 2026-09-03 default to
13+
# `npm stage publish` only, which refuses this workflow)
14+
# npm calls the environment field optional, but it is MANDATORY here: left
15+
# blank, npm accepts a token from ANY run of release.yml on ANY ref, and the
16+
# v* restriction on the GitHub "npm" environment protects nothing. A config
17+
# must complete its first successful publish within 2 days or it expires.
18+
# npm trust github @developerz.ai/claudes --file release.yml \
19+
# --repo developerz-ai/claudes --env npm --allow-publish
20+
#
21+
# On GitHub, the "npm" environment (Settings -> Environments) must be
22+
# restricted to v* tags so that only published releases can enter the
23+
# publish job.
24+
# ---------------------------------------------------------------------------
25+
26+
on:
27+
release:
28+
types: [published]
29+
workflow_dispatch: # dry-run only; a dispatch can never publish for real
30+
31+
# One group per event type, so a dispatched dry run can never displace a
32+
# release (and vice versa). Nothing is cancelled mid-run, but a newer
33+
# release cut inside the same publish window still replaces a pending
34+
# (queued, not yet started) release run.
35+
concurrency:
36+
group: release-${{ github.event_name }}
37+
cancel-in-progress: false
38+
39+
# The npm that publishes (and that the dry run rehearses): one definition.
40+
env:
41+
NPM_VERSION: 12.2.0
42+
NPM_SHA512: ZsJjKpTnlmSXOLLXiU1xDCzC4Wlok4IwZmh/aw2KUuXytU7q6qMv/cUT7MoeSf95Slwuw/lRXYefGzGCspHPNQ==
43+
44+
permissions:
45+
contents: read
46+
47+
jobs:
48+
build:
49+
runs-on: ubuntu-latest
50+
timeout-minutes: 15
51+
permissions:
52+
contents: read # no id-token: this job never talks to npm
53+
outputs:
54+
tarball: ${{ steps.pack.outputs.tarball }}
55+
steps:
56+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
57+
with:
58+
persist-credentials: false
59+
# Full history: fetches all branches and tags, so origin/main exists
60+
# for the ancestry guard below.
61+
fetch-depth: 0
62+
- name: Pre-releases are not published
63+
if: github.event_name == 'release' && github.event.release.prerelease
64+
run: |
65+
echo "::error title=Pre-release refused::this workflow publishes stable releases only; a GitHub pre-release would move the npm 'latest' tag. Delete this release (the tag stays) and create a new, non-pre-release release from the same tag. Editing this release in place or re-running this run will not work: neither fires a new 'published' event." >&2
66+
exit 1
67+
- name: Release tag must equal v + package.json version
68+
if: github.event_name == 'release'
69+
env:
70+
RELEASE_TAG: ${{ github.event.release.tag_name }}
71+
run: |
72+
version="$(node -p "require('./package.json').version")"
73+
expected="v$version"
74+
if [ "$RELEASE_TAG" != "$expected" ]; then
75+
echo "::error title=Tag/version mismatch::release tag '$RELEASE_TAG' does not match package.json version '$version' (expected tag '$expected'). Bump the version in package.json and re-cut the release." >&2
76+
exit 1
77+
fi
78+
- name: Release commit must already be on main
79+
if: github.event_name == 'release'
80+
run: |
81+
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
82+
echo "::error title=Release not on main::commit $GITHUB_SHA is not an ancestor of origin/main. A release must point at a commit already merged to main." >&2
83+
exit 1
84+
fi
85+
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
86+
with:
87+
bun-version: 1.4.3
88+
# This job builds the artifact that gets provenance-signed: never
89+
# restore a Bun binary from a cache another workflow could have written.
90+
no-cache: true
91+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
92+
with:
93+
node-version: 24
94+
# No registry-url: nothing in this job authenticates to npm.
95+
- run: bun install --frozen-lockfile
96+
- run: bin/check
97+
- name: Pack and verify tarball
98+
id: pack
99+
run: |
100+
tgz="$(npm pack | tail -n 1)"
101+
expected="$(printf '%s\n' package/LICENSE package/README.md package/dist/claudes.js package/package.json | sort)"
102+
actual="$(tar -tzf "$tgz" | sort)"
103+
if [ "$actual" != "$expected" ]; then
104+
echo "::error title=Unexpected tarball contents::$tgz must contain exactly package/dist/claudes.js, package/package.json, package/README.md and package/LICENSE." >&2
105+
echo "expected:" && printf '%s\n' "$expected"
106+
echo "actual:" && printf '%s\n' "$actual"
107+
exit 1
108+
fi
109+
echo "tarball=$tgz" >> "$GITHUB_OUTPUT"
110+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
111+
with:
112+
name: npm-tarball
113+
path: ${{ steps.pack.outputs.tarball }}
114+
if-no-files-found: error
115+
116+
publish:
117+
needs: build
118+
if: github.event_name == 'release'
119+
runs-on: ubuntu-latest
120+
timeout-minutes: 15
121+
environment: npm # GitHub env restricted to v* tags; also the OIDC environment name on npmjs.com
122+
permissions:
123+
id-token: write # the only grant: OIDC trusted publishing; no NPM_TOKEN anywhere
124+
env:
125+
TARBALL: ${{ needs.build.outputs.tarball }}
126+
steps:
127+
# No checkout, no bun, no project dependencies: this job only ships
128+
# the tarball the build job verified.
129+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
130+
with:
131+
node-version: 24
132+
# No registry-url: auth comes from OIDC trusted publishing.
133+
# Trusted publishing (OIDC) needs npm >= 11.5.1. Install a pinned,
134+
# digest-verified npm rather than whatever node ships. Pin 12.2.0 to be
135+
# clear of the packed-bundle sigstore regression, where `npm publish
136+
# --provenance` died on "Cannot find module 'sigstore'":
137+
# https://github.com/npm/cli/issues/9722, fixed by
138+
# https://github.com/npm/cli/pull/9740 (merged 2026-07-10). Only [email protected]
139+
# (2026-07-08) shipped broken; from 12.0.1 onward the tarball bundles
140+
# node_modules/sigstore again, and in [email protected] the require.resolve chain
141+
# from libnpmpublish through sigstore and @sigstore/* was verified against
142+
# the actual packed tarball.
143+
- name: Install pinned npm ${{ env.NPM_VERSION }} from a verified tarball
144+
run: |
145+
curl -fsSLo npm.tgz "https://registry.npmjs.org/npm/-/npm-${NPM_VERSION}.tgz"
146+
expected="$NPM_SHA512"
147+
actual="$(openssl dgst -sha512 -binary npm.tgz | openssl base64 -A)"
148+
if [ "$actual" != "$expected" ]; then
149+
echo "::error title=npm tarball digest mismatch::expected sha512 (base64) $expected but got $actual. Refusing to install an unverified npm." >&2
150+
exit 1
151+
fi
152+
npm install -g ./npm.tgz
153+
if [ "$(npm --version)" != "$NPM_VERSION" ]; then
154+
echo "::error title=npm version mismatch::installed npm $(npm --version), expected $NPM_VERSION." >&2
155+
exit 1
156+
fi
157+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
158+
with:
159+
name: npm-tarball
160+
path: artifact
161+
# Publishing the packed tarball (not the working directory) means
162+
# prepublishOnly cannot re-run and nothing outside the verified
163+
# artifact reaches the registry.
164+
- name: Publish
165+
run: npm publish "./artifact/$TARBALL" --access public --provenance --loglevel verbose
166+
167+
verify:
168+
needs: [build, publish]
169+
if: github.event_name == 'release'
170+
runs-on: ubuntu-latest
171+
timeout-minutes: 10
172+
permissions: {} # read-only public registry check; no token of any kind
173+
env:
174+
TARBALL: ${{ needs.build.outputs.tarball }}
175+
steps:
176+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
177+
with:
178+
node-version: 24
179+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
180+
with:
181+
name: npm-tarball
182+
path: artifact
183+
# Separate job so "Re-run failed jobs" repeats only this check: the
184+
# publish itself is immutable and must never be re-run.
185+
- name: Confirm the version is visible on the registry
186+
run: |
187+
version="$(tar -xzOf "./artifact/$TARBALL" package/package.json | node -p 'JSON.parse(require("fs").readFileSync(0,"utf8")).version')"
188+
for _ in $(seq 1 30); do
189+
if [ "$(npm view "@developerz.ai/claudes@$version" version)" = "$version" ]; then
190+
echo "visible: @developerz.ai/claudes@$version"
191+
exit 0
192+
fi
193+
sleep 10
194+
done
195+
echo "::error title=Not yet visible::the publish job succeeded, but @developerz.ai/claudes@$version is not visible on the registry after 5 minutes. This is usually registry propagation lag. Check 'npm view @developerz.ai/claudes versions' manually, and re-run only this verify job. Do NOT re-run publish: the version is immutable." >&2
196+
exit 1
197+
198+
dry-run:
199+
needs: build
200+
if: github.event_name == 'workflow_dispatch'
201+
runs-on: ubuntu-latest
202+
timeout-minutes: 15
203+
permissions: {} # same as publish minus id-token: a dry run can never publish
204+
env:
205+
TARBALL: ${{ needs.build.outputs.tarball }}
206+
steps:
207+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
208+
with:
209+
node-version: 24
210+
# No registry-url: a dry run does not authenticate to npm.
211+
# Same digest-verified npm install as the publish job; see that job
212+
# for why npm 12.2.0 specifically (npm/cli#9722, npm/cli#9740).
213+
- name: Install pinned npm ${{ env.NPM_VERSION }} from a verified tarball
214+
run: |
215+
curl -fsSLo npm.tgz "https://registry.npmjs.org/npm/-/npm-${NPM_VERSION}.tgz"
216+
expected="$NPM_SHA512"
217+
actual="$(openssl dgst -sha512 -binary npm.tgz | openssl base64 -A)"
218+
if [ "$actual" != "$expected" ]; then
219+
echo "::error title=npm tarball digest mismatch::expected sha512 (base64) $expected but got $actual. Refusing to install an unverified npm." >&2
220+
exit 1
221+
fi
222+
npm install -g ./npm.tgz
223+
if [ "$(npm --version)" != "$NPM_VERSION" ]; then
224+
echo "::error title=npm version mismatch::installed npm $(npm --version), expected $NPM_VERSION." >&2
225+
exit 1
226+
fi
227+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
228+
with:
229+
name: npm-tarball
230+
path: artifact
231+
- name: Publish (dry run)
232+
run: npm publish "./artifact/$TARBALL" --dry-run --access public --loglevel verbose

0 commit comments

Comments
 (0)