From ad6870c035f5ae4216599a9425d59a574dceb8b8 Mon Sep 17 00:00:00 2001 From: Jack Williams Date: Tue, 22 Oct 2024 13:40:43 +0100 Subject: [PATCH] Handle duplicate publishing needlessly failing (#726) ## Summary Fixes the release process failing if a package is already published on npm; this should just continue as normal, as these may be released by humans or other actions. ## Checklist - [ ] ~Added a [docs PR](https://github.com/inngest/website) that references this PR~ N/A CI fix - [ ] ~Added unit/integration tests~ N/A CI fix - [x] Added changesets if applicable ## Related - Clean-up following borked release in #725 - should ensure this doesn't happen again --- scripts/release/publish.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/scripts/release/publish.js b/scripts/release/publish.js index 27945f568..b0bc324f7 100644 --- a/scripts/release/publish.js +++ b/scripts/release/publish.js @@ -89,14 +89,40 @@ const exec = async (...args) => { }); console.log("publishing", tag, "to dist tag:", distTag); - await exec( + const { + exitCode: publishExitCode, + stdout: publishStdout, + stderr: publishStderr, + } = await getExecOutput( "npm", ["publish", "--tag", distTag, "--access", "public", "--provenance"], { cwd: distDir, + ignoreReturnCode: true, } ); + if (publishExitCode !== 0) { + // It could be a non-zero code if the package was already published by + // another action or human. If this is the case, we should not fail the + // action. + const duplicatePublishMsg = + "cannot publish over the previously published versions"; + + if ( + publishStdout.includes(duplicatePublishMsg) || + publishStderr.includes(duplicatePublishMsg) + ) { + console.log("npm publish failed but it's okay; it's already published"); + + return; + } + + throw new Error(`npm publish exited with ${publishExitCode}`); + } + + console.log("Publish successful"); + // If this was a backport release, republish the "latest" tag at the actual latest version if (branch !== "main" && distTag === "latest") { console.log(