Post Coverage Comment #12
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"] | |
| types: [completed] | |
| permissions: | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| post_comment: | |
| name: Post coverage report comment | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.event == 'pull_request' | |
| steps: | |
| - name: Download coverage report artifact | |
| continue-on-error: true | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: coverage-report | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - name: Post PR comment | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| if (!fs.existsSync('report.md') || !fs.existsSync('pr-number.txt')) { | |
| console.log('Coverage report artifact missing (report.md or pr-number.txt not found), skipping comment.'); | |
| return; | |
| } | |
| const body = fs.readFileSync('report.md', 'utf8'); | |
| const prNumber = parseInt(fs.readFileSync('pr-number.txt', 'utf8').trim(), 10); | |
| const marker = '<!-- build-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.includes(marker)); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| body: body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: body, | |
| }); | |
| } |