npm-package-release
v0.6.0
Published
Composable, strongly typed npm release workflows with class-based steps and GitHub Actions interfaces.
Maintainers
Readme
npm Package Release
Release your npm package from GitHub Actions without maintaining custom release scripts or storing an npm publish token.
Implements Releases as Code for JavaScript packages: a GitHub Actions workflow tests and lints your package, publishes it to npm, optionally updates the changelog, creates a Git tag and GitHub Release, and prepares the next version. Workflows are composed from strongly typed classes. Similar projects: rust-crate-release and ruby-gem-release.
Installation
Requires Node.js 22.14+ and npm 11.5.1+; the release workflow defaults to Node.js 26 and npm 12.
npm install --save-dev --save-exact [email protected]The CLI is npr; do not install the unrelated npm package named npr.
Usage
1. Configure Your Package
Create npr.config.js (npr.config.mjs in CommonJS projects, and set the workflow's config input to match):
import { KeepAChangelog, ReleaseWorkflow } from "npm-package-release";
export default new ReleaseWorkflow({
changelog: new KeepAChangelog(),
});Your package needs a numeric version, a GitHub repository URL, and a CHANGELOG.md with real notes under ## [Unreleased]. KeepAChangelog is the default when omitted. By default, validation runs npm test and npm run lint.
2. Add the Release Workflow
Add .github/workflows/release.yml (see the caller example):
name: Release
on:
workflow_dispatch:
inputs:
version:
description: Optional numeric release version.
type: string
required: false
permissions:
contents: write
id-token: write
jobs:
release:
uses: dblock/npm-package-release/.github/workflows/[email protected]
with:
version: ${{ inputs.version }}Merge it and the locked development dependency into your default branch. Always upgrade the package and the pinned workflow together. Branch rules must let the workflow push release commits and tags; see Configure GitHub.
3. Enable Trusted Publishing
The workflow publishes with an npm trusted publisher, so you need no npm token or NODE_AUTH_TOKEN. GitHub creates the release environment on the first run. A new publisher expires unless it publishes within two days, so do this when you are ready to release. npm prompts for 2FA in your terminal or browser.
For a new npm package, npm needs the name to exist first. npr bootstrap reserves it with an empty 0.0.0 placeholder and configures the publisher (npr reserve and npr trust run the steps separately):
npm exec --offline -- npr bootstrap --dry-run
npm login --registry=https://registry.npmjs.org
npm exec --offline -- npr bootstrapKeep your first real version, such as 0.1.0, unpublished in package.json; the workflow publishes it.
For an existing npm package, configure the publisher:
npm exec --offline -- npr trust --dry-run
npm login --registry=https://registry.npmjs.org
npm exec --offline -- npr trustCheck that npm trust list shows your repository, release.yml, environment release, and direct publishing. Alternatively, on the npm website open your package's Settings → Trusted publishing and add a GitHub Actions publisher:
| Field | Value |
| --- | --- |
| Organization or user | Your GitHub owner. |
| Repository | Your package's repository, not this tool's repository. |
| Workflow filename | release.yml, the caller filename only. |
| Environment name | release. |
| Allowed actions | Direct npm publish, not stage-only. |
The npm publisher does not check branches. Optionally restrict the release environment to your default branch.
4. Make a Release
Review your changes, run tests, and dispatch from your default branch:
gh workflow run release.ymlThis publishes the checked-in version and prepares the next patch version; pass -f version=0.2.0 to choose another version. Verify the run summary, the registry version and checksums, and the GitHub Release. Inspect recovery artifacts before retrying a failed run.
For a new package, deprecate the 0.0.0 placeholder after the first release if npr reserve could not.
Documentation
- Detailed Usage: CLI, API, configuration, and defaults, including Version References, Releases Without a Registry such as Zip Archives, and GitHub Actions Releases with optional Floating Tags.
- Changelog Templates: contribution prompts and categories.
- Semantic Releases: opt-in Conventional Commits versioning and generated notes.
- Lifecycle Hooks and the Lifecycle Hook Example: ordered stage extensions.
- Updating Markdown Sections: edit README sections during a release.
- Composable Workflows: custom classes and services.
- Execution Providers and Contexts: lifecycle reporting.
- Testing Custom Workflows: test a release configuration locally.
- Recovery and Reconciliation: retrying failed releases.
- Upgrading: migration steps between versions.
Contributing
See CONTRIBUTING.md, DESIGN.md, CHANGELOG.md, RELEASING.md, UPGRADING.md, AGENTS.md, and the documentation above.
License
Distributed under the MIT License.
