You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c42596b
Browse filesBrowse the repository at this point in the historyBrowse files
release: hold the run on the release-approval environment until the staged versions are approved (#6638)
The wait for the npm 2FA approval ran on a hosted runner, so a release had 350 minutes before the job hit GitHub's six-hour cap and had to be re-run. The job now splits into three:
- stage (still on the npm environment, which the trusted publishers are bound to) builds, stages zod and @zod/mini, and writes the approval commands into the step summary.
- approval sits on the release-approval environment. GitHub holds it with no runner for up to 30 days, until the deployment is approved; `stager approve` approves on npm and then approves this deployment.
- finish waits up to 340 minutes for npm to serve both versions, which also absorbs npm's post-approval review, then tags, creates the GitHub release, publishes both packages to JSR and checks lockstep.
The environment approval is only the resume signal. A run resumed without the npm approval fails in finish instead of releasing. When both versions are already served, approval is skipped and finish runs directly.
Also: a workflow-level concurrency group queues a second dispatch behind a held run, the stage job drops contents: write, and the changelog ends at the run's commit rather than main, which may have moved while the run was held.
Copy file name to clipboardExpand all lines: .github/workflows/release.yml
+92-16Lines changed: 92 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,15 @@
3
3
name: Release on npm
4
4
on:
5
5
# Dispatch only, and deliberately so. A `workflow_dispatch` needs a GitHub session or token carrying write access; a stolen git push credential carries neither, so it can no longer start a release by landing a commit or cutting a tag. That is the shape of the 2026-09-21 nubjs/nub compromise, where a stolen push credential cut a tag and 18 packages published unattended. A version bump on main is therefore inert: a maintainer runs `gh workflow run release.yml`, approves the npm environment, and then approves each staged version on npm with 2FA.
6
+
#
7
+
# One run, three release jobs. `stage` puts both versions in npm's staged queue. `approval` is a job on the `release-approval` environment, whose required reviewer is the maintainer: GitHub holds the run there, with no runner, for up to 30 days. The npm approval is the gate; the environment approval only resumes the run, and `finish` checks the registry before it tags or releases anything. `stager approve` does both, approving on npm and then resuming the run.
6
8
workflow_dispatch:
7
9
10
+
# one release at a time, held across the approval wait, so a second dispatch queues instead of staging next to a held run; never cancelled, since a run mid-`npm stage publish` must finish
11
+
concurrency:
12
+
group: release
13
+
cancel-in-progress: false
14
+
8
15
jobs:
9
16
test-node:
10
17
runs-on: ${{ matrix.os }}
@@ -69,17 +76,21 @@ jobs:
69
76
- run: nub install --frozen-lockfile
70
77
- run: nub run check:circular
71
78
72
-
build_and_publish:
79
+
stage:
73
80
needs: [test-node, lint, check-circular]
74
81
runs-on: ubuntu-latest
75
82
# a required reviewer approves every run, and the environment only deploys main; npm's trusted publishers are bound to it so no other branch or workflow can even stage. The environment is the first of two gates — the second is the 2FA approval of each staged version, which this job cannot perform.
76
83
environment: npm
77
-
#6h is GitHub's hard cap for a hosted runner, not a tunable. One wait now covers both packages: they are staged back to back, so a single approval session releases the pair and the maintainer is never asked to be present twice. The wait takes 350 of the 360 minutes. A stall that outlives it needs the wait moved to its own job rather than a larger number here, and that costs a second environment approval.
78
-
timeout-minutes: 360
84
+
#this job only builds and stages; the wait for the approval is the `approval` job, which holds no runner
85
+
timeout-minutes: 60
79
86
permissions:
80
-
contents: write
81
-
pull-requests: read
87
+
contents: read
82
88
id-token: write
89
+
outputs:
90
+
zod: ${{ steps.version.outputs.zod }}
91
+
mini: ${{ steps.version.outputs.mini }}
92
+
# both versions are served already (a re-dispatch after the approval), so there is nothing to wait for and `approval` is skipped
93
+
served: ${{ steps.served.outputs.served }}
83
94
steps:
84
95
- uses: actions/checkout@v7
85
96
with:
@@ -131,11 +142,25 @@ jobs:
131
142
VERSION: ${{ steps.version.outputs.mini }}
132
143
run: bash .github/scripts/npm-stage-publish.sh packages/mini --provenance --access public
133
144
134
-
# THE HUMAN GATE. Both versions sit in the staged queue until a maintainer approves them, and the registry serves them only after that, so everything below — the tag, the GitHub release, both JSR publishes — is downstream of the approval and nothing public ever describes a version npm did not ship. The loop also absorbs the automated review npm runs once a version is approved, which held 4.5.0 for 16 minutes, 4.5.3 for 25 and 4.6.0 for 116; none of those is an upper bound. A GitHub job gets six hours at most. If the approval comes later, re-run this job: a live version is skipped, a staged one is tolerated, and the wait then passes at once.
135
-
- name: Wait for the staged versions to be approved and live
145
+
- name: Check whether npm serves both versions
146
+
id: served
136
147
env:
137
148
ZOD_VERSION: ${{ steps.version.outputs.zod }}
138
149
MINI_VERSION: ${{ steps.version.outputs.mini }}
150
+
run: |
151
+
if curl -sf "https://registry.npmjs.org/zod/$ZOD_VERSION" > /dev/null && curl -sf "https://registry.npmjs.org/@zod%2fmini/$MINI_VERSION" > /dev/null; then
152
+
echo "served=true" >> "$GITHUB_OUTPUT"
153
+
echo "zod@$ZOD_VERSION and @zod/mini@$MINI_VERSION are both served; no approval to wait for"
# shellcheck disable=SC2016 # the backticks below are markdown for the step summary, not command substitution
141
166
{
@@ -144,66 +169,117 @@ jobs:
144
169
echo "- \`zod@$ZOD_VERSION\`"
145
170
echo "- \`@zod/mini@$MINI_VERSION\`"
146
171
echo
147
-
echo 'Neither version is installable until you approve it with 2FA. Read the stage ids with `npm stage list zod` and `npm stage list @zod/mini`, then approve each with `npm stage approve <id>`; `pnpm stage approve` takes both in one interactive picker under a single one-time password, as does the Staged Packages tab on npmjs.com.'
172
+
echo 'Neither version is installable until a maintainer approves it with 2FA. This run is now held on the `release-approval` environment, with no runner, for up to 30 days. It resumes when that deployment is approved, and `finish` then waits for npm to serve both versions before it tags, releases and publishes to JSR.'
173
+
echo
174
+
echo '```'
175
+
echo "stager approve 'zod@$ZOD_VERSION' '@zod/mini@$MINI_VERSION' # approve both in the browser, then resume this run"
176
+
echo "stager reject 'zod@$ZOD_VERSION' '@zod/mini@$MINI_VERSION' # drop both staged versions and fail this run"
177
+
echo '```'
148
178
echo
149
-
echo 'This job waits 350 minutes. If it runs out, approve the versions and re-run it.'
179
+
echo "Without stager: read the stage ids with \`npm stage list zod\` and \`npm stage list @zod/mini\`, then approve each with \`npm stage approve <id>\`; \`pnpm stage approve\` takes both in one interactive picker under a single one-time password, as does the Staged Packages tab on npmjs.com. Then approve the pending \`release-approval\` deployment on $RUN_URL."
150
180
} >> "$GITHUB_STEP_SUMMARY"
151
-
deadline=$(( $(date +%s) + 350 * 60 ))
181
+
182
+
approval:
183
+
# held by the environment's required reviewer, not by a runner: GitHub keeps the run waiting for up to 30 days, with no six-hour cap, until the deployment is approved. It is a resume signal only; a version nobody approved on npm still stops `finish` at the registry check.
184
+
needs: stage
185
+
if: needs.stage.outputs.served != 'true'
186
+
runs-on: ubuntu-latest
187
+
environment: release-approval
188
+
permissions: {}
189
+
steps:
190
+
- env:
191
+
ZOD_VERSION: ${{ needs.stage.outputs.zod }}
192
+
MINI_VERSION: ${{ needs.stage.outputs.mini }}
193
+
run: echo "resuming; finish checks that npm serves zod@$ZOD_VERSION and @zod/mini@$MINI_VERSION"
194
+
195
+
finish:
196
+
needs: [stage, approval]
197
+
# `approval` is skipped when npm already serves both versions, and `finish` still runs then to create whatever an earlier run did not; the explicit condition drops the implicit `success()`, so `stage` is checked by name
# 6h is GitHub's hard cap for a hosted runner; the wait takes 340 minutes of it and the steps after it need a few
201
+
timeout-minutes: 360
202
+
permissions:
203
+
contents: write
204
+
pull-requests: read
205
+
id-token: write
206
+
steps:
207
+
# THE HUMAN GATE. The run resumes on the environment approval, which says nothing about npm, so the tag, the GitHub release and both JSR publishes wait here until the registry serves both versions; nothing public ever describes a version npm did not ship. The loop also absorbs the automated review npm runs once a version is approved, which held 4.5.0 for 16 minutes, 4.5.3 for 25 and 4.6.0 for 116; none of those is an upper bound. If the approval comes later, re-run this job.
208
+
- name: Wait for npm to serve both versions
209
+
env:
210
+
ZOD_VERSION: ${{ needs.stage.outputs.zod }}
211
+
MINI_VERSION: ${{ needs.stage.outputs.mini }}
212
+
run: |
213
+
deadline=$(( $(date +%s) + 340 * 60 ))
152
214
wait_for () {
153
215
local label="$1" url="$2" i=0
154
216
until curl -sf "$url" > /dev/null; do
155
217
if [ "$(date +%s)" -ge "$deadline" ]; then
156
-
echo "::error::$label is still not on the registry; approve the staged version with 2FA, then re-run this job"
218
+
echo "::error::$label is still not served after 340 minutes; if it was never approved on npm, approve it with 2FA (stager approve '$label'), then re-run this job"
157
219
exit 1
158
220
fi
159
221
i=$((i + 1))
160
-
if [ $((i % 15)) -eq 0 ]; then echo "$label is still staged, awaiting approval ($i minutes)"; fi
222
+
if [ $((i % 15)) -eq 0 ]; then echo "$label is not served yet ($i minutes)"; fi
# the job token cannot write a ref once main has moved past this commit with a workflow change, which a run held for days makes likely
197
272
gh release create "v$VERSION" \
198
273
--repo "$GITHUB_REPOSITORY" \
199
274
--target "$GITHUB_SHA" \
200
275
--title "v$VERSION" \
201
-
--notes-file "$RUNNER_TEMP/release_notes.md"
276
+
--notes-file "$RUNNER_TEMP/release_notes.md" \
277
+
|| { echo "::error::could not create v$VERSION at $GITHUB_SHA with the job token; create it with your own (gh release create v$VERSION -R $GITHUB_REPOSITORY --target $GITHUB_SHA --title v$VERSION --generate-notes), then re-run this job"; exit 1; }
202
278
203
279
# last so a jsr outage can't cost the tag — and it aborts on a dirty tree, so nothing above it may leave the workspace dirty
204
280
- name: Publish to JSR
205
281
env:
206
-
VERSION: ${{ steps.version.outputs.zod }}
282
+
VERSION: ${{ needs.stage.outputs.zod }}
207
283
working-directory: ./packages/zod
208
284
run: |
209
285
if curl -sf "https://jsr.io/@zod/zod/${VERSION}_meta.json" > /dev/null; then
0 commit comments