Skip to content

Commit

Permalink
Update publish script to skip lerna (#40815)
Browse files Browse the repository at this point in the history
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: #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
  • Loading branch information
ijjk committed Sep 22, 2022
1 parent 50b98d5 commit 2cbbd61
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_test_deploy.yml
Expand Up @@ -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)
Expand Down
77 changes: 77 additions & 0 deletions scripts/publish-release.js
@@ -0,0 +1,77 @@
#!/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)
}
})()
38 changes: 0 additions & 38 deletions scripts/publish-release.sh

This file was deleted.

0 comments on commit 2cbbd61

Please sign in to comment.