|
| 1 | +name: Changeset Check |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, reopened, synchronize, ready_for_review, labeled] |
| 6 | + branches: [master, develop] |
| 7 | + |
| 8 | +jobs: |
| 9 | + verify: |
| 10 | + name: Verify Changeset |
| 11 | + if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-changeset') && !contains(github.event.pull_request.labels.*.name, 'dependencies') }} |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + pull-requests: write |
| 15 | + contents: read |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Setup pnpm |
| 24 | + uses: pnpm/action-setup@v4 |
| 25 | + with: |
| 26 | + version: 10 |
| 27 | + |
| 28 | + - name: Setup Node.js |
| 29 | + uses: actions/setup-node@v4 |
| 30 | + with: |
| 31 | + node-version: '20' |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: pnpm install --frozen-lockfile |
| 35 | + |
| 36 | + - name: Check for changeset |
| 37 | + id: check |
| 38 | + run: | |
| 39 | + if pnpm changeset status --since=origin/${{ github.base_ref }}; then |
| 40 | + echo "has_changeset=true" >> $GITHUB_OUTPUT |
| 41 | + else |
| 42 | + echo "has_changeset=false" >> $GITHUB_OUTPUT |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | +
|
| 46 | + - name: Comment on PR (success) |
| 47 | + if: steps.check.outputs.has_changeset == 'true' |
| 48 | + uses: actions/github-script@v7 |
| 49 | + with: |
| 50 | + script: | |
| 51 | + const marker = '<!-- changeset-check -->'; |
| 52 | + const body = marker + '\n✅ Changeset file detected.'; |
| 53 | +
|
| 54 | + const { data: comments } = await github.rest.issues.listComments({ |
| 55 | + owner: context.repo.owner, |
| 56 | + repo: context.repo.repo, |
| 57 | + issue_number: context.issue.number |
| 58 | + }); |
| 59 | +
|
| 60 | + const existing = comments.find(c => c.body.includes(marker)); |
| 61 | + if (existing) { |
| 62 | + await github.rest.issues.updateComment({ |
| 63 | + owner: context.repo.owner, |
| 64 | + repo: context.repo.repo, |
| 65 | + comment_id: existing.id, |
| 66 | + body |
| 67 | + }); |
| 68 | + } |
| 69 | +
|
| 70 | + - name: Comment on PR (failure) |
| 71 | + if: failure() |
| 72 | + uses: actions/github-script@v7 |
| 73 | + with: |
| 74 | + script: | |
| 75 | + const marker = '<!-- changeset-check -->'; |
| 76 | + const body = [ |
| 77 | + marker, |
| 78 | + '❌ **Missing Changeset**', |
| 79 | + '', |
| 80 | + 'Please add a changeset describing your changes:', |
| 81 | + '```bash', |
| 82 | + 'pnpm changeset', |
| 83 | + '```', |
| 84 | + '', |
| 85 | + 'If your changes do not need a version bump (docs, CI, refactoring),', |
| 86 | + 'add the `skip-changeset` label to this PR.', |
| 87 | + '', |
| 88 | + 'For dependency updates, use the `dependencies` label.' |
| 89 | + ].join('\n'); |
| 90 | +
|
| 91 | + const { data: comments } = await github.rest.issues.listComments({ |
| 92 | + owner: context.repo.owner, |
| 93 | + repo: context.repo.repo, |
| 94 | + issue_number: context.issue.number |
| 95 | + }); |
| 96 | +
|
| 97 | + const existing = comments.find(c => c.body.includes(marker)); |
| 98 | + if (existing) { |
| 99 | + await github.rest.issues.updateComment({ |
| 100 | + owner: context.repo.owner, |
| 101 | + repo: context.repo.repo, |
| 102 | + comment_id: existing.id, |
| 103 | + body |
| 104 | + }); |
| 105 | + } else { |
| 106 | + await github.rest.issues.createComment({ |
| 107 | + owner: context.repo.owner, |
| 108 | + repo: context.repo.repo, |
| 109 | + issue_number: context.issue.number, |
| 110 | + body |
| 111 | + }); |
| 112 | + } |
| 113 | +
|
| 114 | + skipped: |
| 115 | + name: Changeset Check (Skipped) |
| 116 | + if: ${{ contains(github.event.pull_request.labels.*.name, 'skip-changeset') || contains(github.event.pull_request.labels.*.name, 'dependencies') }} |
| 117 | + runs-on: ubuntu-latest |
| 118 | + steps: |
| 119 | + - run: echo "⏭️ Changeset check skipped via label" |
0 commit comments