Skip to content

Commit cc1a795

Browse files
committed
Add manually-triggered npm publish workflow
Bump version in package.json, push to main, then run the "Publish to npm" workflow with a dist-tag choice (latest/next/beta). Workflow installs, builds, publishes, and creates a git tag. Requires NPM_TOKEN secret set in the repo (Settings > Secrets and variables > Actions).
1 parent 9b43916 commit cc1a795

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Publish to npm
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
dist_tag:
7+
description: 'npm dist-tag to publish under'
8+
required: true
9+
default: 'latest'
10+
type: choice
11+
options:
12+
- latest
13+
- next
14+
- beta
15+
16+
jobs:
17+
publish:
18+
name: Publish
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: write
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Setup pnpm
29+
uses: pnpm/action-setup@v4
30+
with:
31+
version: 10
32+
33+
- name: Setup Node.js
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: '24.x'
37+
registry-url: 'https://registry.npmjs.org'
38+
cache: 'pnpm'
39+
40+
- name: Install dependencies
41+
run: pnpm install --frozen-lockfile
42+
43+
- name: Build
44+
run: pnpm build
45+
46+
- name: Resolve version
47+
id: version
48+
run: |
49+
VERSION=$(node -p "require('./package.json').version")
50+
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
51+
echo "tag_name=v${VERSION}" >> "$GITHUB_OUTPUT"
52+
echo "Publishing version ${VERSION} under dist-tag '${{ inputs.dist_tag }}'"
53+
54+
- name: Publish to npm
55+
run: pnpm publish --tag ${{ inputs.dist_tag }} --no-git-checks --access public
56+
env:
57+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
58+
59+
- name: Create and push git tag
60+
run: |
61+
git config user.name "github-actions[bot]"
62+
git config user.email "github-actions[bot]@users.noreply.github.com"
63+
git tag -a "${{ steps.version.outputs.tag_name }}" -m "Release ${{ steps.version.outputs.version }}"
64+
git push origin "${{ steps.version.outputs.tag_name }}"

0 commit comments

Comments
 (0)