Proposal: Automated PR Test Coverage Comments
Context
Reviewers currently have to check the CI/CD command output to verify test coverage for new code in PRs. Automatically posting coverage summaries will make it easier to understand the quality of contributions and improve code confidence without manual checks.
Motivation
- Faster review: Reviewers can immediately see test coverage impact for a PR without digging into artifacts or logs.
- Better insight: Ensures test gaps are visible during code review, helping prevent untested changes being merged by accident.
- Non-intrusive: No required coverage threshold by default; focus on reporting, not enforcing. Could allow teams to configure thresholds if desired.
- Performance: Should not meaningfully slow down CI, as code coverage is typically already measured.
Scope & Implementation
- Start with posting a summary for total repository coverage.
- Ideally, progress toward showing coverage only for changed files in each PR.
- Implementation can leverage uploading
coverage.out with actions/upload-artifact and then a bot/script posting a PR comment with a summary (see below for an example outline).
- Make it generic so other repositories using mage can follow the same approach.
Example workflow steps
- name: Upload coverage artifact
if: ${{ github.event_name == 'pull_request' && hashFiles('coverage.out') != '' }}
uses: actions/upload-artifact@v4
with:
name: go-coverage
path: coverage.out
- name: Comment PR with coverage
if: ${{ github.event_name == 'pull_request' && hashFiles('coverage.out') != '' }}
uses: actions/github-script@v7
with:
script: |
const { execSync } = require('child_process');
const summary = execSync('go tool cover -func=coverage.out', { encoding: 'utf8' });
const body =
'## Go coverage\n\n' +
'```text\n' + summary + '\n```\n' +
'<!-- go-coverage-comment -->';
const issue_number = context.payload.pull_request.number;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
});
const existing = comments.find(c =>
c.body.includes('<!-- go-coverage-comment -->')
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
body,
});
}
Open for discussion on best practices or ideas for improving how coverage is measured and reported within mage-based Go projects.
Proposal: Automated PR Test Coverage Comments
Context
Reviewers currently have to check the CI/CD command output to verify test coverage for new code in PRs. Automatically posting coverage summaries will make it easier to understand the quality of contributions and improve code confidence without manual checks.
Motivation
Scope & Implementation
coverage.outwith actions/upload-artifact and then a bot/script posting a PR comment with a summary (see below for an example outline).Example workflow steps
Open for discussion on best practices or ideas for improving how coverage is measured and reported within mage-based Go projects.