Files
computer-playbook/cli/meta/ci/roles/runtime/__main__.py
T
kevinveenbirkenbachandClaude Opus 4.8 40052446dc refactor(ci): move role-runtime summary into cli.meta.ci.roles.runtime
Replace the single utils/github/profile/role_summary.py script with a
focused CLI package split per responsibility (model, logparse, csvio,
render, github, sources). Output format is selectable via --format
(table default, plus markdown, csv, json); source is auto-detected as an
Ansible log, a role-runtimes CSV, or a GitHub Actions run/job URL (CSV
artifacts downloaded via gh).

The compose workflow now writes the CSV as a downloadable artifact and
appends the per-variant markdown to the step summary, and hard-fails
when the log is missing or carries no profile_roles data so a broken
metrics capture can no longer pass silently.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-26 03:10:07 +02:00

62 lines
1.7 KiB
Python

from __future__ import annotations
import argparse
import sys
from pathlib import Path
from .render import FORMATS, render
from .sources import load_records
def _build_parser() -> argparse.ArgumentParser:
p = argparse.ArgumentParser(
prog="python -m cli.meta.ci.roles.runtime",
description=(
"Summarise Ansible profile_roles runtimes per matrix-deploy "
"variant. SOURCE is an Ansible run log, a role-runtimes CSV, or a "
"GitHub Actions run/job URL (CSV artifacts are downloaded via gh)."
),
)
p.add_argument(
"source",
help="Ansible log path, role-runtimes CSV path, or GitHub Actions run/job URL.",
)
p.add_argument(
"--format",
choices=FORMATS,
default="table",
help="Output format (default: table).",
)
p.add_argument(
"--output",
help="Write to this file instead of stdout.",
)
return p
def main(argv: list[str] | None = None) -> int:
args = _build_parser().parse_args(argv)
try:
records = load_records(args.source)
except FileNotFoundError as exc:
print(f"[role-runtime] source not found: {exc}", file=sys.stderr)
return 1
except Exception as exc:
print(f"[role-runtime] failed to load {args.source}: {exc}", file=sys.stderr)
return 1
if not records:
print("[role-runtime] no profile_roles entries found", file=sys.stderr)
return 1
text = render(records, args.format)
if args.output:
Path(args.output).write_text(text, encoding="utf-8")
else:
sys.stdout.write(text)
return 0
if __name__ == "__main__":
raise SystemExit(main())