Skip to content

Commit c73d3d6

Browse files
ochafikclaude
andcommitted
Add npm publish workflow
- Add .github/workflows/npm-publish.yml triggered on GitHub releases - Runs build and test jobs before publishing - Uses NPM_TOKEN secret with OIDC provenance - Smart npm tagging: latest, beta, or release-X.Y - Add prepack hook to package.json for automatic builds - Move bun from dependencies to devDependencies - Add npm test step to CI workflow 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 3aa93db commit c73d3d6

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ jobs:
2727

2828
- run: npm run build:all
2929

30+
- run: npm test
31+
3032
- run: npm run prettier

.github/workflows/npm-publish.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: oven-sh/setup-bun@v2
17+
with:
18+
bun-version: latest
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version: "22"
22+
cache: npm
23+
- run: npm ci
24+
- run: npm run build
25+
- run: npm run prettier
26+
27+
test:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v4
31+
- uses: oven-sh/setup-bun@v2
32+
with:
33+
bun-version: latest
34+
- uses: actions/setup-node@v4
35+
with:
36+
node-version: "22"
37+
cache: npm
38+
- run: npm ci
39+
- run: npm test
40+
41+
publish:
42+
runs-on: ubuntu-latest
43+
if: github.event_name == 'release'
44+
environment: release
45+
needs: [build, test]
46+
47+
permissions:
48+
contents: read
49+
id-token: write
50+
51+
steps:
52+
- uses: actions/checkout@v4
53+
- uses: oven-sh/setup-bun@v2
54+
with:
55+
bun-version: latest
56+
- uses: actions/setup-node@v4
57+
with:
58+
node-version: "22"
59+
cache: npm
60+
registry-url: "https://registry.npmjs.org"
61+
- run: npm ci
62+
63+
- name: Determine npm tag
64+
id: npm-tag
65+
run: |
66+
VERSION=$(node -p "require('./package.json').version")
67+
# Check if this is a beta release
68+
if [[ "$VERSION" == *"-beta"* ]]; then
69+
echo "tag=--tag beta" >> $GITHUB_OUTPUT
70+
# Check if this release is from a non-main branch (patch/maintenance release)
71+
elif [[ "${{ github.event.release.target_commitish }}" != "main" ]]; then
72+
# Use "release-X.Y" as tag for old branch releases
73+
MAJOR_MINOR=$(echo "$VERSION" | cut -d. -f1,2)
74+
echo "tag=--tag release-${MAJOR_MINOR}" >> $GITHUB_OUTPUT
75+
else
76+
echo "tag=" >> $GITHUB_OUTPUT
77+
fi
78+
79+
- run: npm publish --provenance --access public ${{ steps.npm-tag.outputs.tag }}
80+
env:
81+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
],
2828
"scripts": {
2929
"build": "bun build.bun.ts",
30+
"prepack": "npm run build",
3031
"build:all": "npm run build && npm run examples:build",
3132
"test": "bun test",
3233
"examples:build": "find examples -maxdepth 1 -mindepth 1 -type d -exec printf '%s\\0' 'npm run --workspace={} build' ';' | xargs -0 concurrently --kill-others-on-fail",
@@ -49,6 +50,7 @@
4950
"author": "Olivier Chafik",
5051
"devDependencies": {
5152
"@types/bun": "^1.3.2",
53+
"bun": "^1.3.2",
5254
"@types/react": "^19.2.2",
5355
"@types/react-dom": "^19.2.2",
5456
"concurrently": "^9.2.1",
@@ -63,7 +65,6 @@
6365
},
6466
"dependencies": {
6567
"@modelcontextprotocol/sdk": "^1.23.0",
66-
"bun": "^1.3.2",
6768
"react": "^19.2.0",
6869
"react-dom": "^19.2.0",
6970
"zod": "^3.25"

0 commit comments

Comments
 (0)