Post Coverage Comment #61
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: | |
| post-comment: | |
| runs-on: ubuntu-24.04 | |
| if: > | |
| github.event.workflow_run.event == 'pull_request' && | |
| github.event.workflow_run.conclusion == 'success' | |
| steps: | |
| - name: Download PR comment artifact | |
| uses: dawidd6/action-download-artifact@v16 | |
| with: | |
| workflow: main.yml | |
| run_id: ${{ github.event.workflow_run.id }} | |
| name: pr-coverage-comment | |
| path: pr-coverage-comment/ | |
| - name: Post or update PR comment | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const prNumber = parseInt( | |
| fs.readFileSync('pr-coverage-comment/pr-number.txt', 'utf8').trim() | |
| ); | |
| const commentBody = fs.readFileSync( | |
| 'pr-coverage-comment/comment-body.txt', 'utf8' | |
| ).trim(); | |
| const marker = '## :test_tube: Code Coverage Report'; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| const existing = comments.find(c => c.body.startsWith(marker)); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| body: commentBody, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: commentBody, | |
| }); | |
| } |