Skip to content

Commit f3d9c43

Browse files
committed
fix(ci): guard release workflow against publishing stale versions as latest
A replayed old tag once caused npm's latest dist-tag to jump backward across 15 packages when changesets published an already-versioned commit with zero semver-order awareness. Block any future publish whose local version isn't strictly greater than the currently published latest.
1 parent 851293b commit f3d9c43

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ jobs:
4141
- name: Build packages
4242
run: pnpm --filter './packages/**' build
4343

44+
- name: Guard against publishing an older version as latest
45+
run: |
46+
set -euo pipefail
47+
for dir in packages/*/; do
48+
pkg_json="${dir}package.json"
49+
[ -f "$pkg_json" ] || continue
50+
is_private=$(node -p "require('./$pkg_json').private === true")
51+
[ "$is_private" = "true" ] && continue
52+
name=$(node -p "require('./$pkg_json').name")
53+
local_version=$(node -p "require('./$pkg_json').version")
54+
published_latest=$(npm view "$name" dist-tags.latest 2>/dev/null || echo "")
55+
if [ -n "$published_latest" ]; then
56+
if ! npx --yes semver "$local_version" -r ">$published_latest" >/dev/null 2>&1; then
57+
echo "::error::$name: local version $local_version is not greater than published latest ($published_latest). Refusing to publish — this would move npm's 'latest' tag backwards."
58+
exit 1
59+
fi
60+
fi
61+
done
62+
4463
- name: Create release PR or publish to npm
4564
id: changesets
4665
uses: changesets/action@v1

0 commit comments

Comments
 (0)