diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9780348f363f38c180d4b5acc8d3252f1c889dde..29a632c949f3753b0ea1f7c6ef31c5a9dfbb9307 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 0000000000000000000000000000000000000000..fbbd6c7d61b145c3ec46b3d8d69920a4cc97e207 --- /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()