Skip to content

Commit 89e9d6f

Browse files
neumarkclaude
andauthored
R3-527: the release job mirrors prettier-config — approval-gated, npm pinned (#3)
R3-527's Architecture named prettier-config's release job as the model. This one was a single unattended job on `npm@latest`, which differs from it in the two ways that matter: - No `environment: production` and no approval assertion, so a push to main published a public, irreversible npm version with no human decision in the loop (R-TA-1). Split into `test` + `release`, with prettier-config's fail-closed assertion — an environment GitHub auto-creates is unprotected, so naming one is not proof of a gate. - `npm@latest` lets a release job float across a major unattended. [email protected] shipped without libnpmpublish's `sigstore` dependency, so every `npm publish --provenance` threw `Cannot find module 'sigstore'` (npm/cli#9722) — that is what broke the SDK's 0.29.0 and the transpiler's 0.5.0. It is fixed in [email protected], so the pin is hygiene rather than a workaround; 11.x is the line the org's other publishes are proven on. (prettier-config's own comment still describes this as an open regression.) Also drops the "package does not exist on npm yet — skipping" bootstrap branch. npm cannot configure a trusted publisher for a name that has never been published, so the bootstrap is a one-time manual `npm publish` by the operator, not something CI can reach — a branch that waits for it can only mask a real publish failure afterwards (R5). Merge this after that publish; the PR body carries the two operator steps. Untested: .github/workflows/ci.yml — CI configuration, exercised by the run it configures; `npm test` (26 tests) and `check:publish-version` are green on this head. Claude-Session: https://claude.ai/code/session_01K7LpQeBDrEP6ornpuSvyHt Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
1 parent 671e82b commit 89e9d6f

1 file changed

Lines changed: 61 additions & 26 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
name: ci
22

33
# Test on every PR + push; publish to npm on push to main via npm trusted
4-
# publishing (OIDC), mirroring platform-constants / the SDK release job. The
5-
# five core repos consume this package as a pinned github: dependency until the
6-
# npm trusted-publishing link exists, then move to pinned npm versions.
7-
# NOTE: npm trusted publishing must be configured for this package on
8-
# npmjs.com before the FIRST publish can succeed (an unpublished package name
9-
# cannot be published by OIDC alone). Until the operator links it, the publish
10-
# step detects the E404 and skips loudly; once the package exists on npm the
11-
# step is a real gate and a red run means a stale or mislinked publish.
4+
# publishing (OIDC). Mirrors prettier-config's split
5+
# (immediately-run/prettier-config/.github/workflows/ci.yml), which R3-527's
6+
# Architecture names as the model: the release half is a separate job behind
7+
# `environment: production`, because R-TA-1 (TESTING_AUTOMATION_SPEC §6) makes
8+
# publishing a public artifact DECISION-gated — an npm version is irreversible
9+
# and consumer-facing. Keeping it in one job would gate every PR run behind an
10+
# approval too.
11+
#
1212
# check:publish-version (R3-327) moves the "shipped bytes changed ⇒ version
13-
# bumped" question to PR time.
13+
# bumped" question to PR time, where the release job never runs.
1414
on:
1515
push:
1616
branches: [main]
1717
pull_request:
1818

1919
jobs:
20-
test-publish:
20+
test:
2121
runs-on: ubuntu-latest
2222
permissions:
2323
contents: read
24-
id-token: write # npm trusted publishing (OIDC)
2524
steps:
2625
- uses: actions/checkout@v6
2726
with:
@@ -32,31 +31,67 @@ jobs:
3231
- uses: actions/setup-node@v6
3332
with:
3433
node-version: '24'
35-
registry-url: 'https://registry.npmjs.org'
36-
package-manager-cache: false # never cache in release builds
37-
# Trusted publishing requires npm >= 11.5.1
38-
- run: npm install -g npm@latest
34+
package-manager-cache: false
3935
# R3-327 — shipped bytes changed ⇒ the version was bumped in this PR
4036
- name: Shipped bytes changed ⇒ the version was bumped in this PR
4137
if: github.event_name == 'pull_request'
4238
run: npm run check:publish-version
4339
- run: npm ci
4440
- run: npm test
45-
- name: Publish to npm via trusted publishing (skip if version already published)
46-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
41+
42+
release:
43+
needs: test
44+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
45+
runs-on: ubuntu-latest
46+
environment: production
47+
permissions:
48+
contents: read
49+
id-token: write # npm trusted publishing (OIDC)
50+
actions: read # read THIS run's approval history (the assertion below)
51+
steps:
52+
# Fail-closed authority gate (ways_of_working §2). GitHub auto-creates an
53+
# UNPROTECTED environment when a workflow names one that does not exist, so
54+
# declaring `environment: production` is not by itself proof of a human gate.
55+
# Refuse to publish rather than publish an irreversible version unattended.
56+
- name: Assert this run cleared the `production` approval gate
57+
env:
58+
GH_TOKEN: ${{ github.token }}
59+
run: |
60+
APPROVALS=$(gh api "repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/approvals")
61+
COUNT=$(printf '%s' "$APPROVALS" | jq '[.[] | select(.state == "approved") | select(any(.environments[]?; .name == "production"))] | length')
62+
if [ "${COUNT:-0}" -lt 1 ]; then
63+
echo "::error::No human approval recorded for environment 'production' on this run. Configure Settings → Environments → production → Required reviewers, then re-run. Refusing to publish an irreversible public version unattended (TESTING_AUTOMATION_SPEC R-TA-1)."
64+
exit 1
65+
fi
66+
printf '%s' "$APPROVALS" | jq -r '.[] | select(.state == "approved") | "approved by \(.user.login): \(.comment // "")"'
67+
68+
- uses: actions/checkout@v6
69+
- uses: actions/setup-node@v6
70+
with:
71+
node-version: '24'
72+
registry-url: 'https://registry.npmjs.org'
73+
package-manager-cache: false # never cache in release builds
74+
# Trusted publishing requires npm >= 11.5.1. Pinned to a major line rather than
75+
# `npm@latest`, so a release cannot float across a major unattended: [email protected]
76+
# shipped without libnpmpublish's `sigstore` dependency and every
77+
# `npm publish --provenance` threw `Cannot find module 'sigstore'` (npm/cli#9722),
78+
# which is what broke the SDK's 0.29.0 and the transpiler's 0.5.0. That one is
79+
# fixed in [email protected], so this pin is hygiene, not a workaround — 11.x is the line
80+
# the org's other publishes are proven on.
81+
- run: npm install -g npm@11
82+
83+
# Only publish when package.json's version is new. The deliberate release act is
84+
# therefore the VERSION BUMP landing on main, not the merge itself (R-TA-1).
85+
- name: Publish if the version is new
4786
env:
4887
# setup-node's registry-url writes an .npmrc bound to NODE_AUTH_TOKEN.
4988
# Clearing it forces OIDC trusted publishing instead of (empty) token auth.
50-
NODE_AUTH_TOKEN: ""
89+
NODE_AUTH_TOKEN: ''
5190
run: |
52-
PKG_NAME=$(node -p "require('./package.json').name")
53-
PKG_VER=$(node -p "require('./package.json').version")
54-
if ! npm view "$PKG_NAME" version >/dev/null 2>&1; then
55-
echo "::notice::$PKG_NAME does not exist on npm yet — trusted publishing is not linked (operator step). Skipping the publish; everything else ran."
56-
exit 0
57-
fi
58-
if npm view "$PKG_NAME@$PKG_VER" version >/dev/null 2>&1; then
59-
echo "::notice::$PKG_NAME@$PKG_VER already published — skipping."
91+
PKG=$(node -p "require('./package.json').name")
92+
VER=$(node -p "require('./package.json').version")
93+
if npm view "$PKG@$VER" version >/dev/null 2>&1; then
94+
echo "$PKG@$VER is already published — nothing to do."
6095
exit 0
6196
fi
6297
npm publish --access public

0 commit comments

Comments
 (0)