Post Coverage Comment #2472
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Post Coverage Comment | |
| on: | |
| workflow_run: | |
| workflows: ["Build and Deploy Snapshot"] | |
| types: [completed] | |
| permissions: | |
| pull-requests: write | |
| jobs: | |
| comment: | |
| runs-on: ubuntu-24.04 | |
| if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' | |
| steps: | |
| - name: Download comment artifact | |
| uses: dawidd6/action-download-artifact@b6e2e70617bc3265edd6dab6c906732b2f1ae151 # v21 | |
| with: | |
| name: pr-comment | |
| path: pr-comment/ | |
| run_id: ${{ github.event.workflow_run.id }} | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| # 2.x branch builds do not produce this artifact; skip instead of failing | |
| if_no_artifact_found: warn | |
| - name: Post coverage comment | |
| if: ${{ hashFiles('pr-comment/pr-number.txt') != '' }} | |
| run: | | |
| PR_NUMBER=$(cat pr-comment/pr-number.txt) | |
| COMMENT_BODY=$(cat pr-comment/comment-body.txt) | |
| # Find and delete existing comment | |
| COMMENT_ID=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json comments \ | |
| --jq '.comments[] | select(.body | contains("<!-- jacoco-coverage-comment -->")) | .id' | head -1) | |
| if [ -n "$COMMENT_ID" ]; then | |
| gh api -X DELETE "repos/${{ github.repository }}/issues/comments/$COMMENT_ID" || true | |
| fi | |
| # Post new comment | |
| gh pr comment $PR_NUMBER --repo ${{ github.repository }} --body "$COMMENT_BODY" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |