fix(release): fail the publish job instead of swallowing npm errors
Summary
scripts/publish.ts swallowed every npm publish error as "may already exist" and always ran changeset tag. Two consequences:
- An auth or registry failure releases nothing and the job stays green.
- Every push to
mainthat is not a release goes red. The Publish runs for #2906 and #2907 (2026-09-02) both failed at 📦 Create Aggregated GitHub Release withHTTP 422: Validation Failed.
for each public package
- rewrite workspace: deps
- try npm publish
- catch → log "may already exist", continue
-try changeset tag (catch → log)
+ npm view name@version
+ exact match → skip
+ E404 → rewrite workspace: deps, npm publish (any failure → exit 1)
+ other error → exit 1
+if nothing was published → no tags, done
+changeset tag (failure → exit 1)
Why the 422: with nothing to publish, changeset tag still prints New tag: for all 22 packages. changesets/action v1 reads those lines as a release and sets published=true, so the workflow runs gh release create v11.0.0 for a release that already exists.
The entry point is now behind import.meta.main, so isPublished can be imported by a test without running a publish.
Evidence
-
Before (run for #2907): 22×
npm error You cannot publish over the previously published versions: 11.0.0.→Failed to publish … (may already exist), then 22×New tag:, thenHTTP 422: Validation Failed. -
After: run locally against the real registry, with a fake
npmthat refusespublish.- Nothing to release: 22×
Already on npm: @node-minify/…@11.0.0, thenNothing to publish, no tags created., exit 0, no new tags. - A version not on npm (
benchmark@99.0.0-shimtest):Publishing …, thenPublish failed: Command failed: npm publish …, exit 1,package.jsonrestored, no tags.
- Nothing to release: 22×
-
scripts/__tests__/publish.test.ts(newscriptsvitest project):isPublished is true when npm view returns the exact version ("11.0.0" and ["11.0.0"]) is false when npm view answers E404 is false when npm view succeeds without the version throws on any other npm view failure (E403, network error)Full suite: 71 files, 1051 tests pass. Biome,
lint:rootand the type-suppression guard are clean. -
Registry check: all 22 public packages on
mainare on npm at 11.0.0, so no past run silently skipped a package.
Merge Danger
Door: two-way. It only changes the release script and adds a test project; revert restores the old behaviour.
Blast Radius: release job.
- It only runs on the next push to
main. If nothing is pending, that run should now be green and create no release. - A real publish failure now fails the job where it used to pass. That is the intent.
- If
changeset tagfails after a successful publish, a re-run finds everything published and skips tagging. Runchangeset tagby hand in that case.
Summary by cubic
Fixes the release script so npm publish errors fail the publish job instead of being logged as "may already exist", which previously let an auth or registry failure release nothing while the job stayed green.
scripts/publish.tschecks each package withnpm view <name>@<version>first: an exact match is skipped, E404 proceeds to publish, and any other lookup or publish failure exits 1.- Registry lookups time out after 2 minutes so an unresponsive npm never hangs the job.
changeset tagruns only when at least one package was published, so a no-op push no longer triggers a failing GitHub Release step (the 422 fromgh release createon already-released versions).publishAlltakes the packages directory and a command runner, and the entry point is behindimport.meta.main, so the newscriptsvitest project tests the loop without a registry. Tests cover the already-published, mixed, and failed-publish paths and restore each rewrittenpackage.json.