From 30ce20ff015356eaeb39964b649573acdc60776b Mon Sep 17 00:00:00 2001 From: yangzhenhui Date: Thu, 26 Mar 2026 16:44:44 +0800 Subject: [PATCH] Add GitHub Actions CI and release workflows --- .github/workflows/ci.yml | 40 +++++++++++++++++++++++++++++ .github/workflows/release.yml | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e1bb1f1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..214ac81 --- /dev/null +++ b/.github/workflows/release.yml @@ -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