Skip to content

Add code coverage reporting to CI - #41

Open
plebioda wants to merge 3 commits into
masterfrom
coverage-reporting
Open

Add code coverage reporting to CI#41
plebioda wants to merge 3 commits into
masterfrom
coverage-reporting

Conversation

@plebioda

@plebioda plebioda commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

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

  • pyproject.toml - add pytest-cov to the dev extra and a [tool.coverage.run] block (relative_files = true as required by the reporting action, source = ["mergai"]).
  • .github/workflows/test.yml - run pytest --cov=mergai, then py-cov-action/python-coverage-comment-action@v3. The job is granted contents: write (to store coverage data + badge on the action's data branch when pushing to master) and pull-requests: write (to post the coverage comment directly on the same run).
  • README.md - add a Coverage badge to the badge row.

Behavior notes

  • Single-workflow design: the coverage comment is posted directly from the Test job. This gives immediate feedback on same-repo pull requests.
  • Fork PRs will not receive a comment - GitHub hands fork pull_request runs a read-only token regardless of the permissions block. Fork support would require the separate workflow_run commenter pattern, which we intentionally skipped for simplicity.
  • The badge and its linked HTML report are served from the python-coverage-comment-action-data branch, which the action creates on the first push to master. The badge renders as broken until this PR merges and that branch exists.

Result

  • Coverage comment on every same-repo PR (total + per-file diff coverage).
  • Verified live on this PR: ~34% total coverage, 261 tests passing.

🤖 Generated with Claude Code

plebioda and others added 2 commits August 3, 2026 21:57
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>
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Coverage report

This PR does not seem to contain any modification to coverable code.

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-cov to the dev dependencies and configure coverage.py (relative_files = true, source = ["mergai"]) in pyproject.toml.
  • Update the CI test workflow to run pytest with coverage and invoke py-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.

Comment thread README.md
# mergai

[![Format Check](https://github.com/Percona-Lab/mergai/actions/workflows/format-check.yml/badge.svg)](https://github.com/Percona-Lab/mergai/actions/workflows/format-check.yml) [![Lint](https://github.com/Percona-Lab/mergai/actions/workflows/lint.yml/badge.svg)](https://github.com/Percona-Lab/mergai/actions/workflows/lint.yml) [![Dependency Check](https://github.com/Percona-Lab/mergai/actions/workflows/deps-check.yml/badge.svg)](https://github.com/Percona-Lab/mergai/actions/workflows/deps-check.yml) [![Security Scan](https://github.com/Percona-Lab/mergai/actions/workflows/security.yml/badge.svg)](https://github.com/Percona-Lab/mergai/actions/workflows/security.yml)
[![Format Check](https://github.com/Percona-Lab/mergai/actions/workflows/format-check.yml/badge.svg)](https://github.com/Percona-Lab/mergai/actions/workflows/format-check.yml) [![Lint](https://github.com/Percona-Lab/mergai/actions/workflows/lint.yml/badge.svg)](https://github.com/Percona-Lab/mergai/actions/workflows/lint.yml) [![Dependency Check](https://github.com/Percona-Lab/mergai/actions/workflows/deps-check.yml/badge.svg)](https://github.com/Percona-Lab/mergai/actions/workflows/deps-check.yml) [![Security Scan](https://github.com/Percona-Lab/mergai/actions/workflows/security.yml/badge.svg)](https://github.com/Percona-Lab/mergai/actions/workflows/security.yml) [![Coverage](https://raw.githubusercontent.com/Percona-Lab/mergai/python-coverage-comment-action-data/badge.svg)](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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants