Unverified Commit 2cbbd61b authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update publish script to skip lerna (#40815)

This updates our `publish-release` script to bypass lerna so that we can
retry publishing automatically when there is an npm error and tolerate
non-fatal publish errors like already existing published versions.
Currently this will only allow publishing a canary release to ensure it
is working as expected and in a follow-up we can enable the stable
publish handling.

Separately we can investigate moving canaries away from `npm` to reduce
the number of versions being created there.

x-ref: https://github.com/vercel/next.js/pull/40812
x-ref:
https://github.com/vercel/next.js/actions/runs/3108735543/jobs/5038717354#step:10:2332
x-ref:
https://github.com/vercel/next.js/actions/runs/3108335849/jobs/5038069555
parent 50b98d50
......@@ -1008,7 +1008,7 @@ jobs:
- run: npm i -g pnpm@${PNPM_VERSION}
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run: ./scripts/publish-native.js $GITHUB_REF
- run: ./scripts/publish-release.sh
- run: ./scripts/publish-release.js
testDeployE2E:
name: E2E (deploy)
......
#!/usr/bin/env node
// @ts-check
const path = require('path')
const { readdir } = require('fs/promises')
const { execSync } = require('child_process')
const cwd = process.cwd()
;(async function () {
let isCanary = false
if (!process.env.NPM_TOKEN) {
console.log('No NPM_TOKEN, exiting...')
return
}
try {
const tagOutput = execSync('git describe --exact-match').toString()
console.log(tagOutput)
isCanary = tagOutput.includes('-canary')
} catch (err) {
console.log(err)
if (err.message && err.message.includes('no tag exactly matches')) {
console.log('Nothing to publish, exiting...')
return
}
throw err
}
console.log(`Publishing ${isCanary ? 'canary' : 'stable'}`)
// TODO: remove after testing, this is a safe guard to ensure we
// don't publish stable unexpectedly
if (!isCanary) {
return
}
const packagesDir = path.join(cwd, 'packages')
const packageDirs = await readdir(packagesDir)
const publish = async (pkg, retry = 0) => {
try {
execSync(
`npm publish ${path.join(packagesDir, pkg)} --access public${
isCanary ? ' --tag canary' : ''
}`
)
} catch (err) {
console.error(`Failed to publish ${pkg}`, err)
if (
err.message &&
err.message.includes(
'You cannot publish over the previously published versions'
)
) {
console.error('Ignoring already published error', pkg)
return
}
if (retry < 3) {
const retryDelaySeconds = 15
console.log(`retrying in ${retryDelaySeconds}s`)
await new Promise((resolve) =>
setTimeout(resolve, retryDelaySeconds * 1000)
)
await publish(pkg, retry + 1)
}
throw err
}
}
for (const packageDir of packageDirs) {
await publish(packageDir)
}
})()
#!/bin/bash
git describe --exact-match
if [[ ! $? -eq 0 ]];then
echo "Nothing to publish, exiting.."
exit 0;
fi
if [[ -z "$NPM_TOKEN" ]];then
echo "No NPM_TOKEN, exiting.."
exit 0;
fi
if [[ $(git describe --exact-match 2> /dev/null || :) =~ -canary ]];
then
echo "Publishing canary"
yarn run lerna publish from-git --npm-tag canary --no-git-reset --no-verify-access --yes
# Make sure to exit script with code 1 if publish failed
if [[ ! $? -eq 0 ]];then
exit 1;
fi
else
echo "Did not publish canary"
fi
if [[ ! $(git describe --exact-match 2> /dev/null || :) =~ -canary ]];then
echo "Publishing stable"
yarn run lerna publish from-git --no-git-reset --no-verify-access --yes
# Make sure to exit script with code 1 if publish failed
if [[ ! $? -eq 0 ]];then
exit 1;
fi
else
echo "Did not publish stable"
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment