DevOps4 min read

Create the GitHub Release Before npm publish

Run the GitHub release before npm publish in the release job, since a published npm version cannot be reused. Why the old order left no clean retry.

tl;dr A release job that publishes to npm before it creates the GitHub release can leave a live package with no source release, and npm will not let that version number be used again. Create and read back the GitHub release first, then publish, so a release failure stops the job with nothing in the registry. Contract tests pin the order.

A release job that publishes to npm and then creates a GitHub release can fail in a way npm cannot recover from. If the release step fails after the publish, a version is live on npm with no source release (the GitHub release tied to the tagged code) behind it, and a re-run cannot publish that version number again, because npm never lets a version be reused.

By the end of this post you will know which release steps to move ahead of the publish and how to pin that order with a test.

The risk in the old order

The publish job ran build, publish to npm, extract the version from the tag, record the publication, create the GitHub release, and report success. The package went out first. The release came last, just before the success report.

A GitHub release can be deleted. An npm version cannot be reused once published. So the step that can be undone was running after the step that cannot.

The pull request that changed this describes the failure as a risk of the order, not as an incident. Nothing in its record shows a release that actually failed this way. The problem was found by reading the step order, not by a failed run.

The reorder

The new order is build, extract the version from the tag, create the GitHub release, publish to npm, record the publication, and report success. No step was added or removed. The release step gained one line: a read-back that runs after the create.

Here is the release step’s logic after the change, with the title, pre-release flag and release notes elided:

set -euo pipefail
if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
  echo "Release $GITHUB_REF_NAME already exists; leaving it as is."
  exit 0
fi
gh release create "$GITHUB_REF_NAME" --verify-tag ...
gh release view "$GITHUB_REF_NAME" >/dev/null

Two checks do the work. The existence check makes a re-run safe: if the release already exists, the step exits 0 and the job goes on to publish. The final read-back makes the step fail when a create reports success but leaves no readable release behind.

The pull request also weighed draft-then-promote, where a draft release is created before the publish and promoted after it. It chose release-first instead, for two reasons in its record. The plugin publisher in the same repository already works this way. And release-first leaves no API call after the publish that can fail behind it.

What the tests and stub runs show

Three new tests read the workflow file. The first asserts that the release step comes before the publish step and that no other step runs npm publish. The second asserts that the release step ends with the read-back. The third fails if an if: or continue-on-error: sits between the release and the publish.

Against the workflow on main, the contract suite gave 2 failed and 6 passed. Against the branch, all 8 passed.

The release step also ran against a stub gh command, with four outcomes:

  • Release lands: exit 0.
  • Create fails: exit 1.
  • Create reports success but the release cannot be read: exit 1.
  • Release already exists: exit 0.

These runs exercise the script, not GitHub. They show the branches behave as written.

What is still unproven

No real fault-injection publish has been run. The pull request lists this as unfinished. Proving the whole path needs an owner-approved run against the npm-production environment, and that run has not happened.

The trade is visible. If the npm publish now fails, a GitHub release exists with no package behind it. The re-run takes the already-exists path and publishes. You accept a release without a package in exchange for never having a package without a release.

The change is in PR #1914, merged 2026-12-05.

Use this

  • Before the first registry write in any release job, move every step whose failure should stop the publish ahead of it. Create the GitHub release there.
  • Read the release back with a command that fails when the release is missing, and make the step fail on that read-back.
  • Write a test that reads the workflow file for step order, then run it against the old workflow too. It should fail on the old order.