From f4801537ec960fc1a8f05c2cc9469a07ee7b01fe Mon Sep 17 00:00:00 2001 From: codex Date: Mon, 11 May 2026 17:39:56 -0300 Subject: [PATCH] ci: publish LOC source file totals --- scripts/publish_test_metrics.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/scripts/publish_test_metrics.py b/scripts/publish_test_metrics.py index 0acc413..6b1c52b 100644 --- a/scripts/publish_test_metrics.py +++ b/scripts/publish_test_metrics.py @@ -152,10 +152,7 @@ def _series_exists(pushgateway_url: str, metric: str, labels: dict[str, str]) -> return False -def _count_source_files_over_limit(repo_root: Path, max_lines: int = 500) -> int: - """Count source files above the configured line budget.""" - - count = 0 +def _iter_source_files(repo_root: Path): for rel_root in ("cmd", "pkg", "scripts", "testing"): base = repo_root / rel_root if not base.exists(): @@ -165,9 +162,23 @@ def _count_source_files_over_limit(repo_root: Path, max_lines: int = 500) -> int continue if path.suffix not in {".go", ".py", ".sh"}: continue - lines = len(path.read_text(encoding="utf-8", errors="ignore").splitlines()) - if lines > max_lines: - count += 1 + yield path + + +def _count_source_files(repo_root: Path) -> int: + """Count source files covered by the line budget.""" + + return sum(1 for _ in _iter_source_files(repo_root)) + + +def _count_source_files_over_limit(repo_root: Path, max_lines: int = 500) -> int: + """Count source files above the configured line budget.""" + + count = 0 + for path in _iter_source_files(repo_root): + lines = len(path.read_text(encoding="utf-8", errors="ignore").splitlines()) + if lines > max_lines: + count += 1 return count @@ -240,6 +251,7 @@ def main() -> int: 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_files_total = _count_source_files(repo_root) 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) @@ -320,6 +332,8 @@ def main() -> int: f'metis_quality_gate_coverage_percent{{suite="{suite}"}} {coverage:.3f}', "# TYPE platform_quality_gate_workspace_line_coverage_percent gauge", f'platform_quality_gate_workspace_line_coverage_percent{{suite="{suite}"}} {coverage:.3f}', + "# TYPE platform_quality_gate_source_files_total gauge", + f'platform_quality_gate_source_files_total{{suite="{suite}"}} {source_files_total}', "# 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 platform_quality_gate_build_info gauge",