From 04e5ae9d3e60094d54c53e582e23d541bfb9e9f0 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Fri, 19 Dec 2025 11:02:17 +0100 Subject: [PATCH] chore: add coverage regexp --- .gitlab-ci.yml | 2 ++ scripts/print_instruction_coverage.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 scripts/print_instruction_coverage.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9780348f3..29a632c94 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,6 +46,8 @@ test: when: always script: - ./gradlew test jacocoDebugReport -PtestAccountName="$testAccountName" -PtestAccountPwd="$testAccountPwd" -PtestServerUrl="$testServerUrl" + - python3 scripts/print_instruction_coverage.py app/build/reports/jacoco/jacocoDebugReport/jacocoDebugReport.xml + coverage: '/INSTRUCTION_COVERAGE\\s+([0-9]{1,3}\\.?[0-9]*)%/' artifacts: when: always paths: diff --git a/scripts/print_instruction_coverage.py b/scripts/print_instruction_coverage.py new file mode 100644 index 000000000..fbbd6c7d6 --- /dev/null +++ b/scripts/print_instruction_coverage.py @@ -0,0 +1,19 @@ +import sys +import xml.etree.ElementTree as ET + + +def main() -> None: + report_path = sys.argv[1] if len(sys.argv) > 1 else "app/build/reports/jacoco/jacocoDebugReport/jacocoDebugReport.xml" + xml_root = ET.parse(report_path).getroot() + instruction_counter = next( + counter for counter in xml_root.findall("counter") if counter.attrib["type"] == "INSTRUCTION" + ) + missed_count = int(instruction_counter.attrib["missed"]) + covered_count = int(instruction_counter.attrib["covered"]) + total_instructions = covered_count + missed_count + coverage_pct = covered_count / total_instructions * 100 if total_instructions else 0 + print(f"INSTRUCTION_COVERAGE {coverage_pct:.2f}%") + + +if __name__ == "__main__": + main() -- GitLab