Skip to content

Publish to NPM

Publish to NPM #30

Workflow file for this run

name: Publish to NPM
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'Version to publish (e.g., 2.1.7)'
required: false
type: string
jobs:
publish:
name: Publish to npm
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org'
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Type check
run: pnpm run type-check
- name: Lint
run: pnpm run lint
- name: Format check
run: pnpm run format:check
- name: Test
run: pnpm run test
- name: Build
run: pnpm run build
- name: Update version
if: github.event_name == 'workflow_dispatch' && github.event.inputs.version != ''
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
if [ "$CURRENT_VERSION" != "${{ github.event.inputs.version }}" ]; then
pnpm version ${{ github.event.inputs.version }} --no-git-tag-version
else
echo "Version $CURRENT_VERSION already matches target, skipping update"
fi
- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}