Add GitHub Actions CI and release workflows

This commit is contained in:
yangzhenhui
2026-03-26 16:44:44 +08:00
parent 2b37e81d44
commit 30ce20ff01
2 changed files with 87 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
name: CI
on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:
jobs:
build:
name: Build (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 20
- 24
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Verify publish artifact
run: npm pack --dry-run
+47
View File
@@ -0,0 +1,47 @@
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: read
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
cache: npm
- name: Ensure tag matches package version
run: |
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
TAG_VERSION="${GITHUB_REF_NAME#v}"
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
echo "package.json version ($PACKAGE_VERSION) does not match tag ($TAG_VERSION)"
exit 1
fi
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Verify publish artifact
run: npm pack --dry-run
- name: Publish to npm
run: npm publish --access public