|
39 | 39 | path: cmk.linux.x86-64.pr${{ github.event.pull_request.number }} |
40 | 40 | if-no-files-found: error |
41 | 41 |
|
| 42 | + - name: Install jq |
| 43 | + run: sudo apt-get update && sudo apt-get install -y jq |
| 44 | + |
42 | 45 | - name: Comment on PR with artifact link |
43 | 46 | if: ${{ github.event_name == 'pull_request' }} |
44 | 47 | env: |
|
47 | 50 | RUN_ID: ${{ github.run_id }} |
48 | 51 | REPO: ${{ github.repository }} |
49 | 52 | 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