Skip to content

Commit 1acadcd

Browse files
chore(p1): add npm publish workflow (#40)
1 parent b2f7ad8 commit 1acadcd

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

.github/workflows/npm-publish.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: NPM Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
tag:
9+
description: 'Tag to publish (vX.Y.Z)'
10+
required: true
11+
type: string
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
env:
19+
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.event.release.tag_name }}
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
ref: ${{ env.RELEASE_TAG }}
24+
25+
- name: Use Node.js 22.x
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: 22.x
29+
registry-url: 'https://registry.npmjs.org'
30+
cache: 'npm'
31+
32+
- name: Install dependencies
33+
run: npm ci
34+
35+
- name: Check Version
36+
run: |
37+
TAG="${RELEASE_TAG#v}"
38+
PKG=$(node -p "require('./package.json').version")
39+
if [ "$PKG" != "$TAG" ]; then
40+
echo "Version mismatch: Tag $TAG vs Package $PKG" >&2
41+
exit 1
42+
fi
43+
44+
- name: Build
45+
run: npm run build
46+
47+
- name: Publish
48+
env:
49+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
50+
run: npm publish --access public

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
"bin": {
88
"cloudsqlctl": "./dist/cli.cjs"
99
},
10+
"files": [
11+
"dist",
12+
"README.md",
13+
"LICENSE",
14+
"CHANGELOG.md"
15+
],
1016
"engines": {
1117
"node": ">=22.0.0"
1218
},

0 commit comments

Comments
 (0)