From 6c93ee725ea5484c52e9e4558c6be2b89c1ce3af Mon Sep 17 00:00:00 2001 From: mikkel Date: Thu, 19 Nov 2026 21:21:14 +0000 Subject: [PATCH] [CF-Pages-Skip] Verify Patchling npm archives --- .github/workflows/ci.yml | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bff5cff..187c940 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -128,20 +128,30 @@ jobs: run: | node --input-type=module <<'JS' import { execFileSync } from 'node:child_process'; + import { createHash } from 'node:crypto'; + import { readFileSync } from 'node:fs'; + import { setTimeout as delay } from 'node:timers/promises'; const version = process.env.VERSION; - const record = await fetch(`https://registry.npmjs.org/patchling/${encodeURIComponent(version)}`, { + const archive = `./patchling-${version}.tgz`; + const integrity = `sha512-${createHash('sha512').update(readFileSync(archive)).digest('base64')}`; + const url = `https://registry.npmjs.org/patchling/${encodeURIComponent(version)}`; + const lookup = () => fetch(url, { signal: AbortSignal.timeout(15_000), redirect: 'error', }); - if (record.ok) { - const published = await record.json(); - if (published.name !== 'patchling' || published.version !== version) { - throw new Error('npm registry response does not identify the requested version'); - } - console.log(`patchling@${version} is already published`); - } else if (record.status === 404) { + let record = await lookup(); + if (record.status === 404) { const tag = version.includes('-') ? 'next' : 'latest'; - execFileSync('npm', ['publish', `./patchling-${version}.tgz`, '--ignore-scripts', '--access', 'public', '--tag', tag], { stdio: 'inherit' }); - } else { - throw new Error(`npm registry returned HTTP ${record.status}`); + execFileSync('npm', ['publish', archive, '--ignore-scripts', '--access', 'public', '--tag', tag], { stdio: 'inherit' }); + for (const waitMs of [0, 2_000, 2_000, 2_000]) { + await delay(waitMs); + record = await lookup(); + if (record.status !== 404) break; + } + } + if (!record.ok) throw new Error(`npm registry returned HTTP ${record.status}`); + const published = await record.json(); + if (published.name !== 'patchling' || published.version !== version || published.dist?.integrity !== integrity) { + throw new Error(`npm metadata for patchling@${version} does not match the tested archive`); } + console.log(`Verified the tested patchling@${version} archive on npm`); JS