Skip to content

Commit d33a15f

Browse files
yuaanlinclaude
andcommitted
ci: automate npm publish on release
Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 7f4686e commit d33a15f

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

.github/workflows/release.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,17 @@ jobs:
4242
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4343
TAG: ${{ env.TAG }}
4444
TAP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }}
45+
46+
- uses: actions/setup-node@v4
47+
with:
48+
node-version: "20"
49+
registry-url: "https://registry.npmjs.org"
50+
51+
- name: Publish to npm
52+
working-directory: npm
53+
env:
54+
VERSION: ${{ github.ref_name }}
55+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
56+
run: |
57+
bash prepare.sh
58+
npm publish

npm/prepare.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
set -euxo pipefail
44
cp -r ../README.md ../dist/* .
55

6-
# bump version
7-
LATEST_TAG=$(gh api repos/:owner/:repo/tags --jq '.[0].name' | sed 's/^v//')
8-
jq --arg ver "$LATEST_TAG" '.version = $ver' package.json > package.json.tmp && mv package.json.tmp package.json
6+
# Use VERSION env var if set (CI), otherwise fetch from GitHub API (local)
7+
if [ -z "${VERSION:-}" ]; then
8+
VERSION=$(gh api repos/:owner/:repo/tags --jq '.[0].name')
9+
fi
10+
11+
# Strip 'v' prefix and bump version
12+
VERSION="${VERSION#v}"
13+
jq --arg ver "$VERSION" '.version = $ver' package.json > package.json.tmp && mv package.json.tmp package.json

0 commit comments

Comments
 (0)