Skip to content

Commit c42596b

Browse files
authored
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.
1 parent bacad51 commit c42596b

2 files changed

Lines changed: 99 additions & 22 deletions

File tree

‎.github/scripts/npm-stage-publish.sh‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
# reaches the registry only once a maintainer approves it with 2FA — a proof of presence that no
66
# token, and no stolen push credential, can supply.
77
#
8-
# Idempotent, because the job it runs in is re-run after a late approval: a version the registry
9-
# already serves is skipped, and a version already sitting in the staged queue makes `npm stage
10-
# publish` refuse, which counts as success here — the approval wait downstream is what decides
11-
# whether the version arrived. That refusal's exact wording is matched loosely, since the first
12-
# stage-only release is where it gets observed; anything else is fatal.
8+
# Idempotent, because a release can be dispatched again for a version an earlier run staged: a
9+
# version the registry already serves is skipped, and a version already sitting in the staged queue
10+
# makes `npm stage publish` refuse, which counts as success here — the registry check in the
11+
# workflow's `finish` job is what decides whether the version arrived. That refusal's exact wording
12+
# is matched loosely, since the first stage-only release is where it gets observed; anything else
13+
# is fatal.
1314
set -euo pipefail
1415

1516
dir="${1:?usage: npm-stage-publish.sh <package-dir> [npm stage publish flags...]}"
@@ -34,7 +35,7 @@ if (cd "$dir" && npm stage publish "$@") > "$out" 2>&1; then
3435
fi
3536
cat "$out"
3637
if grep -qiE 'already (been )?staged|staged version|E409|EPUBLISHCONFLICT|previously published' "$out"; then
37-
echo "$name@$version is already staged; the approval wait decides the rest"
38+
echo "$name@$version is already staged; the finish job's registry check decides the rest"
3839
exit 0
3940
fi
4041
echo "::error::staging $name@$version failed"

‎.github/workflows/release.yml‎

Lines changed: 92 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
name: Release on npm
44
on:
55
# 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.
68
workflow_dispatch:
79

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+
815
jobs:
916
test-node:
1017
runs-on: ${{ matrix.os }}
@@ -69,17 +76,21 @@ jobs:
6976
- run: nub install --frozen-lockfile
7077
- run: nub run check:circular
7178

72-
build_and_publish:
79+
stage:
7380
needs: [test-node, lint, check-circular]
7481
runs-on: ubuntu-latest
7582
# 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.
7683
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
7986
permissions:
80-
contents: write
81-
pull-requests: read
87+
contents: read
8288
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 }}
8394
steps:
8495
- uses: actions/checkout@v7
8596
with:
@@ -131,11 +142,25 @@ jobs:
131142
VERSION: ${{ steps.version.outputs.mini }}
132143
run: bash .github/scripts/npm-stage-publish.sh packages/mini --provenance --access public
133144

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
136147
env:
137148
ZOD_VERSION: ${{ steps.version.outputs.zod }}
138149
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"
154+
else
155+
echo "served=false" >> "$GITHUB_OUTPUT"
156+
fi
157+
158+
- name: Say how to approve
159+
if: steps.served.outputs.served != 'true'
160+
env:
161+
ZOD_VERSION: ${{ steps.version.outputs.zod }}
162+
MINI_VERSION: ${{ steps.version.outputs.mini }}
163+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
139164
run: |
140165
# shellcheck disable=SC2016 # the backticks below are markdown for the step summary, not command substitution
141166
{
@@ -144,66 +169,117 @@ jobs:
144169
echo "- \`zod@$ZOD_VERSION\`"
145170
echo "- \`@zod/mini@$MINI_VERSION\`"
146171
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 '```'
148178
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."
150180
} >> "$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
198+
if: ${{ !cancelled() && needs.stage.result == 'success' && (needs.approval.result == 'success' || (needs.approval.result == 'skipped' && needs.stage.outputs.served == 'true')) }}
199+
runs-on: ubuntu-latest
200+
# 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 ))
152214
wait_for () {
153215
local label="$1" url="$2" i=0
154216
until curl -sf "$url" > /dev/null; do
155217
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"
157219
exit 1
158220
fi
159221
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
161223
sleep 60
162224
done
163225
echo "$label is live"
164226
}
165227
wait_for "zod@$ZOD_VERSION" "https://registry.npmjs.org/zod/$ZOD_VERSION"
166228
wait_for "@zod/mini@$MINI_VERSION" "https://registry.npmjs.org/@zod%2fmini/$MINI_VERSION"
167229
230+
- uses: actions/checkout@v7
231+
with:
232+
fetch-depth: 0
233+
234+
- name: Set up Nub
235+
uses: nubjs/setup-nub@47e5e7393d50f4e9544ddaf756aa277972afba2d # v0
236+
with:
237+
nub-version: "0.8.3"
238+
239+
- run: nub install --frozen-lockfile
240+
168241
- name: Configure changelog
169242
run: |
170243
printf '%s\n' '{"categories": [], "template": "## Commits:\n\n#{{UNCATEGORIZED}}", "pr_template": "- #{{MERGE_SHA}} #{{TITLE}}"}' > changelog_config.json
171244
cat changelog_config.json
172245
echo "last_tag=$(git describe --tags --abbrev=0)" >> "$GITHUB_ENV"
173246
247+
# the run's commit rather than `github.ref`: main may have moved on while the run was held
174248
- name: Generate changelog
175249
id: github_release
176250
uses: mikepenz/release-changelog-builder-action@v6
177251
env:
178252
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
179253
with:
180254
fromTag: "${{ env.last_tag }}"
181-
toTag: ${{ github.ref }}
255+
toTag: ${{ github.sha }}
182256
mode: COMMIT
183257
configuration: changelog_config.json
184258

185259
# notes go through env and a file so a commit subject can't break out of the command
186260
- name: Create release
187261
env:
188262
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
189-
VERSION: ${{ steps.version.outputs.zod }}
263+
VERSION: ${{ needs.stage.outputs.zod }}
190264
CHANGELOG: ${{ steps.github_release.outputs.changelog }}
191265
run: |
192266
if gh release view "v$VERSION" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
193267
echo "v$VERSION is already released"
194268
exit 0
195269
fi
196270
printf '%s' "$CHANGELOG" > "$RUNNER_TEMP/release_notes.md"
271+
# 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
197272
gh release create "v$VERSION" \
198273
--repo "$GITHUB_REPOSITORY" \
199274
--target "$GITHUB_SHA" \
200275
--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; }
202278
203279
# 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
204280
- name: Publish to JSR
205281
env:
206-
VERSION: ${{ steps.version.outputs.zod }}
282+
VERSION: ${{ needs.stage.outputs.zod }}
207283
working-directory: ./packages/zod
208284
run: |
209285
if curl -sf "https://jsr.io/@zod/zod/${VERSION}_meta.json" > /dev/null; then

0 commit comments

Comments
 (0)