Skip to content

Commit 6a95e22

Browse files
committed
ci: add publish-npm-on-release workflow for manual or release-triggered npm publish
1 parent 7238d35 commit 6a95e22

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Publishes to npm when a GitHub release is created (or on manual run for a given tag).
2+
# Use when release-please didn't run publish (e.g. manual release or "chore: release" merge).
3+
name: Publish to npm on release
4+
5+
on:
6+
release:
7+
types: [published]
8+
workflow_dispatch:
9+
inputs:
10+
tag:
11+
description: 'Tag to publish (e.g. v1.6.2)'
12+
required: true
13+
default: 'v1.6.2'
14+
15+
permissions:
16+
contents: read
17+
id-token: write
18+
19+
jobs:
20+
publish:
21+
name: Publish to npm
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
ref: ${{ github.event.inputs.tag || github.event.release.tag_name }}
27+
28+
- uses: pnpm/action-setup@v2
29+
with:
30+
version: 10
31+
32+
- uses: actions/setup-node@v4
33+
with:
34+
node-version: '24'
35+
registry-url: 'https://registry.npmjs.org'
36+
cache: 'pnpm'
37+
38+
- run: pnpm install --frozen-lockfile
39+
40+
- name: Check if version already published
41+
id: check
42+
run: |
43+
VERSION="$(node -e "console.log(JSON.parse(require('fs').readFileSync('package.json','utf8')).version)")"
44+
if npm view "codebase-context@${VERSION}" version 2>/dev/null; then
45+
echo "already_published=true" >> "$GITHUB_OUTPUT"
46+
else
47+
echo "already_published=false" >> "$GITHUB_OUTPUT"
48+
fi
49+
50+
- name: Quality gates
51+
if: steps.check.outputs.already_published != 'true'
52+
run: |
53+
pnpm lint
54+
pnpm format:check
55+
pnpm type-check
56+
pnpm test
57+
pnpm build
58+
59+
- name: Publish to npm with provenance
60+
if: steps.check.outputs.already_published != 'true'
61+
run: pnpm publish --access public --no-git-checks --provenance

0 commit comments

Comments
 (0)