From e32e86a377f264ec7fa28c6a366317bd4a4da7b6 Mon Sep 17 00:00:00 2001 From: yuez Date: Thu, 22 Oct 2026 17:19:38 +0800 Subject: [PATCH] ci: add a check pipeline and a tag-driven npm release ci runs typecheck + unit tests + build + scripts/smoke.sh and asserts the publishable tarball embeds dist/ and web/dist/ without leaking src/ or test/. release verifies the tag matches package.json, runs the tests and publishes with provenance. --- .github/workflows/ci.yml | 78 +++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 64 ++++++++++++++++++++++++++++ 2 files changed, 142 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..2b0a080 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,78 @@ +name: ci + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: pnpm/action-setup@v4 + with: + version: 10 + + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + cache-dependency-path: | + pnpm-lock.yaml + web/pnpm-lock.yaml + + - name: Install daemon deps + run: pnpm install --frozen-lockfile + + - name: Install web deps + run: pnpm --dir web install --frozen-lockfile + + - name: Typecheck daemon + run: pnpm typecheck + + - name: Typecheck web + run: pnpm --dir web typecheck + + - name: Unit tests (daemon) + run: pnpm test + + - name: Unit tests (web) + run: pnpm --dir web exec vitest run + + - name: Build daemon + run: pnpm build + + - name: Build web + run: pnpm build:web + + - name: Smoke (daemon + static UI round trip) + run: bash scripts/smoke.sh + + # --ignore-scripts: everything is already built above, and prepack's build + # output would corrupt the JSON on stdout. + - name: Check the publishable tarball embeds dist + web/dist + run: | + node -e 'if (!require("./package.json").scripts.prepack) { console.error("prepack missing"); process.exit(1) }' + npm pack --dry-run --json --ignore-scripts > pack.json + node -e ' + const [t] = require("./pack.json"); + const files = t.files.map((f) => f.path); + for (const need of ["dist/cli/pi2.js", "web/dist/index.html", "docs/protocol.md"]) { + if (!files.includes(need)) { + console.error(`missing from tarball: ${need}`); + process.exit(1); + } + } + if (files.some((f) => f.startsWith("src/") || f.startsWith("test/"))) { + console.error("tarball leaks source or tests"); + process.exit(1); + } + console.log(`tarball ok: ${files.length} files`); + ' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4de19d5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,64 @@ +name: release + +on: + push: + tags: ["v*"] + +permissions: + contents: read + id-token: write # npm provenance + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: pnpm/action-setup@v4 + with: + version: 10 + + - uses: actions/setup-node@v4 + with: + node-version: 22 + registry-url: https://registry.npmjs.org + cache: pnpm + cache-dependency-path: | + pnpm-lock.yaml + web/pnpm-lock.yaml + + - name: Tag must match package.json version + run: | + tag="${GITHUB_REF_NAME#v}" + pkg="$(node -p 'require("./package.json").version')" + if [ "$tag" != "$pkg" ]; then + echo "tag $GITHUB_REF_NAME does not match package.json $pkg" >&2 + exit 1 + fi + + - name: Install deps + run: | + pnpm install --frozen-lockfile + pnpm --dir web install --frozen-lockfile + + - name: Test + run: | + pnpm typecheck + pnpm test + pnpm --dir web exec vitest run + + # `prepack` builds dist/ and web/dist/ as part of pack+publish, so the + # published tarball is always built from the tagged source. + - name: Publish to npm + run: npm publish --access public --provenance + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Create GitHub release + uses: softprops/action-gh-release@v2 + with: + generate_release_notes: true + body: | + `npm i -g pi2d@${{ github.ref_name }}` + + Compatible pi2.nvim: protocol v1 (see `docs/protocol.md`).