From 4a5ea8ee6fa759d29e685c6354c5fa2128377885 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Sun, 12 Jul 2026 15:31:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20=E5=90=8C=E6=AD=A5develop=E4=B8=8Aci?= =?UTF-8?q?=5Fcoverage=5Fsummary.py=E6=9C=80=E6=96=B0=E7=89=88=EF=BC=88?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=A0=BC=E5=BC=8F+=E5=86=B2=E7=AA=81?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ci_coverage_summary.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/ci_coverage_summary.py b/scripts/ci_coverage_summary.py index 34543d9d0..b78197d22 100644 --- a/scripts/ci_coverage_summary.py +++ b/scripts/ci_coverage_summary.py @@ -1,25 +1,35 @@ #!/usr/bin/env python3 """解析 coverage.xml 并输出覆盖率汇总。""" + import os import sys import xml.etree.ElementTree as ET + THRESHOLD = int(os.environ.get("COVERAGE_THRESHOLD", 65)) # 行覆盖率门槛,百分比,可通过环境变量覆盖 + + def main() -> int: try: tree = ET.parse("coverage.xml") except FileNotFoundError: print("coverage.xml 不存在,跳过汇总") return 0 + root = tree.getroot() line_rate = float(root.get("line-rate", 0)) * 100 branch_rate = float(root.get("branch-rate", 0)) * 100 lines_covered = int(root.get("lines-covered", 0)) lines_valid = int(root.get("lines-valid", 0)) + print(f"行覆盖率: {line_rate:.2f}% ({lines_covered}/{lines_valid})") print(f"分支覆盖率: {branch_rate:.2f}%") print(f"门槛: {THRESHOLD}%") status = "PASS ✅" if line_rate >= THRESHOLD else "FAIL ❌" print(f"状态: {status}") + return 0 if line_rate >= THRESHOLD else 1 + + if __name__ == "__main__": sys.exit(main()) +