name: Release on: push: tags: - 'v*.*.*' workflow_dispatch: inputs: tag: description: '要发布的 tag(例如 v0.24.0)' required: true permissions: contents: write concurrency: group: release-${{ github.ref }} cancel-in-progress: false jobs: release: runs-on: ubuntu-latest env: TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }} steps: - name: Checkout tag uses: actions/checkout@v4 with: ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }} fetch-depth: 0 - name: Verify tag matches package.json run: | version="$(node -p "require('./package.json').version")" if [ "$TAG" != "v$version" ]; then echo "::error::tag $TAG 与 package.json 的 v$version 不一致" exit 1 fi - name: Setup pnpm uses: pnpm/action-setup@v4 with: version: 10 - name: Setup Node uses: actions/setup-node@v4 with: node-version: 22 cache: pnpm - run: pnpm install --frozen-lockfile - run: pnpm check - run: pnpm test - run: pnpm build - name: Verify committed client bundle run: | if ! git diff --quiet -- lib/client.js; then echo "::error::lib/client.js 与 src/ 不一致:请本地 pnpm build 后提交再打 tag" git diff --stat -- lib/client.js exit 1 fi - name: Generate release notes from changelog run: node scripts/release-notes.mjs --out release-notes.md - name: Append full changelog link run: | { echo "" echo "---" echo "完整版本历史:[docs/changelog.md](https://github.com/$GITHUB_REPOSITORY/blob/main/docs/changelog.md)" } >> release-notes.md - name: Pack npm tarball run: | mkdir -p dist npm pack --pack-destination dist - name: Create or update GitHub Release env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | if gh release view "$TAG" >/dev/null 2>&1; then gh release edit "$TAG" --title "$TAG" --notes-file release-notes.md gh release upload "$TAG" dist/*.tgz --clobber else gh release create "$TAG" dist/*.tgz \ --title "$TAG" \ --notes-file release-notes.md \ --verify-tag fi