Skip to content

Publish to npm

Publish to npm #7

Workflow file for this run

name: Publish to npm
on:
workflow_dispatch:
inputs:
version:
description: 'Version to publish (e.g. 1.6.0)'
required: true
type: string
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org
- run: npm install -g npm@latest
- run: npm ci
- run: npm audit --omit=dev
# Bump package.json to the requested version
- name: Set version
run: npm version "${{ inputs.version }}" --no-git-tag-version --allow-same-version
- run: npm run check
# Commit version bump (if changed), tag, and push
- name: Commit, tag, and push
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add package.json package-lock.json
git diff --cached --quiet || git commit -m "v${{ inputs.version }}"
git tag -f "v${{ inputs.version }}"
git push origin main
git push origin "v${{ inputs.version }}" --force
# Create GitHub Release from the new tag
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "v${{ inputs.version }}" --generate-notes --latest
- run: npm publish --provenance --access public