Repository navigation
feat: Add code coverage delta to PR's - #927
MaximilianSoerenPollak wants to merge 12 commits into
Conversation
WIP: Add code coverage to DaC
Signed-off-by: Maximilian Sören Pollak <maximilian.pollak@qorix.com>
Signed-off-by: Maximilian Sören Pollak <maximilian.pollak@qorix.com>
| REPO: ${{ github.repository }} | ||
| HEAD_SHA: ${{ github.event.workflow_run.head_sha }} | ||
| run: | | ||
| pr=$(cat coverage-report/pr_number) |
There was a problem hiding this comment.
this should not rely on what a PR has said what it is. See docs-publish workflow
There was a problem hiding this comment.
Okay that is a good catch.
Will address that once I take a look at trying to fix the code.
There was a problem hiding this comment.
🟡 Changes recommended
Missing-artifact handling can prevent reports, and malformed reference data can still crash rendering.
2 open findings
What changed in this PR
Adds merged Python coverage reporting and PR comments, including deltas against main.
Changes:
- Adds LCOV merging, summaries, comparison logic, and tests.
- Instruments Bazel and docs scenarios for coverage.
- Adds workflows to collect, publish, and comment coverage results.
| File | Description |
|---|---|
.github/workflows/_test.yml |
Collects and merges coverage artifacts. |
.github/workflows/coverage_comment.yml |
Posts coverage summaries on PRs. |
.gitignore |
Ignores generated coverage output. |
bzl/needs_rules.bzl |
Forwards coverage settings to Sphinx actions. |
pyproject.toml |
Configures coverage.py. |
src/docs_cli/BUILD |
Defines coverage build settings. |
src/docs_cli/cli.py |
Starts coverage before application imports. |
src/requirements.in |
Adds coverage.py dependency. |
src/requirements.txt |
Locks coverage.py for Python 3.12. |
src/requirements_py314.txt |
Locks coverage.py for Python 3.14. |
src/tests/docs_bzl/README.md |
Documents scenario coverage usage. |
src/tests/docs_bzl/helpers.py |
Propagates coverage configuration through Bazel. |
tools/BUILD |
Defines the coverage-report binary. |
tools/coverage_report.py |
Implements merging, comparison, and Markdown output. |
tools/tests/BUILD |
Registers coverage-report tests. |
tools/tests/coverage_report_test.py |
Tests coverage processing and reporting. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| run: >- | ||
| bazel run --lockfile_mode=error //tools:coverage_report -- | ||
| "Unit tests=coverage-data/unit_tests/unit_tests.lcov" | ||
| "docs.bzl scenarios=coverage-data/docs_bzl" | ||
| --output coverage-data/coverage.lcov | ||
| --markdown coverage-data/summary.md | ||
| --json coverage-data/coverage.json | ||
| ${{ github.event_name == 'pull_request' && '--compare-with coverage-data/main/coverage.json' || '' }} |
| lines_hit, lines_total = data["lines"] | ||
| branches_hit, branches_total = data["branches"] | ||
| return cls(lines_hit, lines_total, branches_hit, branches_total) |
There was a problem hiding this comment.
Can this actually ever occur?
I guess adding some defenses here is not a bad idea.
I will add this.
|
Documentation preview for this pull request is available at: |
| "_coverage_file": attr.label(default = Label("//src/docs_cli:coverage_file")), | ||
| "_coverage_process_start": attr.label( | ||
| default = Label("//src/docs_cli:coverage_process_start"), | ||
| ), |
There was a problem hiding this comment.
use internal_target for these?
There was a problem hiding this comment.
You mean the __internal__ prefix?
| # An absolute path in the checkout is readable from every sandbox and | ||
| # runfiles tree the Sphinx runs start in. |
There was a problem hiding this comment.
not with remote execution
There was a problem hiding this comment.
That is true, but I think once we have remote execution a lot of things will fail.
Though I will adapt the comments
| """Run Bazel, optionally overriding the environment of the subprocess.""" | ||
| start_time = time.time() | ||
| cmd = ["bazel", *args] | ||
| coverage_env = _coverage_env() |
There was a problem hiding this comment.
not sure, but something like: env |= _coverage_env()
There was a problem hiding this comment.
Oh, you mean env = _coverage_env() | env?
Though this would then not add them but instead choose one or the other which is not quiet what we want.
Hmm but I think I kind of get what you mean, let me see if I can integrate this.
|
|
||
| # Measure what the docs.bzl scenario tests exercise inside Sphinx, and merge | ||
| # coverage reports in //tools:coverage_report. | ||
| coverage |
There was a problem hiding this comment.
latest after this PR we need to discuss splitting requirements.in for internal and public usage
There was a problem hiding this comment.
I think we for sure need to do this.
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
| """Merge Python coverage reports and add every tracked file no test imports. |
There was a problem hiding this comment.
extract to tools? actually this is exact same thing as coverage_tool does... but generalizing coverage_tool is 10x effort.
There was a problem hiding this comment.
Yes, I saw that tools has a similar script-ish already, and I think it might makes sense in the future to bring them together.
But I think for that coverage_tool needs to get into a better state first so we can see if maybe that script can be generalized and used here.
MaximilianSoerenPollak
left a comment
There was a problem hiding this comment.
Questions answered, and new ones raised.
| @@ -0,0 +1,980 @@ | |||
| # ******************************************************************************* | |||
There was a problem hiding this comment.
This file is quiet large due to the execesive comments that explain inputs & outputs as well as other things.
I'm unsure if this is good or bad.
| "_coverage_file": attr.label(default = Label("//src/docs_cli:coverage_file")), | ||
| "_coverage_process_start": attr.label( | ||
| default = Label("//src/docs_cli:coverage_process_start"), | ||
| ), |
There was a problem hiding this comment.
You mean the __internal__ prefix?
| # An absolute path in the checkout is readable from every sandbox and | ||
| # runfiles tree the Sphinx runs start in. |
There was a problem hiding this comment.
That is true, but I think once we have remote execution a lot of things will fail.
Though I will adapt the comments
| """Run Bazel, optionally overriding the environment of the subprocess.""" | ||
| start_time = time.time() | ||
| cmd = ["bazel", *args] | ||
| coverage_env = _coverage_env() |
There was a problem hiding this comment.
Oh, you mean env = _coverage_env() | env?
Though this would then not add them but instead choose one or the other which is not quiet what we want.
Hmm but I think I kind of get what you mean, let me see if I can integrate this.
|
|
||
| # Measure what the docs.bzl scenario tests exercise inside Sphinx, and merge | ||
| # coverage reports in //tools:coverage_report. | ||
| coverage |
There was a problem hiding this comment.
I think we for sure need to do this.
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
| """Merge Python coverage reports and add every tracked file no test imports. |
There was a problem hiding this comment.
Yes, I saw that tools has a similar script-ish already, and I think it might makes sense in the future to bring them together.
But I think for that coverage_tool needs to get into a better state first so we can see if maybe that script can be generalized and used here.
| lines_hit, lines_total = data["lines"] | ||
| branches_hit, branches_total = data["branches"] | ||
| return cls(lines_hit, lines_total, branches_hit, branches_total) |
There was a problem hiding this comment.
Can this actually ever occur?
I guess adding some defenses here is not a bad idea.
I will add this.
- Make new targets internal - Add more defensive measures

📌 Description
This brings in the ability to measure complete code coverage in DaC and display the code coverage as a comment in the PR's themselves.
WIP:
Currently this is how they look like:

Can be seen here
🚨 Impact Analysis
✅ Checklist