From 6302dec97185135c71c241c78e919881e552f1d9 Mon Sep 17 00:00:00 2001 From: RetricSu Date: Tue, 10 Mar 2026 10:09:12 +0800 Subject: [PATCH] ci: fix changeset workflow to support skip-changeset label --- .github/workflows/changeset-check.yml | 97 +++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 7 deletions(-) diff --git a/.github/workflows/changeset-check.yml b/.github/workflows/changeset-check.yml index 2564fc1..74e31d5 100644 --- a/.github/workflows/changeset-check.yml +++ b/.github/workflows/changeset-check.yml @@ -2,12 +2,17 @@ name: Changeset Check on: pull_request: + types: [opened, reopened, synchronize, ready_for_review, labeled] branches: [master, develop] jobs: - changeset: - name: Require changeset + verify: + name: Verify Changeset + if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-changeset') && !contains(github.event.pull_request.labels.*.name, 'dependencies') }} runs-on: ubuntu-latest + permissions: + pull-requests: write + contents: read steps: - name: Checkout repository @@ -23,14 +28,92 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: "20" + node-version: '20' - name: Install dependencies run: pnpm install --frozen-lockfile - name: Check for changeset + id: check run: | - echo "Checking for changeset files in this PR..." - echo "If this fails, run 'pnpm changeset' to add a changeset describing your changes." - echo "For changes that don't need a changelog entry (docs, CI, refactoring), use 'pnpm changeset --empty'." - pnpm changeset status --since=origin/${{ github.base_ref }} + if pnpm changeset status --since=origin/${{ github.base_ref }}; then + echo "has_changeset=true" >> $GITHUB_OUTPUT + else + echo "has_changeset=false" >> $GITHUB_OUTPUT + exit 1 + fi + + - name: Comment on PR (success) + if: steps.check.outputs.has_changeset == 'true' + uses: actions/github-script@v7 + with: + script: | + const marker = ''; + const body = marker + '\n✅ Changeset file detected.'; + + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + + const existing = comments.find(c => c.body.includes(marker)); + if (existing) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + body + }); + } + + - name: Comment on PR (failure) + if: failure() + uses: actions/github-script@v7 + with: + script: | + const marker = ''; + const body = [ + marker, + '❌ **Missing Changeset**', + '', + 'Please add a changeset describing your changes:', + '```bash', + 'pnpm changeset', + '```', + '', + 'If your changes do not need a version bump (docs, CI, refactoring),', + 'add the `skip-changeset` label to this PR.', + '', + 'For dependency updates, use the `dependencies` label.' + ].join('\n'); + + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + + const existing = comments.find(c => c.body.includes(marker)); + if (existing) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + body + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body + }); + } + + skipped: + name: Changeset Check (Skipped) + if: ${{ contains(github.event.pull_request.labels.*.name, 'skip-changeset') || contains(github.event.pull_request.labels.*.name, 'dependencies') }} + runs-on: ubuntu-latest + steps: + - run: echo "⏭️ Changeset check skipped via label"