Skip to content

Commit 63190ef

Browse files
author
chenliuyun
committed
ci: add GitHub Actions for CI and auto-publish on release
1 parent 5111f2f commit 63190ef

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [18.x, 20.x, 22.x]
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Use Node.js ${{ matrix.node-version }}
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: ${{ matrix.node-version }}
21+
cache: npm
22+
- run: npm ci
23+
- run: npm run build
24+
- run: npm test

.github/workflows/publish.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
id-token: write
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: 20.x
18+
registry-url: https://registry.npmjs.org
19+
cache: npm
20+
- run: npm ci
21+
- run: npm run build
22+
- run: npm test
23+
- name: Verify tag matches package.json version
24+
run: |
25+
PKG_VERSION=$(node -p "require('./package.json').version")
26+
TAG_VERSION="${GITHUB_REF_NAME#v}"
27+
if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then
28+
echo "Tag $TAG_VERSION does not match package.json version $PKG_VERSION"
29+
exit 1
30+
fi
31+
- run: npm publish --provenance --access public
32+
env:
33+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)