()
| 361 | |
| 362 | |
| 363 | def main() -> int: |
| 364 | args = parse_args() |
| 365 | since = dt.datetime.now(dt.UTC) - dt.timedelta(days=args.days) |
| 366 | all_stats: list[WorkflowStats] = [] |
| 367 | # Only do the expensive all-repo scan if at least one reusable workflow |
| 368 | # appears in the target list. |
| 369 | need_repo_scan = any(w in REUSABLE_WORKFLOWS for w in WORKFLOWS) |
| 370 | all_repo_runs: list[dict] = [] |
| 371 | if need_repo_scan: |
| 372 | print("• (scanning all repo runs for reusable attribution)", file=sys.stderr) |
| 373 | all_repo_runs = fetch_all_repo_runs(since) |
| 374 | for workflow in WORKFLOWS: |
| 375 | print(f"• {workflow}", file=sys.stderr) |
| 376 | if workflow in REUSABLE_WORKFLOWS: |
| 377 | runs = fetch_reusable_runs(workflow, all_repo_runs) |
| 378 | all_stats.append(summarize(workflow, args.days, runs, reusable=True)) |
| 379 | else: |
| 380 | runs = fetch_runs(workflow, since) |
| 381 | all_stats.append(summarize(workflow, args.days, runs)) |
| 382 | |
| 383 | args.out.parent.mkdir(parents=True, exist_ok=True) |
| 384 | args.out.write_text( |
| 385 | json.dumps( |
| 386 | { |
| 387 | "repo": REPO, |
| 388 | "window_days": args.days, |
| 389 | "generated_at": dt.datetime.now(dt.UTC).isoformat(), |
| 390 | "workflows": [dataclasses.asdict(s) for s in all_stats], |
| 391 | }, |
| 392 | indent=2, |
| 393 | default=str, |
| 394 | ) |
| 395 | + "\n", |
| 396 | encoding="utf-8", |
| 397 | ) |
| 398 | args.md.write_text(render_markdown(all_stats, since), encoding="utf-8") |
| 399 | print(f"wrote {args.out}", file=sys.stderr) |
| 400 | print(f"wrote {args.md}", file=sys.stderr) |
| 401 | return 0 |
| 402 | |
| 403 | |
| 404 | if __name__ == "__main__": |
no test coverage detected