|
1 | 1 | name: Validate pnpm-lock.yaml |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request: |
| 4 | + pull_request_target: |
5 | 5 | paths: |
6 | 6 | - 'pnpm-lock.yaml' |
7 | 7 | - '**/package.json' |
|
15 | 15 | uses: actions/checkout@v4 |
16 | 16 | with: |
17 | 17 | fetch-depth: 0 |
| 18 | + ref: ${{ github.event.pull_request.head.sha }} |
| 19 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
18 | 20 |
|
19 | 21 | - name: Set up Node.js |
20 | 22 | uses: actions/setup-node@v4 |
@@ -55,16 +57,41 @@ jobs: |
55 | 57 | exit 1 |
56 | 58 | fi |
57 | 59 |
|
| 60 | + - name: Find existing lockfile validation comment |
| 61 | + if: always() |
| 62 | + uses: peter-evans/find-comment@v3 |
| 63 | + id: find-comment |
| 64 | + with: |
| 65 | + issue-number: ${{ github.event.pull_request.number }} |
| 66 | + comment-author: 'github-actions[bot]' |
| 67 | + body-includes: 'Lockfile Validation Failed' |
| 68 | + |
58 | 69 | - name: Comment on PR if validation failed |
59 | 70 | if: failure() |
60 | | - uses: peter-evans/create-or-update-comment@v4 |
| 71 | + uses: peter-evans/create-or-update-comment@v5 |
61 | 72 | with: |
62 | 73 | token: ${{ secrets.GITHUB_TOKEN }} |
63 | 74 | issue-number: ${{ github.event.pull_request.number }} |
| 75 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 76 | + edit-mode: replace |
64 | 77 | body: | |
| 78 | + ❌ **Lockfile Validation Failed** |
| 79 | +
|
65 | 80 | The following issue(s) were detected: |
66 | 81 | ${{ steps.validate.outputs.errors }} |
67 | 82 |
|
68 | 83 | Please address these and push an update. |
69 | 84 |
|
70 | 85 | _Posted automatically by GitHub Actions_ |
| 86 | +
|
| 87 | + - name: Delete comment if validation passed |
| 88 | + if: success() && steps.find-comment.outputs.comment-id != '' |
| 89 | + uses: actions/github-script@v7 |
| 90 | + with: |
| 91 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 92 | + script: | |
| 93 | + await github.rest.issues.deleteComment({ |
| 94 | + owner: context.repo.owner, |
| 95 | + repo: context.repo.repo, |
| 96 | + comment_id: ${{ steps.find-comment.outputs.comment-id }}, |
| 97 | + }); |
0 commit comments