fix(release): fail the publish job instead of swallowing npm errors

Merged
SR
1mo ago
+311-54

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 main that is not a release goes red. The Publish runs for #2906 and #2907 (2026-09-02) both failed at 📦 Create Aggregated GitHub Release with HTTP 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:, then HTTP 422: Validation Failed.

  • After: run locally against the real registry, with a fake npm that refuses publish.

    • Nothing to release: 22× Already on npm: @node-minify/…@11.0.0, then Nothing to publish, no tags created., exit 0, no new tags.
    • A version not on npm (benchmark@99.0.0-shimtest): Publishing …, then Publish failed: Command failed: npm publish …, exit 1, package.json restored, no tags.
  • scripts/__tests__/publish.test.ts (new scripts vitest 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:root and the type-suppression guard are clean.

  • Registry check: all 22 public packages on main are 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 tag fails after a successful publish, a re-run finds everything published and skips tagging. Run changeset tag by 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.ts checks each package with npm 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 tag runs only when at least one package was published, so a no-op push no longer triggers a failing GitHub Release step (the 422 from gh release create on already-released versions).
  • publishAll takes the packages directory and a command runner, and the entry point is behind import.meta.main, so the new scripts vitest project tests the loop without a registry. Tests cover the already-published, mixed, and failed-publish paths and restore each rewritten package.json.