|
64 | 64 | name: coverage-report |
65 | 65 | path: coverage/ |
66 | 66 | retention-days: 30 |
| 67 | + - name: Comment Coverage on PR |
| 68 | + if: github.event_name == 'pull_request' && always() |
| 69 | + uses: actions/github-script@v7 |
| 70 | + with: |
| 71 | + script: | |
| 72 | + const fs = require('fs'); |
| 73 | +
|
| 74 | + if (!fs.existsSync('coverage/.last_run.json')) { |
| 75 | + console.log('Coverage report not found'); |
| 76 | + return; |
| 77 | + } |
| 78 | +
|
| 79 | + const coverage = JSON.parse(fs.readFileSync('coverage/.last_run.json', 'utf8')); |
| 80 | + const coveragePercent = coverage.result.line; |
| 81 | + const threshold = 50; |
| 82 | + const meetsThreshold = coveragePercent >= threshold; |
| 83 | + const emoji = meetsThreshold ? '✅' : '⚠️'; |
| 84 | +
|
| 85 | + const comment = `## ${emoji} Code Coverage Report |
| 86 | +
|
| 87 | + **Coverage:** ${coveragePercent}% |
| 88 | + **Threshold:** ${threshold}% |
| 89 | +
|
| 90 | + ${emoji} Coverage ${meetsThreshold ? 'meets' : 'is below'} minimum threshold |
| 91 | +
|
| 92 | + <sub>📊 [View detailed coverage report in artifacts](${context.payload.repository.html_url}/actions/runs/${context.runId})</sub>`; |
| 93 | +
|
| 94 | + // Find existing coverage comment |
| 95 | + const { data: comments } = await github.rest.issues.listComments({ |
| 96 | + owner: context.repo.owner, |
| 97 | + repo: context.repo.repo, |
| 98 | + issue_number: context.issue.number, |
| 99 | + }); |
| 100 | +
|
| 101 | + const botComment = comments.find(comment => |
| 102 | + comment.user.type === 'Bot' && |
| 103 | + comment.body.includes('Code Coverage Report') |
| 104 | + ); |
| 105 | +
|
| 106 | + if (botComment) { |
| 107 | + // Update existing comment |
| 108 | + await github.rest.issues.updateComment({ |
| 109 | + owner: context.repo.owner, |
| 110 | + repo: context.repo.repo, |
| 111 | + comment_id: botComment.id, |
| 112 | + body: comment |
| 113 | + }); |
| 114 | + } else { |
| 115 | + // Create new comment |
| 116 | + await github.rest.issues.createComment({ |
| 117 | + owner: context.repo.owner, |
| 118 | + repo: context.repo.repo, |
| 119 | + issue_number: context.issue.number, |
| 120 | + body: comment |
| 121 | + }); |
| 122 | + } |
67 | 123 |
|
68 | 124 | linter: |
69 | 125 | name: Linter |
|
0 commit comments