ci(atlasbot): publish canonical build info

This commit is contained in:
jenkins 2026-04-21 09:34:51 -03:00
parent 603d2dcec5
commit 3ba75ee234

View File

@ -28,6 +28,12 @@ def _escape_label(value: str) -> str:
return value.replace("\\", "\\\\").replace("\n", "\\n").replace('"', '\\"') return value.replace("\\", "\\\\").replace("\n", "\\n").replace('"', '\\"')
def _label_str(labels: dict[str, str]) -> str:
"""Render Prometheus labels, omitting empty optional values."""
parts = [f'{key}="{_escape_label(val)}"' for key, val in labels.items() if val]
return "{" + ",".join(parts) + "}" if parts else ""
def _as_int(node: ET.Element, name: str) -> int: def _as_int(node: ET.Element, name: str) -> int:
raw = node.attrib.get(name) or "0" raw = node.attrib.get(name) or "0"
try: try:
@ -219,6 +225,8 @@ def main() -> int:
docs_rc_path = Path(os.getenv("QUALITY_GATE_DOCS_RC_PATH", "build/docs-naming.rc")) docs_rc_path = Path(os.getenv("QUALITY_GATE_DOCS_RC_PATH", "build/docs-naming.rc"))
source_root = Path(os.getenv("SOURCE_ROOT", "atlasbot")) source_root = Path(os.getenv("SOURCE_ROOT", "atlasbot"))
build_dir = Path(os.getenv("BUILD_DIR", "build")) build_dir = Path(os.getenv("BUILD_DIR", "build"))
branch = os.getenv("BRANCH_NAME", os.getenv("GIT_BRANCH", ""))
build_number = os.getenv("BUILD_NUMBER", "")
if not junit_path.exists(): if not junit_path.exists():
junit_candidates = sorted(build_dir.glob("junit*.xml")) junit_candidates = sorted(build_dir.glob("junit*.xml"))
@ -280,6 +288,8 @@ def main() -> int:
f'platform_quality_gate_workspace_line_coverage_percent{{suite="{suite}"}} {coverage_pct:.3f}', f'platform_quality_gate_workspace_line_coverage_percent{{suite="{suite}"}} {coverage_pct:.3f}',
"# TYPE platform_quality_gate_source_lines_over_500_total gauge", "# 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}', f'platform_quality_gate_source_lines_over_500_total{{suite="{suite}"}} {source_lines_over_500}',
"# TYPE platform_quality_gate_build_info gauge",
f'platform_quality_gate_build_info{_label_str({"suite": suite, "branch": branch, "build_number": build_number})} 1',
"# TYPE atlasbot_quality_gate_checks_total gauge", "# TYPE atlasbot_quality_gate_checks_total gauge",
"# TYPE platform_quality_gate_test_case_result gauge", "# TYPE platform_quality_gate_test_case_result gauge",
] ]