Skip to content

Commit 3d2dae7

Browse files
authored
Update build-pr-cmk.yml
1 parent 50f175f commit 3d2dae7

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
path: cmk.linux.x86-64.pr${{ github.event.pull_request.number }}
4040
if-no-files-found: error
4141

42+
- name: Install jq
43+
run: sudo apt-get update && sudo apt-get install -y jq
44+
4245
- name: Comment on PR with artifact link
4346
if: ${{ github.event_name == 'pull_request' }}
4447
env:
@@ -47,9 +50,27 @@ jobs:
4750
RUN_ID: ${{ github.run_id }}
4851
REPO: ${{ github.repository }}
4952
run: |
50-
COMMENT="✅ Build complete for PR #${PR_NUMBER}%0A🔗 [Download the cmk binary](https://github.com/${REPO}/actions/runs/${RUN_ID})"
51-
curl -s -X POST \
52-
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
53-
-H "Content-Type: application/json" \
54-
-d "{\"body\": \"${COMMENT}\"}" \
55-
"https://api.github.com/repos/${REPO}/issues/${PR_NUMBER}/comments"
53+
COMMENT_BODY="<!-- cmk-build-artifact -->
54+
✅ Build complete for PR #${PR_NUMBER}
55+
🔗 [Download the cmk binary](https://github.com/${REPO}/actions/runs/${RUN_ID})"
56+
57+
# Find existing comment ID (if any)
58+
comment_id=$(curl -s -H "Authorization: Bearer ${GITHUB_TOKEN}" \
59+
"https://api.github.com/repos/${REPO}/issues/${PR_NUMBER}/comments" |
60+
jq '.[] | select(.user.login == "github-actions[bot]") | select(.body | contains("<!-- cmk-build-artifact -->")) | .id')
61+
62+
if [ -n "$comment_id" ]; then
63+
echo "📝 Updating existing comment $comment_id"
64+
curl -s -X PATCH \
65+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
66+
-H "Content-Type: application/json" \
67+
-d "$(jq -n --arg body "$COMMENT_BODY" '{body: $body}')" \
68+
"https://api.github.com/repos/${REPO}/issues/comments/${comment_id}"
69+
else
70+
echo "💬 Creating new comment"
71+
curl -s -X POST \
72+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
73+
-H "Content-Type: application/json" \
74+
-d "$(jq -n --arg body "$COMMENT_BODY" '{body: $body}')" \
75+
"https://api.github.com/repos/${REPO}/issues/${PR_NUMBER}/comments"
76+
fi

0 commit comments

Comments
 (0)