Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions scripts/publish-release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test('publishing validates all packages and publishers before publishing in depe
result.calls.filter((line) => line.startsWith('npm:')),
releasePackages.map(
(name) =>
`npm:${name}:publish --access public --provenance --tag latest --workspaces=false --ignore-scripts`,
`npm:${name}:stage publish --access public --provenance --tag latest --workspaces=false --ignore-scripts`,
),
)
})
Expand Down Expand Up @@ -83,14 +83,14 @@ test('a prerelease of packages without a stable release publishes to latest and
for (const name of reactNativePackages)
assert.ok(
npm.includes(
`npm:${name}:publish --access public --provenance --tag alpha --workspaces=false --ignore-scripts`,
`npm:${name}:stage publish --access public --provenance --tag alpha --workspaces=false --ignore-scripts`,
),
name,
)
for (const name of nitroUIPackages)
assert.ok(
npm.includes(
`npm:${name}:publish --access public --provenance --tag latest --workspaces=false --ignore-scripts`,
`npm:${name}:stage publish --access public --provenance --tag latest --workspaces=false --ignore-scripts`,
),
name,
)
Expand All @@ -108,16 +108,10 @@ test('a prerelease of packages without a stable release publishes to latest and
)
})

test('an npm without trusted dist-tag support prevents publishing a prerelease to latest', () => {
const result = runPublication(
{
PUBLISH_TEST_PRERELEASE_LATEST: '11.0.0-alpha.0',
PUBLISH_TEST_NPM_VERSION: '11.19.1',
},
'11.0.0-alpha.1',
)
test('an npm without staged publishing and trusted dist-tag support prevents every upload', () => {
const result = runPublication({ PUBLISH_TEST_NPM_VERSION: '11.19.1' })
assert.notEqual(result.status, 0)
assert.match(result.stderr, /npm 11\.19\.1 cannot move dist-tags/)
assert.match(result.stderr, /npm 11\.19\.1 cannot stage packages/)
assert.equal(
result.calls.some((line) => line.startsWith('npm:')),
false,
Expand Down Expand Up @@ -254,7 +248,10 @@ test('a package without repository metadata prevents publishing any package', ()
test('other npm publish failures stop before the next package', () => {
const result = runPublication({ PUBLISH_TEST_CORE_FAILS: '1' })
assert.notEqual(result.status, 0)
assert.match(result.stderr, /react-native-nitro-sqlite: npm publish failed/)
assert.match(
result.stderr,
/react-native-nitro-sqlite: npm stage publish failed/,
)
assert.equal(result.calls.filter((line) => line.startsWith('npm:')).length, 1)
})

Expand Down
18 changes: 13 additions & 5 deletions scripts/publish-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ export async function publishRelease(version: string): Promise<void> {
const npmVersion = execFileSync('npm', ['--version'], {
encoding: 'utf8',
}).trim()
if (prereleaseOnly.size && compareVersions(npmVersion, '11.21.0') < 0)
if (compareVersions(npmVersion, '11.21.0') < 0)
throw new Error(
`npm ${npmVersion} cannot move dist-tags with trusted publishing. Use npm 11.21.0 or newer.`,
`npm ${npmVersion} cannot stage packages and move dist-tags with trusted publishing. Use npm 11.21.0 or newer.`,
)
for (const name of pending) {
// npm's CLI exchanges GitHub OIDC credentials and records provenance without a publishing token.
// A staged version stays private until a maintainer approves it with 2FA on npmjs.com.
const result = spawnSync(
'npm',
[
'stage',
'publish',
'--access',
'public',
Expand All @@ -82,12 +84,18 @@ export async function publishRelease(version: string): Promise<void> {
)
const stderr = result.stderr ?? ''
process.stderr.write(stderr)
// npm hides a new version for several minutes and rejects a second publish of it until then.
// npm rejects staging a version again until a maintainer approves or rejects the earlier one.
const stagedByEarlierAttempt = /previously staged version/.test(stderr)
if (result.status !== 0 && !stagedByEarlierAttempt)
throw new Error(`${name}: npm publish failed.`, { cause: result.error })
throw new Error(`${name}: npm stage publish failed.`, {
cause: result.error,
})
}
// Verify after publishing every package, so npm's processing delays overlap.
if (pending.length)
console.log(
`Approve the staged ${version} packages in npmjs.com's Staged Packages tab.`,
)
// Verify after staging every package, so one approval covers them all.
for (const name of pending) await verifyPublication(name, version, commit)
// Retries tag already published versions too. Each package's trusted publisher needs "Allow npm dist-tag".
for (const name of prereleaseOnly) {
Expand Down
6 changes: 3 additions & 3 deletions scripts/release-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function checkTrustedPublishers(
}
}

/** Confirm the published version records the selected commit, allowing registry propagation.
/** Confirm the published version records the selected commit, allowing approval and registry propagation.
* Registry and connection errors while waiting are retried until the deadline.
* @throws After 20 minutes if the version is missing or unreadable, or at once if its commit differs.
*/
Expand All @@ -148,7 +148,7 @@ export async function verifyPublication(
commit: string,
pollMs = 5_000,
): Promise<void> {
// npm hides a new version while it processes it. 10.3.0 took over a minute and 11.0.0-nitro-v1.0 about four.
// A staged version appears after a maintainer approves it, and npm can take several minutes to process it.
const deadline = Date.now() + 20 * 60_000
let lastError: unknown
while (Date.now() < deadline) {
Expand All @@ -164,7 +164,7 @@ export async function verifyPublication(
await new Promise((resolve) => setTimeout(resolve, pollMs))
}
throw new Error(
`${name}: published version could not be verified. Resume with release_tag.`,
`${name}: published version could not be verified. Approve its staged version on npmjs.com, then resume with release_tag.`,
{ cause: lastError },
)
}
Expand Down
Loading