Post Coverage Comment #273
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 | |
| id: download | |
| 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 PR builds don't produce this artifact (coverage comment steps | |
| # only exist on 3.x), so don't fail when it's absent -- just skip. | |
| if_no_artifact_found: warn | |
| - name: Post coverage comment | |
| if: ${{ steps.download.outputs.found_artifact == 'true' }} | |
| run: | | |
| PR_NUMBER=$(cat pr-comment/pr-number.txt) | |
| COMMENT_BODY=$(cat pr-comment/comment-body.txt) | |
| 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 | |
| gh pr comment $PR_NUMBER --repo ${{ github.repository }} --body "$COMMENT_BODY" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |