A version reaches npm when a commit on main changes the version in package.json (release-please's release pull request is merged) and the owner approves the publishing job; the workflow then creates the tag v<major>.<minor>.<patch> and the GitHub release. The owner can also push the tag by hand (to retry, or to release a version whose run he rejected). The workflow is .github/workflows/release.yml. This page says how to release, how the very first version is set up, and how to check what was published.
The workflow runs on every push to main and on every pushed tag v*, in three jobs, so the identity that can publish never exists while dependencies install or run their scripts.
-
detecthas only read access.scripts/release-detect.mjsdecides whether the push releases anything, and prints one line saying why:- a push to
mainreleases only when it movesmainforward (a merge; never a forced push), changes theversioninpackage.jsonagainst the commit before the push, and the tagv<version>does not exist yet. A README fix merged later, while the version still waits for approval, releases nothing; - a pushed tag goes on to
check, except one pushed by the release app itself (brunosouzas-stackledger-release[bot], see The release app): the run that made it is already releasing it; - anything else stops here, in seconds, and the run is green. An unreadable
package.jsonor a Git failure fails the run.
- a push to
-
checkhas only read access to the repository. It runsscripts/check-release-tag.mjsfirst: the tag must bevplus theversioninpackage.json, digits only (no-beta), on a commit that is onorigin/main(frommain: the pushed commit, and if the tag already exists it must name that commit). Thennpm ci, the build, the full test suite andnpm audit(any vulnerability, or an audit that cannot run, stops the release). Thennode scripts/pack-production.mjs "$RUNNER_TEMP/release"packs a temporary copy of the built package files with a production-only shrinkwrap derived from the repository lock. It does not mutate the repository lock (which retains dev dependencies fornpm ci); the staged manifest omits dev dependencies andprepack, because the build already ran. The CycloneDX SBOM is generated withnpm sbom --package-lock-only --sbom-format cyclonedxfrom the manifest and production shrinkwrap extracted from that exact tarball (not from the development checkout). Two clean registry-stand-in installs test that no dev-only or untracked packages ship (npm 10 may classify locked optional WASM packages as extraneous). The exact staged tarball, its integrity and the SBOM go to the next job as an artifact. -
publishruns in the GitHub environmentnpm, which waits for the owner's approval. It installs nothing and builds nothing. It checks out the released commit only to runscripts/release-publish.shon the downloaded files. Frommain, the script first reserves the tag: it createsv<version>on the released commit through the GitHub API, which either creates it or answers that it exists. The owner may push the same tag by hand meanwhile; an existing tag must name the released commit, or the script stops and nothing is published. Then it asks npm whether the version exists:- absent: it publishes the tarball with
npm publish --provenance --access public --ignore-scripts; - present with the same integrity and a provenance attestation: it skips publishing;
- present with other bytes, or without provenance, or npm cannot answer: it stops with exit 1 and publishes nothing (a tag reserved before stays).
Then it creates the GitHub release on the tag (
--verify-tag) with the SBOM attached, or replaces the SBOM of an existing release. The script acts on GitHub as the release app, so the tag it creates starts the workflow again (unlike a tag made with the workflow's own token);detectstops that run at once. - absent: it publishes the tarball with
If a run fails part way (npm down after the tag was reserved, or the GitHub release after npm), use "Re-run failed jobs": GitHub keeps the successful detect and check with their outputs and artifact, and the script finds its own tag on the same commit and the same bytes on npm, and only finishes what is missing. Do not use "Re-run all jobs": detect then sees the tag and stops. If the failed run can no longer be re-run (its artifact expires after 7 days), delete the tag (git push origin :refs/tags/v0.2.0) and push it again: the tag path releases it.
For release candidates, run node scripts/pack-production.mjs <destination> after npm ci. Plain npm pack at the repository root still runs prepack and builds dist/, but includes the development shrinkwrap and must not be published. Only the staging packer supplies the production-only shrinkwrap. The release workflow uploads precisely its output, not a subsequent root pack.
Since AB#243 the version is never set by hand. Every pull request title is a Conventional Commit (the Title check), and the squash merge makes it the commit on main (its description becomes the commit body). On every push to main, the Release PR workflow (.github/workflows/release-please.yml: the reusable release-please workflow of brunosouzas/github-reusable-workflows, run as the release app in the environment release-please) keeps one release pull request open, chore(main): release <version>: it bumps version in package.json and npm-shrinkwrap.json and adds the section of CHANGELOG.md. feat raises the minor version, fix, perf and revert the patch; a breaking change (feat!:, or BREAKING CHANGE: in the body) raises the minor version while the package is below 1.0.0. docs, ci, chore, test, refactor, build and style release nothing. A line Release-As: x.y.z, as the last paragraph of a pull request's description (the squash merge's body), forces that version.
-
When the release pull request holds what you want to release, check the trusted publisher (below). Nobody edits the release pull request by hand: release-please rewrites it on every push. It also keeps the version in the README (the lines marked
x-release-please-version). Between the merge of a release pull request and its tag, release-please opens no new one; the next push tomainafter the tag marks it released and opens the next. -
Merge it. The run of that merge in the Actions tab goes through
detectandcheck, then thepublishjob waits for you: review it and approve. To not release it, reject the run; nothing is published and no tag is created.Before the first release after the trusted publisher was set up, check its status on npmjs.com (package → Settings → Trusted Publisher). npm marks a new configuration "Pending validation" until a publish uses it, and expires it 48 hours after creation (GitHub changelog). An expired configuration no longer authorises publishing, and with no token left the job fails. If it is pending or expired, delete it and add it again with the same values (step 5.1 below) just before merging the version (or pushing the tag): the release then validates it.
-
Check the result (see Checking a release).
By hand, or to retry. Tag the commit on main and push the tag:
git switch main && git pull --ff-only
git tag v0.2.0
git push origin v0.2.0A tag that does not match the version, or a tag on a commit that is not on main, fails in the first step of check. Delete the tag (git push origin :refs/tags/v0.2.0), fix, and tag again.
Three controls, so neither a merge nor a pushed tag alone publishes:
- The tag check. Only a commit on
main, so only merged and reviewed code, is released, and only when its version is the tag's. - The environment
npm. Its required reviewer is the owner, so every publishing run waits for his approval. - The trusted publisher on npm (after the first version). npm accepts a publication only from the workflow
release.ymlofbrunosouzas/stackledger, running in the environmentnpm.
A tag ruleset stops a v* tag from being created, moved or deleted by anyone but its two bypasses, the release app and the owner.
Since AB#243 the repository has its own GitHub App, brunosouzas-stackledger-release (the naming rule: brunosouzas-<repository>-release): Contents, Pull requests and Issues read and write, Metadata read, no webhook, installed on this repository alone. It opens the release pull request (a pull request opened with the workflow's own token starts no checks) and, in the publish job, makes the tag and the GitHub release with a one-hour token for this repository and Contents only.
- The App ID and the private key are in 1Password, vault
Automation, itemGitHub App - brunosouzas-stackledger-release(the key as the attachmentprivatekey). - The environments
release-please(deployment branchmainonly, no reviewer) andnpmeach hold the variableRELEASE_APP_CLIENT_ID(the Client ID, not a secret) and the secretRELEASE_APP_PRIVATE_KEY(the PEM). - Rotate the key: generate a new one on the app's page, attach it to the 1Password item, set the secret again in both environments (
op read "op://automation/GitHub App - brunosouzas-stackledger-release/privatekey" | gh secret set RELEASE_APP_PRIVATE_KEY -R brunosouzas/stackledger -e <environment>), then delete the old key on the app's page.
npm lets a package trust a GitHub workflow only once the package exists. So the first version of a package is published with a short-lived token, and the token is removed right after. The owner does every step below; the agent does none of them.
The package is @brunosouzas/stackledger, in the npm organisation brunosouzas; its first version is 0.4.1. Versions 0.1.0 to 0.4.0 were published by the same workflow under the unscoped name stackledger (npm user bruno_souza), which is deprecated and points to the scoped name. The command is stackledger in both.
-
Sign in to npmjs.com with two-factor authentication on (npm docs). The organisation
brunosouzasmust exist, with the owner in it. -
Create a granular access token (npm docs): Access Tokens → Generate New Token → Granular Access Token.
- Name:
stackledger first release. - Expiration: 7 days.
- Packages and scopes: permission Read and write, not "Read and write (stage only)": a stage-only token cannot run
npm publish. Select Only select packages and scopes, with the scope@brunosouzasand no package (the package does not exist yet, and the token needs nothing else). - Tick Bypass two-factor authentication: the job cannot answer a two-factor prompt. npm is phasing such tokens out for direct publishing; this one lives for one release.
- Organizations: no access.
Copy the token once; it is shown only once. Never paste it anywhere but the secret below.
- Name:
If the publishing job later fails with 403, or with E404 Not Found - PUT, the token lacks a permission (npm often reports a missing scope permission as 404): make a new token with Organizations set to read only, replace the secret, and re-run the job.
For 0.4.1 the environment and the tag ruleset (step 3) already exist from 0.1.0: only the NPM_TOKEN environment secret is added again. For a new repository: Settings → Environments → New environment, named npm (GitHub docs).
- Required reviewers: the owner. Leave "Prevent self-review" off: the owner pushes the tag and approves his own run.
- Deployment branches and tags: "Selected branches and tags", with the branch rule
mainand the tag rulev*. - Environment secrets: add
NPM_TOKENwith the token from step 1. It is an environment secret, not a repository secret, so only the approvedpublishjob can read it.
Settings → Rules → Rulesets → New ruleset → New tag ruleset (GitHub docs):
- Name:
release tags; enforcement: Active. - Target tags: include by pattern
v*. - Rules: restrict creations, restrict updates, restrict deletions, block force pushes.
- Bypass list: the release app
brunosouzas-stackledger-releaseand Repository admin (the owner), always allowed. Without the app, a release frommainstops at the tag reservation, before npm, and nothing is published; fix the bypass, then "Re-run failed jobs".
Follow Releasing a version from step 2 (package.json already says 0.4.1):
git switch main && git pull --ff-only
git tag v0.4.1
git push origin v0.4.1Approve the publish job when it waits. npm publishes with the token and with provenance.
Right after the version is on npm:
- On npmjs.com, open the package
@brunosouzas/stackledger→ Settings → Trusted Publisher → GitHub Actions (npm docs): userbrunosouzas, repositorystackledger, workflow filenamerelease.yml, environmentnpm. Save. The configuration stays "Pending validation" until a release publishes through it, and expires after 48 hours without one; the next release re-creates it if needed (see step 3 of Releasing a version). - In the same settings, Publishing access: choose "Require two-factor authentication and disallow tokens". From now on only the trusted workflow can publish.
- Revoke the token: Access Tokens → the
stackledger first releasetoken → Delete. - Delete the environment secret
NPM_TOKENin Settings → Environments →npm.
The workflow still passes NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}. With the secret gone it is empty, and npm publishes through OpenID Connect: the job proves who it is with a short-lived token from GitHub, and no long-lived npm token exists anywhere.
Signed in to npm as bruno_souza, the owner of the unscoped package, with two-factor authentication. The account brunosouzas became the organisation and does not own the unscoped package, so npm whoami must print bruno_souza first; otherwise npm answers 404. Type the command rather than paste it, so no stray backtick reaches the shell:
npm whoami
npm deprecate stackledger "Moved to @brunosouzas/stackledger"Without a version range the message applies to every version. They stay installable; npm install stackledger and npx stackledger show the message.
Done once, before the first version that should release on merge (AB#172):
- Settings → Environments →
npm→ Deployment branches and tags: add the branch rulemain(keepv*). Without it thepublishjob of a push tomaincannot enter the environment. - Settings → Rules → Rulesets →
release tags: since AB#243 creations are restricted again, with the release app in the bypass list (see The release app).
The trusted publisher on npm does not change: it names the workflow file release.yml and the environment npm, not the trigger. AB#243 added the release app, so creations are restricted again; its tag push is the one detect skips.
On npm. The package page on npmjs.com shows a provenance badge naming the repository, the workflow and the commit. From the command line:
npm view @brunosouzas/stackledger@0.8.0 dist --json # integrity and attestations.provenanceSignatures and provenance of an install. In a scratch folder, not in a project:
mkdir stackledger-check && cd stackledger-check
npm init -y
npm install @brunosouzas/stackledger@0.8.0
npm audit signaturesnpm audit signatures checks the registry signature of every installed package and the provenance attestation of those that have one; stackledger must be counted under "verified attestation". Then delete the folder.
The SBOM. The GitHub release of the tag has stackledger-<version>.cdx.json attached: a CycloneDX list of the production dependencies with their versions and integrity hashes, the same versions npm-shrinkwrap.json locks. To read it:
gh release download v0.8.0 -R brunosouzas/stackledger -p 'stackledger-*.cdx.json'What this proves. Provenance says the tarball on npm was built by release.yml in brunosouzas/stackledger from the tagged commit; it does not say the code is safe. The SBOM says which dependency versions the package installs, so you can check them against advisories later. The tarball on npm is the one the check job tested and audited: publish uploads those bytes and builds nothing.