|
21 | 21 | pull_request: |
22 | 22 | types: [opened, synchronize, reopened] |
23 | 23 |
|
| 24 | +concurrency: |
| 25 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} |
| 26 | + cancel-in-progress: true |
| 27 | + |
24 | 28 | permissions: |
25 | 29 | contents: read |
26 | 30 | pull-requests: write |
@@ -58,28 +62,51 @@ jobs: |
58 | 62 | run: | |
59 | 63 | echo "expiry_date=$(date -d '+10 days' '+%B %d, %Y')" >> $GITHUB_OUTPUT |
60 | 64 |
|
61 | | - - name: Find existing PR comment |
62 | | - id: find_comment |
63 | | - if: always() |
64 | | - uses: peter-evans/find-comment@v3 |
| 65 | + - name: Comment or update cmk build artifact on PR |
| 66 | + uses: actions/github-script@v7 |
65 | 67 | with: |
66 | | - issue-number: ${{ github.event.pull_request.number }} |
67 | | - comment-author: 'github-actions[bot]' |
68 | | - body-includes: '<!-- cmk-build-artifact-comment -->' |
| 68 | + script: | |
| 69 | + const issue_number = context.payload.pull_request.number; |
| 70 | + const identifier = "cmk-build-artifact-comment"; |
| 71 | + const jobStatus = "${{ job.status }}"; |
| 72 | + const artifactUrl = "${{ steps.upload_artifact.outputs.artifact-url }}"; |
| 73 | + const expiryDate = "${{ steps.expiry_date.outputs.expiry_date }}"; |
| 74 | + const runId = "${{ github.run_id }}"; |
| 75 | + const repo = "${{ github.repository }}"; |
69 | 76 |
|
70 | | - - name: Create/update comment |
71 | | - if: always() |
72 | | - uses: peter-evans/create-or-update-comment@v4 |
73 | | - with: |
74 | | - token: ${{ secrets.GITHUB_TOKEN }} |
75 | | - issue-number: ${{ github.event.pull_request.number }} |
76 | | - comment-id: ${{ steps.find_comment.outputs.comment-id }} |
77 | | - body: | |
78 | | - <!-- cmk-build-artifact-comment --> |
79 | | - ${{ job.status == 'success' && '✅ Build complete' || '❌ Build failed' }} for PR #${{ github.event.pull_request.number }}. |
80 | | -
|
81 | | - ${{ job.status == 'success' |
82 | | - && format('🔗 Download the [cmk binaries]({0}) (expires on {1})', steps.upload_artifact.outputs.artifact-url, steps.expiry_date.outputs.expiry_date) |
83 | | - || format('See the [workflow run](https://github.com/{0}/actions/runs/{1}) for details.', github.repository, github.run_id) }} |
84 | | - edit-mode: replace |
| 77 | + let commentBody = `<!-- ${identifier} -->\n`; |
| 78 | +
|
| 79 | + if (jobStatus === 'success') { |
| 80 | + commentBody += `✅ Build complete for PR #${issue_number}.\n\n`; |
| 81 | + commentBody += `🔗 Download the [cmk binaries](${artifactUrl}) (expires on ${expiryDate})`; |
| 82 | + } else { |
| 83 | + commentBody += `❌ Build failed for PR #${issue_number}.\n\n`; |
| 84 | + commentBody += `See the [workflow run](https://github.com/${repo}/actions/runs/${runId}) for details.`; |
| 85 | + } |
| 86 | +
|
| 87 | + const { data: comments } = await github.rest.issues.listComments({ |
| 88 | + owner: context.repo.owner, |
| 89 | + repo: context.repo.repo, |
| 90 | + issue_number |
| 91 | + }); |
| 92 | +
|
| 93 | + const existing = comments.find(c => |
| 94 | + c.user.login === 'github-actions[bot]' && |
| 95 | + c.body.includes(identifier) |
| 96 | + ); |
85 | 97 |
|
| 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: commentBody |
| 104 | + }); |
| 105 | + } else { |
| 106 | + await github.rest.issues.createComment({ |
| 107 | + owner: context.repo.owner, |
| 108 | + repo: context.repo.repo, |
| 109 | + issue_number, |
| 110 | + body: commentBody |
| 111 | + }); |
| 112 | + } |
0 commit comments