From bf03109d76e6dcffdcbd771aab8c2d358df8c118 Mon Sep 17 00:00:00 2001 From: Simon Shi Date: Tue, 16 Jun 2026 13:38:59 +0800 Subject: [PATCH] ci: add build CI and Trusted Publishing release workflows --- .github/workflows/ci.yml | 44 +++++++++++++++++++++++++++ .github/workflows/release.yml | 57 +++++++++++++++++++++++++++++++++++ 2 files changed, 101 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..2c17a9d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,44 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: + contents: read + +jobs: + build: + name: Lint, typecheck & build + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Lint + run: npm run lint + + - name: Type check + run: npm run check + + - name: Build + run: npm run build + + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/ + if-no-files-found: error + retention-days: 14 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d07e687 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,57 @@ +name: Release + +on: + push: + tags: + - "v*" + +permissions: + contents: read + # Required for npm provenance (OIDC). + id-token: write + +jobs: + publish: + name: Build & publish to npm + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + registry-url: https://registry.npmjs.org + cache: npm + + # Trusted Publishing (OIDC) requires npm >= 11.5.1. + - name: Upgrade npm + run: npm install -g npm@latest + + - name: Install dependencies + run: npm ci + + - name: Verify tag matches package.json version + run: | + PKG_VERSION="$(node -p "require('./package.json').version")" + TAG_VERSION="${GITHUB_REF_NAME#v}" + if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then + echo "::error::Tag $GITHUB_REF_NAME ($TAG_VERSION) does not match package.json version ($PKG_VERSION)" + exit 1 + fi + echo "Publishing version $PKG_VERSION" + + - name: Lint + run: npm run lint + + - name: Type check + run: npm run check + + - name: Build + run: npm run build + + # Publishes via Trusted Publishing (OIDC) — no NPM_TOKEN needed. + # npm publish runs prepublishOnly (check + build) again as a safety net. + - name: Publish to npm + run: npm publish --provenance --access public