From d9320dd5b7310733f4f7c13dd96902e235f1faf1 Mon Sep 17 00:00:00 2001 From: codex Date: Mon, 20 Apr 2026 21:53:45 -0300 Subject: [PATCH] ci(metis): publish testcase and docs gate metrics --- scripts/publish_test_metrics.py | 41 +++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/scripts/publish_test_metrics.py b/scripts/publish_test_metrics.py index 04b9688..b0f34ea 100644 --- a/scripts/publish_test_metrics.py +++ b/scripts/publish_test_metrics.py @@ -58,6 +58,35 @@ def _load_junit(path: str) -> dict[str, int]: return totals +def _load_junit_cases(path: str) -> list[tuple[str, str]]: + tree = ET.parse(path) + root = tree.getroot() + 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_exit_code(path: str) -> int | None: if not path or not os.path.exists(path): return None @@ -75,7 +104,7 @@ def _post_text(url: str, payload: str) -> None: req = urllib.request.Request( url, data=payload.encode("utf-8"), - method="POST", + method="PUT", headers={"Content-Type": "text/plain"}, ) with urllib.request.urlopen(req, timeout=10) as resp: @@ -172,6 +201,7 @@ def main() -> int: coverage_path = os.getenv("COVERAGE_JSON", "build/coverage.json") junit_path = os.getenv("JUNIT_XML", "build/junit.xml") test_exit_code_path = os.getenv("TEST_EXIT_CODE_PATH", "build/test.exitcode") + docs_exit_code_path = os.getenv("DOCS_EXIT_CODE_PATH", "build/docs-naming.rc") pushgateway_url = os.getenv( "PUSHGATEWAY_URL", "http://platform-quality-gateway.monitoring.svc.cluster.local:9091" ).strip() @@ -190,7 +220,9 @@ def main() -> int: coverage = _load_coverage(coverage_path) totals = _load_junit(junit_path) + test_cases = _load_junit_cases(junit_path) test_exit_code = _load_exit_code(test_exit_code_path) + docs_exit_code = _load_exit_code(docs_exit_code_path) source_lines_over_500 = _count_source_files_over_limit(repo_root, max_lines=500) passed = max(totals["tests"] - totals["failures"] - totals["errors"] - totals["skipped"], 0) @@ -206,7 +238,7 @@ def main() -> int: "tests": "ok" if outcome == "ok" else "failed", "coverage": "ok" if coverage >= 95.0 else "failed", "loc": "ok" if source_lines_over_500 == 0 else "failed", - "docs_naming": "not_applicable", + "docs_naming": "ok" if docs_exit_code == 0 else "failed", "gate_glue": "ok", "sonarqube": _sonarqube_check_status(build_dir), "supply_chain": _supply_chain_check_status(build_dir), @@ -253,9 +285,14 @@ 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 metis_quality_gate_checks_total gauge", + "# TYPE platform_quality_gate_test_case_result gauge", "# TYPE metis_quality_gate_build_info gauge", f"metis_quality_gate_build_info{_label_str(labels)} 1", ] + payload_lines.extend( + 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 + ) payload_lines.extend( f'metis_quality_gate_checks_total{{suite="{suite}",check="{check_name}",result="{check_status}"}} 1' for check_name, check_status in checks.items()