refactor: print the autorun plan in the command

This commit is contained in:
Abdessamad Derraz committed 2026-11-22 00:58:05 +01:00
1 parent e77cf9fd69
commit 936e9ceed9
3 files changed
+29 -10

No files matched your search

+8 -2
View File
@@ -44,7 +44,7 @@ from core.hostguard import (
)
from unattended.breaker import gh_json
from unattended.jobs import DEFERRED, OK, load_jobs
from unattended.runner import Context, render_status, run_job, status
from unattended.runner import Context, UnknownJob, describe, find_job, render_status, run_job, status
from unattended.timers import install_timers, render_units
from unattended.worktree import main_checkout
@@ -90,7 +90,13 @@ def main() -> int:
)
if args.command == "run":
ctx.dry_run, ctx.push = args.dry_run, args.push
result, detail = run_job(ctx, args.job)
try:
if args.dry_run:
print("\n".join(describe(find_job(ctx, args.job), ctx)))
result, detail = run_job(ctx, args.job)
except UnknownJob as exc:
print(exc, file=sys.stderr)
return 1
print(f"{args.job}: {result} ({detail})")
return EXIT_CODES.get(result, 1)
if args.command == "status":
+13 -4
View File
@@ -444,13 +444,22 @@ def describe(job: Job, ctx: Context) -> list[str]:
return lines
def run_job(ctx: Context, name: str) -> tuple[str, str]:
"""Run one job and record it, returning (result, detail)."""
class UnknownJob(LookupError):
"""A job name that automation/jobs.yml does not declare."""
def find_job(ctx: Context, name: str) -> Job:
"""The job of that name, or UnknownJob naming the declared ones."""
job = ctx.jobs.get(name)
if job is None:
raise SystemExit(f"unknown job {name!r}: {', '.join(sorted(ctx.jobs))}")
raise UnknownJob(f"unknown job {name!r}: {', '.join(sorted(ctx.jobs))}")
return job
def run_job(ctx: Context, name: str) -> tuple[str, str]:
"""Run one job and record it, returning (result, detail)."""
job = find_job(ctx, name)
if ctx.dry_run:
print("\n".join(describe(job, ctx)))
return OK, "dry run"
state = load_state(ctx.state_path)
runner = Runner(ctx, job, state)