Unverified Commit 04b13f52 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update error handling in publish scripts (#62754)

Seems we aren't ignoring the already published error correctly.

x-ref:
https://github.com/vercel/next.js/actions/runs/8118349923/job/22192598805

Closes NEXT-2668
parent be871323
...@@ -24,6 +24,7 @@ const cwd = process.cwd() ...@@ -24,6 +24,7 @@ const cwd = process.cwd()
await Promise.all( await Promise.all(
platforms.map(async (platform) => { platforms.map(async (platform) => {
await publishSema.acquire() await publishSema.acquire()
let output = ''
try { try {
let binaryName = `next-swc.${platform}.node` let binaryName = `next-swc.${platform}.node`
...@@ -41,7 +42,7 @@ const cwd = process.cwd() ...@@ -41,7 +42,7 @@ const cwd = process.cwd()
path.join(nativePackagesDir, platform, 'package.json'), path.join(nativePackagesDir, platform, 'package.json'),
JSON.stringify(pkg, null, 2) JSON.stringify(pkg, null, 2)
) )
await execa( const child = execa(
`npm`, `npm`,
[ [
`publish`, `publish`,
...@@ -52,14 +53,20 @@ const cwd = process.cwd() ...@@ -52,14 +53,20 @@ const cwd = process.cwd()
], ],
{ stdio: 'inherit' } { stdio: 'inherit' }
) )
const handleData = (type) => (chunk) => {
process[type].write(chunk)
output += chunk.toString()
}
child.stdout?.on('data', handleData('stdout'))
child.stderr?.on('data', handleData('stderr'))
await child
} catch (err) { } catch (err) {
// don't block publishing other versions on single platform error // don't block publishing other versions on single platform error
console.error(`Failed to publish`, platform, err) console.error(`Failed to publish`, platform, err)
if ( if (
err.message && output.includes(
err.message.includes( 'cannot publish over the previously published versions'
'You cannot publish over the previously published versions'
) )
) { ) {
console.error('Ignoring already published error', platform, err) console.error('Ignoring already published error', platform, err)
......
...@@ -42,9 +42,10 @@ const cwd = process.cwd() ...@@ -42,9 +42,10 @@ const cwd = process.cwd()
const publishSema = new Sema(2) const publishSema = new Sema(2)
const publish = async (pkg, retry = 0) => { const publish = async (pkg, retry = 0) => {
let output = ''
try { try {
await publishSema.acquire() await publishSema.acquire()
await execa( const child = execa(
`npm`, `npm`,
[ [
'publish', 'publish',
...@@ -54,18 +55,21 @@ const cwd = process.cwd() ...@@ -54,18 +55,21 @@ const cwd = process.cwd()
'--ignore-scripts', '--ignore-scripts',
...(isCanary ? ['--tag', 'canary'] : []), ...(isCanary ? ['--tag', 'canary'] : []),
], ],
{ stdio: 'inherit' } { stdio: 'pipe' }
) )
const handleData = (type) => (chunk) => {
process[type].write(chunk)
output += chunk.toString()
}
child.stdout?.on('data', handleData('stdout'))
child.stderr?.on('data', handleData('stderr'))
// Return here to avoid retry logic // Return here to avoid retry logic
return return await child
} catch (err) { } catch (err) {
console.error(`Failed to publish ${pkg}`, err) console.error(`Failed to publish ${pkg}`, err)
if ( if (
err.message && output.includes('cannot publish over the previously published versions')
err.message.includes(
'You cannot publish over the previously published versions'
)
) { ) {
console.error('Ignoring already published error', pkg) console.error('Ignoring already published error', pkg)
return return
......
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