Skip to content

GitHub Actions NPM CI/CD Setup

Bumper comes with built-in support for updating npm packages in a way that plugs in conveniently with npm publishing.

For a given release group, update your config:

.bumper/config.toml
[[groups]]
name = "my-package"
display_name = "my-package"
changelog_cmd = ["bumper", "builtins", "amendlog:default"]
cat_cmd = ["bumper", "builtins", "cat:default"]
current_cmd = ["bumper", "builtins", "current:default"]
next_cmd = ["bumper", "builtins", "next:default"]
current_cmd = ["bumper", "builtins", "current:npm", "--package", "package.json"]
next_cmd = ["bumper", "builtins", "next:npm", "--package", "package.json"]

Now in your GitHub Actions workflow, you can set up a release job that triggers on changes to package.json files:

.github/workflows/release.yml
name: Release
on:
# Allows manual triggering of the workflow
workflow_dispatch:
# Only run this workflow automatically on pushes that modify package.json files
push:
branches:
- main # Adjust this based on your default branch
paths: [package.json]
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
npm-publish:
runs-on: ubuntu-latest
permissions:
contents: write # To push tags
id-token: write # To publish using NPM trusted publishing
steps:
steps:
- name: Checkout repository
uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493 # v5.0.0
- name: Set up Node.js
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
with:
node-version: 'lts/*'
- name: Install dependencies
run: npm install
- name: Get latest version
id: bumper
run: |
latest_version=$(mise bumper current --group my-package)
echo "latest_version=$latest_version" >> $GITHUB_OUTPUT
if npm view "my-package@$latest_version" version &>/dev/null; then
echo "Version $latest_version already exists on NPM. Skipping publish."
echo "should_publish=false" >> $GITHUB_OUTPUT
else
echo "should_publish=true" >> $GITHUB_OUTPUT
fi
- name: Publish
if: steps.bumper.outputs.should_publish == 'true'
run: |
npm publish --provenance
tag="v${{ steps.bumper.outputs.latest_version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "$tag"
git push origin "$tag"