From 5de3460884170280dfdcff3d4d0d52646e805f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=87=AF90331?= <90331@sangfor.com> Date: Thu, 14 May 2026 16:33:03 +0800 Subject: [PATCH 1/5] ci(publish-npm): add dry-run support and normalize version input Add optional dry-run flag to workflow dispatch for validating publishes without uploading to the registry. Support version inputs with or without the v prefix by resolving the correct git ref automatically. Skip changelog generation and GitHub release creation when running in dry-run mode. Co-authored-by: CoStrict --- .github/workflows/publish-npm.yml | 46 +++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index 351e107cf..cb461a7da 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -7,9 +7,14 @@ on: workflow_dispatch: inputs: version: - description: '版本号 (例如: v1.9.0)' + description: '版本号 (例如: 4.0.16)' required: true type: string + dry_run: + description: 'Dry run (仅验证,不实际发布)' + required: false + type: boolean + default: false permissions: contents: write @@ -22,7 +27,26 @@ jobs: steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2, 2026-04-25 with: - ref: ${{ github.event.inputs.version || github.ref }} + fetch-depth: 0 + + - name: Resolve version ref + id: version + run: | + RAW="${{ github.event.inputs.version || github.ref_name }}" + RAW_NO_V="${RAW#v}" + if git rev-parse "v${RAW_NO_V}" >/dev/null 2>&1; then + echo "tag=v${RAW_NO_V}" >> "$GITHUB_OUTPUT" + echo "ref=v${RAW_NO_V}" >> "$GITHUB_OUTPUT" + elif git rev-parse "${RAW}" >/dev/null 2>&1; then + echo "tag=${RAW}" >> "$GITHUB_OUTPUT" + echo "ref=${RAW}" >> "$GITHUB_OUTPUT" + else + echo "Error: neither v${RAW_NO_V} nor ${RAW} exists" >&2 + exit 1 + fi + echo "raw=${RAW_NO_V}" >> "$GITHUB_OUTPUT" + + - run: git checkout "${{ steps.version.outputs.ref }}" - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6, 2026-04-25 with: @@ -43,14 +67,22 @@ jobs: run: bun test - name: Publish to npm + if: ${{ !github.event.inputs.dry_run }} run: npm publish --provenance --access public env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Publish to npm (dry-run) + if: ${{ github.event.inputs.dry_run }} + run: npm publish --dry-run --provenance --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Generate changelog + if: ${{ !github.event.inputs.dry_run }} id: changelog run: | - VERSION="${{ github.event.inputs.version || github.ref_name }}" + VERSION="${{ steps.version.outputs.tag }}" PREV_TAG=$(git tag --sort=-version:refname | grep -v "^${VERSION#v}$" | head -1) if [ -n "$PREV_TAG" ]; then @@ -66,14 +98,16 @@ jobs: } >> "$GITHUB_OUTPUT" - name: Create GitHub Release + if: ${{ !github.event.inputs.dry_run }} uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2, 2026-04-25 with: - name: ${{ github.event.inputs.version || github.ref_name }} + tag_name: ${{ steps.version.outputs.tag }} + name: ${{ steps.version.outputs.tag }} body: | ## What's Changed ${{ steps.changelog.outputs.commits }} - **Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ github.event.inputs.version || github.ref_name }}^...${{ github.event.inputs.version || github.ref_name }} + **Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ steps.version.outputs.tag }}^...${{ steps.version.outputs.tag }} draft: false - prerelease: ${{ contains(github.event.inputs.version || github.ref_name, 'rc') || contains(github.event.inputs.version || github.ref_name, 'beta') || contains(github.event.inputs.version || github.ref_name, 'alpha') }} + prerelease: ${{ contains(steps.version.outputs.raw, 'rc') || contains(steps.version.outputs.raw, 'beta') || contains(steps.version.outputs.raw, 'alpha') }} From de53813db33c3c0b268233bb051198f0c0461a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=87=AF90331?= <90331@sangfor.com> Date: Thu, 14 May 2026 16:37:35 +0800 Subject: [PATCH 2/5] ci(publish-npm): auto-create missing tag on manual dispatch When triggering the publish workflow manually with a version that does not yet have a corresponding git tag, automatically create and push the v-prefixed tag on the current HEAD instead of failing. Co-authored-by: CoStrict --- .github/workflows/publish-npm.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index cb461a7da..b4d73c683 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -34,14 +34,23 @@ jobs: run: | RAW="${{ github.event.inputs.version || github.ref_name }}" RAW_NO_V="${RAW#v}" - if git rev-parse "v${RAW_NO_V}" >/dev/null 2>&1; then - echo "tag=v${RAW_NO_V}" >> "$GITHUB_OUTPUT" - echo "ref=v${RAW_NO_V}" >> "$GITHUB_OUTPUT" + TAG="v${RAW_NO_V}" + + if git rev-parse "${TAG}" >/dev/null 2>&1; then + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" + echo "ref=${TAG}" >> "$GITHUB_OUTPUT" elif git rev-parse "${RAW}" >/dev/null 2>&1; then echo "tag=${RAW}" >> "$GITHUB_OUTPUT" echo "ref=${RAW}" >> "$GITHUB_OUTPUT" + elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag "${TAG}" + git push origin "${TAG}" + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" + echo "ref=${TAG}" >> "$GITHUB_OUTPUT" else - echo "Error: neither v${RAW_NO_V} nor ${RAW} exists" >&2 + echo "Error: tag ${TAG} does not exist" >&2 exit 1 fi echo "raw=${RAW_NO_V}" >> "$GITHUB_OUTPUT" From a23ebc03033c122610ac55170c7a6bd93c5e8b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=87=AF90331?= <90331@sangfor.com> Date: Thu, 14 May 2026 16:57:09 +0800 Subject: [PATCH 3/5] ci(publish-npm): restrict to manual trigger and auto-sync version Remove push tag trigger so the workflow only runs on manual dispatch. Add steps to automatically sync package.json and scripts/defines.ts version before publishing, create the git tag, and skip typecheck. Co-authored-by: CoStrict --- .github/workflows/publish-npm.yml | 44 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index b4d73c683..ddcd70bc5 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -1,9 +1,6 @@ name: Publish to npm on: - push: - tags: - - 'v*' workflow_dispatch: inputs: version: @@ -35,27 +32,36 @@ jobs: RAW="${{ github.event.inputs.version || github.ref_name }}" RAW_NO_V="${RAW#v}" TAG="v${RAW_NO_V}" + echo "raw=${RAW_NO_V}" >> "$GITHUB_OUTPUT" + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" - if git rev-parse "${TAG}" >/dev/null 2>&1; then - echo "tag=${TAG}" >> "$GITHUB_OUTPUT" - echo "ref=${TAG}" >> "$GITHUB_OUTPUT" - elif git rev-parse "${RAW}" >/dev/null 2>&1; then - echo "tag=${RAW}" >> "$GITHUB_OUTPUT" - echo "ref=${RAW}" >> "$GITHUB_OUTPUT" - elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + - name: Sync package version + if: ${{ github.event_name == 'workflow_dispatch' && !github.event.inputs.dry_run }} + run: | + VERSION="${{ steps.version.outputs.raw }}" + # Update package.json + jq --arg v "$VERSION" '.version = $v' package.json > package.json.tmp && mv package.json.tmp package.json + # Update scripts/defines.ts + sed -i "s/\"MACRO.VERSION\": JSON.stringify(\"[^\"]*\")/\"MACRO.VERSION\": JSON.stringify(\"$VERSION\")/" scripts/defines.ts + # Commit and push version bump + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add package.json scripts/defines.ts + git commit -m "chore(release): bump version to ${VERSION}" + git push origin HEAD + + - name: Create tag if missing + if: ${{ github.event_name == 'workflow_dispatch' }} + run: | + TAG="${{ steps.version.outputs.tag }}" + if ! git rev-parse "${TAG}" >/dev/null 2>&1; then git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git tag "${TAG}" git push origin "${TAG}" - echo "tag=${TAG}" >> "$GITHUB_OUTPUT" - echo "ref=${TAG}" >> "$GITHUB_OUTPUT" - else - echo "Error: tag ${TAG} does not exist" >&2 - exit 1 fi - echo "raw=${RAW_NO_V}" >> "$GITHUB_OUTPUT" - - run: git checkout "${{ steps.version.outputs.ref }}" + - run: git checkout "${{ steps.version.outputs.tag }}" - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6, 2026-04-25 with: @@ -69,8 +75,8 @@ jobs: - name: Install dependencies run: bun install --frozen-lockfile - - name: Type check - run: bun run typecheck + # - name: Type check + # run: bun run typecheck - name: Run tests run: bun test From 86c68723a45cfc0a946c5e418ab5f4071cf397fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=87=AF90331?= <90331@sangfor.com> Date: Thu, 14 May 2026 17:07:16 +0800 Subject: [PATCH 4/5] ci(publish-npm): drop v prefix from tags and skip tests Use the exact input version for git tags without adding a v prefix. Also comment out typecheck and test steps to speed up the publish flow. Co-authored-by: CoStrict --- .github/workflows/publish-npm.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index ddcd70bc5..052933594 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -31,7 +31,7 @@ jobs: run: | RAW="${{ github.event.inputs.version || github.ref_name }}" RAW_NO_V="${RAW#v}" - TAG="v${RAW_NO_V}" + TAG="${RAW_NO_V}" echo "raw=${RAW_NO_V}" >> "$GITHUB_OUTPUT" echo "tag=${TAG}" >> "$GITHUB_OUTPUT" @@ -78,8 +78,8 @@ jobs: # - name: Type check # run: bun run typecheck - - name: Run tests - run: bun test + # - name: Run tests + # run: bun test - name: Publish to npm if: ${{ !github.event.inputs.dry_run }} @@ -98,7 +98,7 @@ jobs: id: changelog run: | VERSION="${{ steps.version.outputs.tag }}" - PREV_TAG=$(git tag --sort=-version:refname | grep -v "^${VERSION#v}$" | head -1) + PREV_TAG=$(git tag --sort=-version:refname | grep -v "^${VERSION}$" | head -1) if [ -n "$PREV_TAG" ]; then COMMITS=$(git log "${PREV_TAG}..${VERSION}" --pretty=format:"- %s (%h)" --no-merges) From 5890d776ddf8728d5c23f021cf68d44dcbc2068b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=87=AF90331?= <90331@sangfor.com> Date: Thu, 14 May 2026 17:13:30 +0800 Subject: [PATCH 5/5] ci(publish-npm): add ssh setup and review builtin generation Add SSH agent setup before build so generate-review-builtin.ts can clone the private costrict-review repo. Also run the generator explicitly with continue-on-error to ensure the bundled review skills file exists before Bun.build. Co-authored-by: CoStrict --- .github/workflows/publish-npm.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index 052933594..1562b0b10 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -73,6 +73,15 @@ jobs: with: bun-version: latest + - name: Setup SSH for review agent generation + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.MY_SSH_PRIVATE_KEY }} + + - name: Generate review builtin files + run: bun run scripts/generate-review-builtin.ts + continue-on-error: true + - name: Install dependencies run: bun install --frozen-lockfile # - name: Type check