Add code coverage reporting to CI - #41
Open
plebioda wants to merge 3 commits into
Open
Conversation
Measure test coverage with pytest-cov and surface it on GitHub without any external service. The Test workflow now records coverage and a separate workflow_run workflow posts/updates a coverage comment on pull requests, which keeps write permissions working for fork PRs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Grant the Test job pull-requests: write so the coverage action can post the comment on the same run, and drop the separate workflow_run workflow. This gives immediate feedback on same-repo pull requests. Fork PRs receive a read-only token from GitHub and will not get a comment. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The badge and its linked HTML report are served from the python-coverage-comment-action-data branch, which the coverage action creates on the first push to master. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds Python test coverage measurement to the existing CI pipeline and exposes the results via a repository-hosted badge and PR coverage comments.
Changes:
- Add
pytest-covto the dev dependencies and configurecoverage.py(relative_files = true,source = ["mergai"]) inpyproject.toml. - Update the CI test workflow to run
pytestwith coverage and invokepy-cov-action/python-coverage-comment-action@v3. - Add a coverage badge link to the README.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| README.md | Adds a Coverage badge and link to view coverage output. |
| pyproject.toml | Adds pytest-cov and a [tool.coverage.run] configuration block. |
| .github/workflows/test.yml | Runs pytest with coverage and runs the coverage comment action; adds explicit job permissions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # mergai | ||
|
|
||
| [](https://github.com/Percona-Lab/mergai/actions/workflows/format-check.yml) [](https://github.com/Percona-Lab/mergai/actions/workflows/lint.yml) [](https://github.com/Percona-Lab/mergai/actions/workflows/deps-check.yml) [](https://github.com/Percona-Lab/mergai/actions/workflows/security.yml) | ||
| [](https://github.com/Percona-Lab/mergai/actions/workflows/format-check.yml) [](https://github.com/Percona-Lab/mergai/actions/workflows/lint.yml) [](https://github.com/Percona-Lab/mergai/actions/workflows/deps-check.yml) [](https://github.com/Percona-Lab/mergai/actions/workflows/security.yml) [](https://htmlpreview.github.io/?https://github.com/Percona-Lab/mergai/blob/python-coverage-comment-action-data/htmlcov/index.html) |
Comment on lines
+17
to
+18
| contents: write | ||
| pull-requests: write |
Comment on lines
+13
to
+16
| # contents: write lets the action store coverage data and the badge on | ||
| # its data branch (on push to master). pull-requests: write lets it post | ||
| # the coverage comment on pull requests. Note: fork PRs get a read-only | ||
| # token from GitHub regardless, so they will not receive a comment. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds test coverage measurement to CI and surfaces it on GitHub, with no external reporting service (no Codecov/Coveralls, no coverage data leaving Percona-Lab).
How
pytest-covto thedevextra and a[tool.coverage.run]block (relative_files = trueas required by the reporting action,source = ["mergai"]).pytest --cov=mergai, thenpy-cov-action/python-coverage-comment-action@v3. The job is grantedcontents: write(to store coverage data + badge on the action's data branch when pushing tomaster) andpull-requests: write(to post the coverage comment directly on the same run).Behavior notes
pull_requestruns a read-only token regardless of thepermissionsblock. Fork support would require the separateworkflow_runcommenter pattern, which we intentionally skipped for simplicity.python-coverage-comment-action-databranch, which the action creates on the first push tomaster. The badge renders as broken until this PR merges and that branch exists.Result
🤖 Generated with Claude Code