-
Notifications
You must be signed in to change notification settings - Fork 8
Add detailed info about coverage #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
allnes
wants to merge
20
commits into
embedded-dev-research:main
Choose a base branch
from
allnes:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e1d6be8
ci: add per-module coverage reporting
allnes be99ef0
ci: switch coverage reporting to quality monitor
allnes 38e90e4
ci: publish only canonical coverage comments
allnes 537401f
ci: publish coverage from aggregated kover report
allnes e35c511
ci: fix aggregated coverage reporting paths
allnes 2999190
ci: publish only aggregated coverage artifact
allnes 60c4fe7
ci: match downloaded aggregated coverage report
allnes d5cf468
ci: use glob pattern for aggregated coverage report
allnes 18ea9a3
ci: add detailed module coverage reporting
allnes c8081d6
ci: fix detailed coverage report paths
allnes 807918f
ci: annotate uncovered coverage in pull requests
allnes 9a0dd57
ci: fix coverage annotation matching
allnes 43f3c56
ci: attach coverage annotations to pr head
allnes 5b998db
ci: override autograding target sha
allnes 9bc0d8e
ci: split coverage annotations by module
allnes 1030c29
ci: set module source paths for coverage annotations
allnes 9d05130
ci: publish uncovered coverage comment
allnes ccbadf6
ci: link uncovered coverage ranges to source
allnes d64f649
ci: render uncovered code snippets in pr comments
allnes 2a44a2f
ci: simplify coverage artifact reporting
allnes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "coverage": [ | ||
| { | ||
| "name": "AI Coverage Annotations", | ||
| "sourcePath": "ai/src/main/java", | ||
| "maxScore": 100, | ||
| "coveredPercentageImpact": 1, | ||
| "missedPercentageImpact": 0, | ||
| "tools": [ | ||
| { | ||
| "id": "jacoco", | ||
| "name": "Line Coverage", | ||
| "metric": "line", | ||
| "sourcePath": "ai/src/main/java", | ||
| "pattern": "**/pr-artifacts/ai/build/reports/kover/report.xml" | ||
| }, | ||
| { | ||
| "id": "jacoco", | ||
| "name": "Branch Coverage", | ||
| "metric": "branch", | ||
| "sourcePath": "ai/src/main/java", | ||
| "pattern": "**/pr-artifacts/ai/build/reports/kover/report.xml" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "coverage": [ | ||
| { | ||
| "name": "App Coverage Annotations", | ||
| "sourcePath": "app/src/main/java", | ||
| "maxScore": 100, | ||
| "coveredPercentageImpact": 1, | ||
| "missedPercentageImpact": 0, | ||
| "tools": [ | ||
| { | ||
| "id": "jacoco", | ||
| "name": "Line Coverage", | ||
| "metric": "line", | ||
| "sourcePath": "app/src/main/java", | ||
| "pattern": "**/pr-artifacts/app/build/reports/kover/report.xml" | ||
| }, | ||
| { | ||
| "id": "jacoco", | ||
| "name": "Branch Coverage", | ||
| "metric": "branch", | ||
| "sourcePath": "app/src/main/java", | ||
| "pattern": "**/pr-artifacts/app/build/reports/kover/report.xml" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "coverage": [ | ||
| { | ||
| "name": "Data Coverage Annotations", | ||
| "sourcePath": "data/src/main/java", | ||
| "maxScore": 100, | ||
| "coveredPercentageImpact": 1, | ||
| "missedPercentageImpact": 0, | ||
| "tools": [ | ||
| { | ||
| "id": "jacoco", | ||
| "name": "Line Coverage", | ||
| "metric": "line", | ||
| "sourcePath": "data/src/main/java", | ||
| "pattern": "**/pr-artifacts/data/build/reports/kover/report.xml" | ||
| }, | ||
| { | ||
| "id": "jacoco", | ||
| "name": "Branch Coverage", | ||
| "metric": "branch", | ||
| "sourcePath": "data/src/main/java", | ||
| "pattern": "**/pr-artifacts/data/build/reports/kover/report.xml" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "coverage": [ | ||
| { | ||
| "name": "Domain Coverage Annotations", | ||
| "sourcePath": "domain/src/main/java", | ||
| "maxScore": 100, | ||
| "coveredPercentageImpact": 1, | ||
| "missedPercentageImpact": 0, | ||
| "tools": [ | ||
| { | ||
| "id": "jacoco", | ||
| "name": "Line Coverage", | ||
| "metric": "line", | ||
| "sourcePath": "domain/src/main/java", | ||
| "pattern": "**/pr-artifacts/domain/build/reports/kover/report.xml" | ||
| }, | ||
| { | ||
| "id": "jacoco", | ||
| "name": "Branch Coverage", | ||
| "metric": "branch", | ||
| "sourcePath": "domain/src/main/java", | ||
| "pattern": "**/pr-artifacts/domain/build/reports/kover/report.xml" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "coverage": [ | ||
| { | ||
| "name": "Line Coverage", | ||
| "tools": [ | ||
| { | ||
| "id": "jacoco", | ||
| "metric": "line", | ||
| "pattern": "**/pr-artifacts/build/reports/kover/report.xml" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "name": "Instruction Coverage", | ||
| "tools": [ | ||
| { | ||
| "id": "jacoco", | ||
| "metric": "instruction", | ||
| "pattern": "**/pr-artifacts/build/reports/kover/report.xml" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| find "${1:-pr-artifacts}" -maxdepth 4 -type f | sort | ||
| find "${1:-pr-artifacts}" -maxdepth 8 -type f | sort |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| #!/usr/bin/env python3 | ||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
| import xml.etree.ElementTree as ET | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| MetricCounts = dict[str, tuple[int, int]] | ||
| METRICS: list[tuple[str, str]] = [ | ||
| ("LINE", "Line"), | ||
| ("INSTRUCTION", "Instruction"), | ||
| ("BRANCH", "Branch"), | ||
| ("METHOD", "Method"), | ||
| ("CLASS", "Class"), | ||
| ] | ||
|
|
||
|
|
||
| def read_counters(report: Path) -> MetricCounts | None: | ||
| try: | ||
| root = ET.parse(report).getroot() | ||
| except ET.ParseError: | ||
| return None | ||
|
|
||
| counters: MetricCounts = {} | ||
| for counter in root.findall("./counter"): | ||
| metric = counter.attrib.get("type") | ||
| if metric is None: | ||
| continue | ||
| counters[metric] = ( | ||
| int(counter.attrib.get("covered", "0")), | ||
| int(counter.attrib.get("missed", "0")), | ||
| ) | ||
|
|
||
| return counters or None | ||
|
|
||
|
|
||
| def format_ratio(covered: int, missed: int) -> str: | ||
| total = covered + missed | ||
| if total == 0: | ||
| return "n/a" | ||
| return f"{covered / total * 100:.2f}%" | ||
|
|
||
|
|
||
| def format_metric_cell(counts: MetricCounts, metric: str) -> str: | ||
| covered, missed = counts.get(metric, (0, 0)) | ||
| total = covered + missed | ||
| if total == 0: | ||
| return "n/a (0/0)" | ||
| return f"{format_ratio(covered, missed)} ({covered}/{total})" | ||
|
|
||
|
|
||
| def render_table_row(cells: list[str]) -> str: | ||
| return f"| {' | '.join(cells)} |" | ||
|
|
||
|
|
||
| def discover_reports(reports_root: Path) -> tuple[MetricCounts | None, list[tuple[str, MetricCounts]]]: | ||
| aggregate_report = reports_root / "build" / "reports" / "kover" / "report.xml" | ||
| if aggregate_report.exists(): | ||
| aggregate_counts = read_counters(aggregate_report) | ||
| module_rows: list[tuple[str, MetricCounts]] = [] | ||
| for report in reports_root.glob("*/build/reports/kover/report.xml"): | ||
| counts = read_counters(report) | ||
| if counts is None: | ||
| continue | ||
| module_rows.append((report.relative_to(reports_root).parts[0], counts)) | ||
| return aggregate_counts, module_rows | ||
|
|
||
| aggregate_counts = None | ||
| module_rows = [] | ||
| fallback_rows = [] | ||
|
|
||
| for report in sorted(reports_root.glob("**/build/reports/kover/report.xml")): | ||
| counts = read_counters(report) | ||
| if counts is None: | ||
| continue | ||
|
|
||
| rel = report.relative_to(reports_root) | ||
| parts = rel.parts | ||
|
|
||
| if parts == ("build", "reports", "kover", "report.xml"): | ||
| aggregate_counts = counts | ||
| elif len(parts) >= 5 and parts[1:5] == ("build", "reports", "kover", "report.xml"): | ||
| module_rows.append((parts[0], counts)) | ||
| else: | ||
| fallback_rows.append((str(rel.parent), counts)) | ||
|
|
||
| return aggregate_counts, module_rows or fallback_rows | ||
|
|
||
|
|
||
| def main() -> int: | ||
| if len(sys.argv) != 3: | ||
| print("usage: build_coverage_summary.py <reports_root> <output_file>", file=sys.stderr) | ||
| return 2 | ||
|
|
||
| reports_root = Path(sys.argv[1]) | ||
| output_file = Path(sys.argv[2]) | ||
|
|
||
| aggregate_counts, rows = discover_reports(reports_root) | ||
|
|
||
| if aggregate_counts is None and rows: | ||
| aggregate_counts = {} | ||
| for metric, _ in METRICS: | ||
| covered = sum(counts.get(metric, (0, 0))[0] for _, counts in rows) | ||
| missed = sum(counts.get(metric, (0, 0))[1] for _, counts in rows) | ||
| aggregate_counts[metric] = (covered, missed) | ||
|
|
||
| lines = [ | ||
| "## Coverage Details", | ||
| "", | ||
| ] | ||
|
|
||
| if aggregate_counts is not None: | ||
| lines.extend( | ||
| [ | ||
| "", | ||
| "### Overall", | ||
| "", | ||
| "| Metric | Coverage | Covered | Missed | Total |", | ||
| "| --- | ---: | ---: | ---: | ---: |", | ||
| ] | ||
| ) | ||
|
|
||
| for metric, label in METRICS: | ||
| covered, missed = aggregate_counts.get(metric, (0, 0)) | ||
| total = covered + missed | ||
| lines.append( | ||
| render_table_row([label, format_ratio(covered, missed), str(covered), str(missed), str(total)]) | ||
| ) | ||
|
|
||
| if rows: | ||
| lines.extend( | ||
| [ | ||
| "", | ||
| "### By Module", | ||
| "", | ||
| "| Module | Line | Instruction | Branch | Method | Class |", | ||
| "| --- | ---: | ---: | ---: | ---: | ---: |", | ||
| ] | ||
| ) | ||
|
|
||
| for module, counts in sorted(rows): | ||
| lines.append( | ||
| render_table_row( | ||
| [ | ||
| f"`{module}`", | ||
| format_metric_cell(counts, "LINE"), | ||
| format_metric_cell(counts, "INSTRUCTION"), | ||
| format_metric_cell(counts, "BRANCH"), | ||
| format_metric_cell(counts, "METHOD"), | ||
| format_metric_cell(counts, "CLASS"), | ||
| ] | ||
| ) | ||
| ) | ||
| elif aggregate_counts is None: | ||
| lines.extend(["", "- No Kover XML reports found"]) | ||
|
|
||
| output_file.write_text("\n".join(lines) + "\n", encoding="utf-8") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.