diff --git a/scripts/publish_test_metrics.py b/scripts/publish_test_metrics.py index 7f2b979..50f953f 100755 --- a/scripts/publish_test_metrics.py +++ b/scripts/publish_test_metrics.py @@ -54,6 +54,39 @@ def _load_junit(path: Path) -> dict[str, int]: return totals +def _load_junit_cases(path: Path) -> list[tuple[str, str]]: + if not path.exists(): + return [] + + tree = ET.parse(path) + root = tree.getroot() + suites: list[ET.Element] + if root.tag == "testsuite": + suites = [root] + elif root.tag == "testsuites": + suites = list(root.findall("testsuite")) + else: + suites = [] + + cases: list[tuple[str, str]] = [] + for suite in suites: + for case in suite.findall("testcase"): + name = (case.attrib.get("name") or "").strip() + classname = (case.attrib.get("classname") or "").strip() + if not name: + continue + test_id = f"{classname}::{name}" if classname else name + status = "passed" + if case.find("failure") is not None: + status = "failed" + elif case.find("error") is not None: + status = "error" + elif case.find("skipped") is not None: + status = "skipped" + cases.append((test_id, status)) + return cases + + def _load_coverage_percent(path: Path) -> float: if not path.exists(): return 0.0 @@ -183,6 +216,7 @@ def main() -> int: build_dir = Path(os.getenv("BUILD_DIR", "build")) totals = _load_junit(junit_path) + test_cases = _load_junit_cases(junit_path) coverage_pct = _load_coverage_percent(coverage_path) gate_rc = _load_gate_rc(gate_rc_path) docs_rc = _load_gate_rc(docs_rc_path) @@ -226,8 +260,13 @@ def main() -> int: "# TYPE platform_quality_gate_source_lines_over_500_total gauge", f'platform_quality_gate_source_lines_over_500_total{{suite="{suite}"}} {source_lines_over_500}', "# TYPE atlasbot_quality_gate_checks_total gauge", + "# TYPE platform_quality_gate_test_case_result gauge", ] ) + "\n" + payload += "\n".join( + f'platform_quality_gate_test_case_result{{suite="{suite}",test="{_escape_label(test_name)}",status="{_escape_label(test_status)}"}} 1' + for test_name, test_status in test_cases + ) + "\n" payload += "\n".join( f'atlasbot_quality_gate_checks_total{{suite="{suite}",check="{check_name}",result="{check_status}"}} 1' for check_name, check_status in checks.items()