Skip to content

Commit dbf0490

Browse files
committed
without community action
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 19a3847 commit dbf0490

File tree

1 file changed

+49
-22
lines changed

1 file changed

+49
-22
lines changed

.github/workflows/build-pr-cmk.yml

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ on:
2121
pull_request:
2222
types: [opened, synchronize, reopened]
2323

24+
concurrency:
25+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
26+
cancel-in-progress: true
27+
2428
permissions:
2529
contents: read
2630
pull-requests: write
@@ -58,28 +62,51 @@ jobs:
5862
run: |
5963
echo "expiry_date=$(date -d '+10 days' '+%B %d, %Y')" >> $GITHUB_OUTPUT
6064
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
6567
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 }}";
6976
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+
);
8597
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

Comments
 (0)