Skip to content

NPM Publish

NPM Publish #11

Workflow file for this run

name: NPM Publish
on:
workflow_dispatch:
inputs:
tag:
description: Release tag to publish, for example v1.2.3.
required: true
type: string
push:
tags:
- v*
permissions:
contents: read
id-token: write
concurrency:
group: npm-publish-${{ github.ref }}
cancel-in-progress: false
jobs:
publish:
name: Publish package
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Validate tag matches package version
shell: bash
run: |
set -euo pipefail
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
tag_name="${{ inputs.tag }}"
else
tag_name="$GITHUB_REF_NAME"
fi
tag_version="${tag_name#v}"
package_version="$(node -p "require('./package.json').version")"
if [ "$tag_version" != "$package_version" ]; then
echo "Tag version '$tag_version' does not match package.json version '$package_version'." >&2
exit 1
fi
- name: Pack dry run
run: npm pack --dry-run
- name: Publish to npm
run: npm publish --access public