Skip to content

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

Merged
srod merged 4 commits into
developfrom
fix/strict-npm-publish
Oct 9, 2026
Merged

srod merged 4 commits into
developfrom
fix/strict-npm-publish

Conversation

@srod

@srod srod commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Summary

scripts/publish.ts swallowed every npm publish error as "may already exist" and always ran changeset tag. Two consequences:

 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 chore: run the action on node24, refresh v12 backlog #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.

Written for commit a12c4fd. Summary will update on new commits.

View guided diff Turn on auto-fix

scripts/publish.ts caught every `npm publish` failure as "may already exist"
and still exited 0, so an auth or registry failure would release nothing and
stay green. It also ran `changeset tag` unconditionally: on every push to
main without a release, CI tried to republish all 22 packages, `changeset
tag` printed "New tag:" for each, changesets/action read that as a release,
and `gh release create v11.0.0` failed with HTTP 422 (publish runs of
2026-09-02 for #2906 and #2907).

Now each package is checked with `npm view name@version` first: an exact
match is skipped, E404 is published, any other lookup error or publish
failure stops the run with exit 1. Tags are only created when something was
published. The entry point is guarded by `import.meta.main` so the script
can be imported by its test without publishing.
@changeset-bot

changeset-bot Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a12c4fd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread scripts/publish.ts Resolved
Comment thread scripts/publish.ts Resolved
srod added 2 commits October 9, 2026 13:46
publishAll takes the packages directory and the command runner, so the
tests can check without a registry: no tags when everything is already on
npm, only missing packages published with workspace deps resolved, and a
failed publish stopping the run with its package.json restored.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread scripts/__tests__/publish.test.ts Resolved
@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.43750% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.63%. Comparing base (078af29) to head (a12c4fd).

Files with missing lines Patch % Lines
scripts/publish.ts 73.43% 17 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2925      +/-   ##
===========================================
- Coverage    99.64%   98.63%   -1.01%     
===========================================
  Files           69       70       +1     
  Lines         1961     2056      +95     
  Branches       599      624      +25     
===========================================
+ Hits          1954     2028      +74     
- Misses           7       28      +21     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@srod
srod merged commit a7c2690 into develop Oct 9, 2026
6 checks passed
@srod
srod deleted the fix/strict-npm-publish branch October 9, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant