fix: dynamically increment prerelease versions in publish.sh#1932
fix: dynamically increment prerelease versions in publish.sh#1932inlined wants to merge 2 commits into
Conversation
3b5481e to
e1aa47a
Compare
There was a problem hiding this comment.
Code Review
This pull request updates the prerelease versioning logic in scripts/publish.sh to check npm for existing prerelease versions in the target range and increment them if found, rather than always starting from the stable version. The reviewer noted that parsing the raw output of npm view with tail and grep is fragile and prone to errors due to output formatting variations, sorting assumptions, and a hardcoded regex. They suggested a more robust approach using Node.js and the semver package to parse the JSON output safely.
747ba4c to
8ebf2f0
Compare
8ebf2f0 to
2a51ea7
Compare
| STABLE_VERSION=$(npm view "$PACKAGE_NAME" version) | ||
|
|
||
| # Find the absolute latest version overall on npm (including prereleases) | ||
| LATEST_VERSION=$(npm view "$PACKAGE_NAME" versions --json | grep -oE '[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?' | tail -n 1) |
There was a problem hiding this comment.
I was doing some diving to fully understand this. It totally works and I'm fine merging it. Gemini thinks if we're already using jq it'd be slightly more robust to use it:
LATEST_VERSION=$(npm view "$PACKAGE_NAME" versions --json | jq -r '[.[] | select(test("^[0-9]+\\.[0-9]+\\.[0-9]+(-rc\\.[0-9]+)?$"))] | .[-1]')
It does all the stripping so you just reduce to testing the version numbers to be fair... but I kinda doubt npm view versions --json is going to change much.
|
|
||
| # 3. Stateless Version Discovery | ||
| PACKAGE_NAME=$(node -p "require('./package.json').name") | ||
| PACKAGE_NAME=$(jq -r '.name' package.json) |
There was a problem hiding this comment.
Why is it safe to assuming jq will be installed? It wasn't on my cloudtop for example (though I've now installed it).
Description
Fixes an issue in
scripts/publish.shwhere prerelease publishing (e.g. running with--prerelease) would fail ifrc.0was already published on npm for that target version series, since it always bumped from the stable version. It now dynamically checks npm for any existing prerelease versions of the target version series, and performs aprereleaseincrement (e.g., torc.1) if one exists.Newly assumes the jq command exists to avoid silly node scripts (will need to test in prod or build a new container). Now handles gh not existing since it didn't in the past.
Release Notes
relnote: chore: improve release script