|
1 | 1 | name: Changeset check |
2 | 2 |
|
3 | | -on: workflow_dispatch |
| 3 | +on: pull_request |
4 | 4 |
|
5 | 5 | jobs: |
6 | 6 | changeset-check: |
|
15 | 15 |
|
16 | 16 | - name: Checkout |
17 | 17 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Install pnpm package manager |
| 22 | + uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0 |
18 | 23 |
|
19 | | - - name: List comments |
| 24 | + - name: Install dependencies |
| 25 | + run: pnpm install --frozen-lockfile |
| 26 | + |
| 27 | + - name: Changset status |
| 28 | + id: changeset-status |
| 29 | + run: | |
| 30 | + if pnpm run changeset:status; then |
| 31 | + echo "status=0" | tee -a $GITHUB_OUTPUT |
| 32 | + else |
| 33 | + echo "status=1" | tee -a $GITHUB_OUTPUT |
| 34 | + fi |
| 35 | +
|
| 36 | + - name: Find existing comment |
| 37 | + id: find-existing-comment |
20 | 38 | env: |
21 | 39 | GH_TOKEN: ${{ steps.app-token.outputs.token }} |
22 | 40 | run: | |
| 41 | + COMMENT=$(gh api repos/:owner/:repo/issues/${{ github.event.pull_request.number }}/comments --jq ".[] | select(.user.login == \"${{ steps.app-token.outputs.app-slug }}[bot]\") | .id") |
| 42 | + echo "comment=${COMMENT}" | tee -a $GITHUB_OUTPUT |
23 | 43 |
|
| 44 | + - name: Remove existing comment |
| 45 | + if: ${{ steps.find-existing-comment.outputs.comment != '' && steps.changeset-status.outputs.status == 0 }} |
| 46 | + env: |
| 47 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 48 | + run: gh api --method DELETE repos/:owner/:repo/issues/comments/${{ steps.find-existing-comment.outputs.comment }} |
| 49 | + |
| 50 | + - name: Create new comment |
| 51 | + if: ${{ steps.find-existing-comment.outputs.comment == '' && steps.changeset-status.output.status == 1 }} |
| 52 | + env: |
| 53 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 54 | + run: gh pr comment ${{ github.event.pull_request.number }} --body "New comment" |
| 55 | + |
| 56 | + - name: Update existing comment |
| 57 | + if: ${{ steps.find-existing-comment.outputs.comment != '' && steps.changeset-status.output.status == 1 }} |
| 58 | + env: |
| 59 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 60 | + run: gh pr comment ${{ github.event.pull_request.number }} --edit-last --body "Updated comment" |
0 commit comments