Add ci_report_hook/src/ci_report_hook/cli.py

This commit is contained in:
Mika 2026-01-28 16:22:44 +00:00
parent a1eecfea11
commit 3ee0c95611

View file

@ -0,0 +1,46 @@
import argparse
import sys
from ci_report_hook.core import record_ci_run
def main() -> None:
"""CLI entrypoint for recording CI run reports."""
parser = argparse.ArgumentParser(
description="Erfasst Laufdaten eines CI-Runs und speichert sie als Report-JSON."
)
parser.add_argument("--run-id", required=True, type=str, help="Eindeutiger Bezeichner des CI-Runs.")
parser.add_argument("--decision", required=True, type=str, choices=["PASS", "WARN", "FAIL"], help="Entscheidung: PASS, WARN oder FAIL.")
parser.add_argument("--margin", required=True, type=float, help="Abstand zur Entscheidungsgrenze als float.")
parser.add_argument("--flaky-flag", required=False, type=str, default="False", help="Boolesches Flag zur Instabilitätsmarkierung.")
parser.add_argument("--subset-flip-count", required=False, type=int, default=0, help="Anzahl Subset-Flips im CI-Run.")
parser.add_argument("--mischfenster-p95", required=False, type=float, default=0.0, help="95. Perzentil des Mischfensters als float.")
args = parser.parse_args()
# Convert inputs and validate
try:
flaky_flag_str = args.flaky_flag.strip().lower()
if flaky_flag_str in ("true", "1", "yes", "y"):
flaky_flag = True
elif flaky_flag_str in ("false", "0", "no", "n"):
flaky_flag = False
else:
raise ValueError(f"Ungültiger Wert für --flaky-flag: {args.flaky_flag}")
record_ci_run(
run_id=args.run_id,
decision=args.decision,
margin=args.margin,
flaky_flag=flaky_flag,
subset_flip_count=args.subset_flip_count,
mischfenster_p95=args.mischfenster_p95,
)
except Exception as exc:
print(f"Fehler beim Erfassen des CI-Reports: {exc}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()