Skip to content

Commit

Permalink
Fix 404 error if releasing a new package (#763)
Browse files Browse the repository at this point in the history
## Summary
<!-- Succinctly describe your change, providing context, what you've
changed, and why. -->

A small fix to handle brand new packages in the release script; we
search for `dist-tags` to ensure we can backport from `v*.x` branches,
but dist tags won't exist for new packages!

## Checklist
<!-- Tick these items off as you progress. -->
<!-- If an item isn't applicable, ideally please strikeout the item by
wrapping it in "~~"" and suffix it with "N/A My reason for skipping
this." -->
<!-- e.g. "- [ ] ~~Added tests~~ N/A Only touches docs" -->

- [ ] ~Added a [docs PR](https://github.com/inngest/website) that
references this PR~ N/A KTLO
- [ ] ~Added unit/integration tests~ N/A KTLO
- [ ] ~Added changesets if applicable~ N/A KTLO
  • Loading branch information
jpwilliams authored Nov 27, 2024
1 parent 581ce9a commit 854f451
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions scripts/release/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,51 @@ const exec = async (...args) => {
}

// Get current latest version
let latestVersion;

const {
exitCode: latestCode,
stdout: latestStdout,
stderr: latestStderr,
} = await getExecOutput("npm", ["dist-tag", "ls"]);

if (latestCode !== 0) {
throw new Error(
`npm dist-tag ls exited with ${latestCode}:\n${latestStderr}`
);
}
// It could be a non-zero code if the package was never published before
const notFoundMsg = "is not in this registry";

const latestVersion = latestStdout
.split("\n")
.find((line) => line.startsWith("latest: "))
?.split(" ")[1];

if (!latestVersion) {
throw new Error(`Could not find "latest" dist-tag in:\n${latestStdout}`);
if (
latestStdout.includes(notFoundMsg) ||
latestStderr.includes(notFoundMsg)
) {
console.log(
"npm dist-tag ls failed but it's okay; package hasn't been published yet"
);
} else {
throw new Error(
`npm dist-tag ls exited with ${latestCode}:\n${latestStderr}`
);
}
} else {
latestVersion = latestStdout
?.split("\n")
?.find((line) => line.startsWith("latest: "))
?.split(" ")[1];

if (!latestVersion) {
throw new Error(`Could not find "latest" dist-tag in:\n${latestStdout}`);
}
}

console.log("latestVersion:", latestVersion);

// If this is going to be backport release, don't allow us to continue if we
// have no latest version to reset to
if (branch !== "main" && !latestVersion) {
throw new Error(
"Cannot continue with backport release; no latest version found"
);
}

// Release to npm
await exec("npm", ["config", "set", "git-tag-version", "false"], {
cwd: distDir,
Expand Down

0 comments on commit 854f451

Please sign in to comment.