|
| 1 | +name: Changeset check |
| 2 | + |
| 3 | +on: pull_request |
| 4 | + |
| 5 | +jobs: |
| 6 | + changeset-check: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + steps: |
| 9 | + - name: Create GitHub App Token |
| 10 | + id: app-token |
| 11 | + uses: actions/create-github-app-token@21cfef2b496dd8ef5b904c159339626a10ad380e # 1.11.6 |
| 12 | + with: |
| 13 | + app-id: ${{ vars.NL_DESIGN_SYSTEM_BOT_APP_ID }} |
| 14 | + private-key: ${{ secrets.NL_DESIGN_SYSTEM_BOT_PRIVATE_KEY }} |
| 15 | + |
| 16 | + - name: Checkout |
| 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 |
| 23 | + |
| 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 |
| 38 | + env: |
| 39 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 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 |
| 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: | |
| 49 | + gh api --method DELETE repos/:owner/:repo/issues/comments/${{ steps.find-existing-comment.outputs.comment }} |
| 50 | + exit 0 |
| 51 | +
|
| 52 | + - name: Create new comment |
| 53 | + if: ${{ steps.find-existing-comment.outputs.comment == '' && steps.changeset-status.outputs.status == 1 }} |
| 54 | + env: |
| 55 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 56 | + run: | |
| 57 | + gh pr comment ${{ github.event.pull_request.number }} --body ":warning: Deze pull request mist een changeset terwijl er wel een nodig is :warning:" |
| 58 | + exit 1 |
| 59 | +
|
| 60 | + - name: Update existing comment |
| 61 | + if: ${{ steps.find-existing-comment.outputs.comment != '' && steps.changeset-status.outputs.status == 1 }} |
| 62 | + env: |
| 63 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 64 | + run: | |
| 65 | + gh pr comment ${{ github.event.pull_request.number }} --edit-last --body ":warning: Deze pull request mist nog steeds een changeset terwijl er wel een nodig is. :warning:" |
| 66 | + exit 1 |
0 commit comments