Skip to content

Commit 85b4627

Browse files
authored
fix(release): verify the registry in bounded windows, with at most two follow-up verification jobs (#9658)
* fix(release): registry verification waits up to 30 minutes, backing off from 15 s to 60 s, for slow-propagating packages * fix(release): verify in bounded 8-minute windows and hand unreadable packages to at most two follow-up verification jobs * test(release): nothing acts on a stable release before the final verification decides the run * fix(release): refuse a non-numeric verification window, and give follow-up jobs a 7-minute window inside their 10-minute limit * test(release): bound the CLI runs so an endless window fails the test instead of hanging it * Merge branch 'main' into fix/verify-published-longer-wait
1 parent d0cf29a commit 85b4627

4 files changed

Lines changed: 403 additions & 16 deletions

File tree

‎.github/scripts/release-publish-workflow.test.mjs‎

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ async function runCanaryPublish({
184184
}
185185

186186
/** Runs the stable publish step over two packages with stubbed npm and pnpm. */
187-
function runStablePublish({failingPackage = '', failOnce = ''} = {}) {
187+
function runStablePublish({
188+
failingPackage = '',
189+
failOnce = '',
190+
verifyExit = null,
191+
} = {}) {
188192
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-stable-publish-'));
189193
const publishLog = path.join(root, 'publish.log');
190194
try {
@@ -212,6 +216,9 @@ function runStablePublish({failingPackage = '', failOnce = ''} = {}) {
212216
writeExecutable(root, 'npm', '#!/bin/sh\nexit 1\n');
213217
writeExecutable(root, 'pnpm', PNPM_STUB);
214218
const publisherEnv = withPublisher(root);
219+
if (verifyExit !== null) writeVerifierStub(root, verifyExit);
220+
const githubOutput = path.join(root, 'github-output');
221+
fs.writeFileSync(githubOutput, '');
215222
const result = spawnSync(
216223
'bash',
217224
['-c', step(stable, 'Publish changed packages').run],
@@ -224,6 +231,7 @@ function runStablePublish({failingPackage = '', failOnce = ''} = {}) {
224231
DRY_RUN: 'false',
225232
FAIL_ONCE: failOnce,
226233
FAIL_PACKAGE: failingPackage,
234+
GITHUB_OUTPUT: githubOutput,
227235
PATH: `${path.join(root, 'bin')}:${process.env.PATH}`,
228236
PUBLISH_LOG: publishLog,
229237
RELEASE_VERSION: '0.7.7',
@@ -232,6 +240,7 @@ function runStablePublish({failingPackage = '', failOnce = ''} = {}) {
232240
);
233241
return {
234242
...result,
243+
output: fs.readFileSync(githubOutput, 'utf8'),
235244
published: fs.existsSync(publishLog)
236245
? fs.readFileSync(publishLog, 'utf8')
237246
: '',
@@ -241,6 +250,39 @@ function runStablePublish({failingPackage = '', failOnce = ''} = {}) {
241250
}
242251
}
243252

253+
/** A registry verifier stand-in that exits with `code`. */
254+
function writeVerifierStub(root, code) {
255+
const file = path.join(root, 'scripts/npm/verify-published.mjs');
256+
fs.mkdirSync(path.dirname(file), {recursive: true});
257+
fs.writeFileSync(file, `process.exit(${code});\n`);
258+
}
259+
260+
/** Runs one follow-up verification job's script with a verifier stand-in. */
261+
function runFollowUp(job, verifyExit) {
262+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-verify-'));
263+
try {
264+
writeVerifierStub(root, verifyExit);
265+
const githubOutput = path.join(root, 'github-output');
266+
fs.writeFileSync(githubOutput, '');
267+
const result = spawnSync(
268+
'bash',
269+
['-c', step(job, 'Verify published packages').run],
270+
{
271+
cwd: root,
272+
encoding: 'utf8',
273+
env: {
274+
...process.env,
275+
GITHUB_OUTPUT: githubOutput,
276+
RELEASE_VERSION: '0.7.7',
277+
},
278+
},
279+
);
280+
return {...result, output: fs.readFileSync(githubOutput, 'utf8')};
281+
} finally {
282+
fs.rmSync(root, {recursive: true, force: true});
283+
}
284+
}
285+
244286
describe('stable and canary publication authority', () => {
245287
it('keeps stable explicit and canary limited to main pushes', () => {
246288
expect(stable.if).toBe("github.event_name == 'workflow_dispatch'");
@@ -609,4 +651,97 @@ describe('stable publish requires the cut commit release-check (spec:AST-030 FR1
609651
expect(stable.steps[guard]['continue-on-error']).toBeUndefined();
610652
expect(stable.permissions.actions).toBe('read');
611653
});
654+
655+
it('passes the release when every package is readable in the first window', () => {
656+
const result = runStablePublish({verifyExit: 0});
657+
658+
expect(result.status).toBe(0);
659+
expect(result.output).toContain('verified=true');
660+
});
661+
662+
it('ends the publish job as "not yet readable", not failed, and hands over to a follow-up', () => {
663+
const result = runStablePublish({verifyExit: 2});
664+
665+
expect(result.status).toBe(0);
666+
expect(result.output).toContain('verified=pending');
667+
expect(result.stdout).toContain('not yet readable on the registry');
668+
});
669+
670+
it('still fails the publish job on a verification error', () => {
671+
const result = runStablePublish({verifyExit: 1});
672+
673+
expect(result.status).toBe(1);
674+
expect(result.output).not.toContain('verified=');
675+
});
676+
677+
it('runs at most two bounded follow-up verification jobs, each only while packages are pending', () => {
678+
const first = workflow.jobs['verify-registry-1'];
679+
const last = workflow.jobs['verify-registry-2'];
680+
const followUps = Object.keys(workflow.jobs).filter(name =>
681+
name.startsWith('verify-registry'),
682+
);
683+
684+
expect(followUps).toEqual(['verify-registry-1', 'verify-registry-2']);
685+
expect(stable.outputs.verified).toBe(
686+
'${{ steps.publish.outputs.verified }}',
687+
);
688+
expect(first.needs).toBe('publish');
689+
expect(first.if).toBe("needs.publish.outputs.verified == 'pending'");
690+
expect(last.needs).toBe('verify-registry-1');
691+
expect(last.if).toBe(
692+
"needs.verify-registry-1.outputs.verified == 'pending'",
693+
);
694+
for (const job of [first, last]) {
695+
expect(job['runs-on']).toBe('ubuntu-latest');
696+
expect(job['timeout-minutes']).toBeLessThanOrEqual(10);
697+
expect(job.permissions).toEqual({contents: 'read'});
698+
expect(step(job, 'Verify published packages').run).toContain(
699+
'node scripts/npm/verify-published.mjs --version "$RELEASE_VERSION" --tag latest --window-ms 420000',
700+
);
701+
}
702+
});
703+
704+
it('hands a still-pending check from the first follow-up to the last one', () => {
705+
const pending = runFollowUp(workflow.jobs['verify-registry-1'], 2);
706+
expect(pending.status).toBe(0);
707+
expect(pending.output).toContain('verified=pending');
708+
709+
const readable = runFollowUp(workflow.jobs['verify-registry-1'], 0);
710+
expect(readable.status).toBe(0);
711+
expect(readable.output).toContain('verified=true');
712+
});
713+
714+
it('fails the release when the last follow-up still finds a package unreadable', () => {
715+
const result = runFollowUp(workflow.jobs['verify-registry-2'], 2);
716+
717+
expect(result.status).toBe(2);
718+
expect(result.stdout).toContain(
719+
'still not readable on the registry after three verification windows',
720+
);
721+
});
722+
723+
it('lets nothing act on a stable release before the final verification decides the run', () => {
724+
// Every job that depends on the publish job is the next verification
725+
// window, so no release step can start on the publish job's pass alone.
726+
const dependents = name =>
727+
Object.entries(workflow.jobs)
728+
.filter(([, job]) => [job.needs].flat().includes(name))
729+
.map(([jobName]) => jobName);
730+
expect(dependents('publish')).toEqual(['verify-registry-1']);
731+
expect(dependents('verify-registry-1')).toEqual(['verify-registry-2']);
732+
expect(dependents('verify-registry-2')).toEqual([]);
733+
734+
// Pending in the publish job and in follow-up 1, still unreadable in
735+
// follow-up 2: the run ends failed, so anything that waits for the run's
736+
// conclusion does not proceed.
737+
const publish = runStablePublish({verifyExit: 2});
738+
const first = runFollowUp(workflow.jobs['verify-registry-1'], 2);
739+
const last = runFollowUp(workflow.jobs['verify-registry-2'], 2);
740+
const jobResults = [publish.status, first.status, last.status];
741+
expect(jobResults).toEqual([0, 0, 2]);
742+
expect(jobResults.some(status => status !== 0)).toBe(true);
743+
expect(stable.outputs.verified).toBeDefined();
744+
expect(publish.output).toContain('verified=pending');
745+
expect(first.output).toContain('verified=pending');
746+
});
612747
});

‎.github/workflows/release.yml‎

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
# release branch and head. Stable publication from main is rejected.
2525
# Version-gated and idempotent: any version already on the registry is
2626
# skipped, so re-running (or a `dry-run` first) is safe.
27+
# Registry verification runs in bounded windows: the publish job's own,
28+
# then at most two follow-up verification jobs while packages are not yet
29+
# readable. Anything that acts on a stable release (the GitHub
30+
# Release, deployment, merge-back, release receipts, release tracking)
31+
# waits for this workflow run's conclusion, never the publish job's: while
32+
# packages are still propagating, the publish job passes and a follow-up
33+
# job decides the run.
2734
# - canary: push to main only. Main normally declares the next planned version,
2835
# so this publishes <declared>-canary.<short-sha> to the `canary` dist-tag.
2936
# The trusted release merge-back briefly leaves main equal to the stable tag;
@@ -94,6 +101,8 @@ jobs:
94101
actions: read
95102
contents: read
96103
id-token: write # npm OIDC trusted publishing + provenance
104+
outputs:
105+
verified: ${{ steps.publish.outputs.verified }}
97106
steps:
98107
- name: Checkout immutable release tag
99108
uses: actions/checkout@v7
@@ -174,6 +183,7 @@ jobs:
174183
run: pnpm build
175184

176185
- name: Publish changed packages
186+
id: publish
177187
env:
178188
DRY_RUN: ${{ inputs.dry-run }}
179189
RELEASE_VERSION: ${{ inputs['release-version'] }}
@@ -233,12 +243,96 @@ jobs:
233243
if [ "$DRY_RUN" = "true" ]; then
234244
echo "Dry run complete; no packages were published."
235245
else
246+
# One bounded verification window. Packages that are still not
247+
# readable when it ends (exit 2) do not fail the release: the
248+
# follow-up verification jobs below continue with windows of
249+
# their own.
250+
STATUS=0
236251
node scripts/npm/verify-published.mjs \
237252
--version "$RELEASE_VERSION" \
238-
--tag latest
239-
echo "Published $published package(s); registry verification passed."
253+
--tag latest || STATUS=$?
254+
case "$STATUS" in
255+
0)
256+
echo "verified=true" >> "$GITHUB_OUTPUT"
257+
echo "Published $published package(s); registry verification passed."
258+
;;
259+
2)
260+
echo "verified=pending" >> "$GITHUB_OUTPUT"
261+
echo "::notice::Published $published package(s); some are not yet readable on the registry. A follow-up verification job continues."
262+
;;
263+
*)
264+
exit "$STATUS"
265+
;;
266+
esac
240267
fi
241268
269+
# Follow-up registry verification: each job is one more bounded window for
270+
# packages that were published but not yet readable, with the same exact-
271+
# version proofs. The last one fails the release if a package is still not
272+
# readable.
273+
# A follow-up starts no check after 7 minutes, which leaves room in its
274+
# 10-minute limit for checkout, Node setup and a last slow check.
275+
verify-registry-1:
276+
name: Verify registry (follow-up 1)
277+
needs: publish
278+
if: needs.publish.outputs.verified == 'pending'
279+
runs-on: ubuntu-latest
280+
timeout-minutes: 10
281+
permissions:
282+
contents: read
283+
outputs:
284+
verified: ${{ steps.verify.outputs.verified }}
285+
steps:
286+
- name: Checkout immutable release tag
287+
uses: actions/checkout@v7
288+
- name: Setup Node
289+
uses: ./.github/actions/setup
290+
with:
291+
install: 'false'
292+
- name: Verify published packages
293+
id: verify
294+
env:
295+
RELEASE_VERSION: ${{ inputs['release-version'] }}
296+
run: |
297+
set -eu
298+
STATUS=0
299+
node scripts/npm/verify-published.mjs --version "$RELEASE_VERSION" --tag latest --window-ms 420000 || STATUS=$?
300+
case "$STATUS" in
301+
0) echo "verified=true" >> "$GITHUB_OUTPUT" ;;
302+
2)
303+
echo "verified=pending" >> "$GITHUB_OUTPUT"
304+
echo "::notice::Some packages are still not readable on the registry. The last follow-up verification job continues."
305+
;;
306+
*) exit "$STATUS" ;;
307+
esac
308+
309+
verify-registry-2:
310+
name: Verify registry (follow-up 2, last)
311+
needs: verify-registry-1
312+
if: needs.verify-registry-1.outputs.verified == 'pending'
313+
runs-on: ubuntu-latest
314+
timeout-minutes: 10
315+
permissions:
316+
contents: read
317+
steps:
318+
- name: Checkout immutable release tag
319+
uses: actions/checkout@v7
320+
- name: Setup Node
321+
uses: ./.github/actions/setup
322+
with:
323+
install: 'false'
324+
- name: Verify published packages
325+
env:
326+
RELEASE_VERSION: ${{ inputs['release-version'] }}
327+
run: |
328+
set -eu
329+
STATUS=0
330+
node scripts/npm/verify-published.mjs --version "$RELEASE_VERSION" --tag latest --window-ms 420000 || STATUS=$?
331+
if [ "$STATUS" -eq 2 ]; then
332+
echo "::error::Published packages are still not readable on the registry after three verification windows."
333+
fi
334+
exit "$STATUS"
335+
242336
# Canary publish — runs on every push to main. The @canary dist-tag always
243337
# points to the latest main commit:
244338
# npm install @astryxdesign/core@canary

0 commit comments

Comments
 (0)