"""The job registry: automation/jobs.yml read into jobs, the results a job ends with, and the environment each step gets. """ from __future__ import annotations import os import re import subprocess from collections.abc import Sequence from dataclasses import dataclass from pathlib import Path from core.childenv import is_secret, safe_env from core.hostguard import LOCK_HELD_ENV from core.paths import REPO_ROOT from model.sources import source_yaml_file JOBS_FILE = REPO_ROOT / "automation" / "jobs.yml" OK = "ok" FAILED = "failed" DEFERRED = "deferred" REFUSED = "refused" BLOCKED = "blocked" JOB_KEYS = frozenset({ "schedule", "steps", "gate", "twice", "commits", "worktree", "lock", "network", "min_free_gb", "max_load_wait", "timeout", "scratch", "report", }) class AutorunError(RuntimeError): """A condition that ends a job with a named result.""" def __init__(self, result: str, detail: str) -> None: super().__init__(detail) self.result = result self.detail = detail @dataclass(frozen=True) class Step: argv: tuple[str, ...] ok_codes: tuple[int, ...] = (0,) stdout: str = "" # Variables passed through beside the allowlist (romfetch's settings). env: tuple[str, ...] = () # GITHUB_TOKEN for a first-party script that calls the GitHub API. github_token: bool = False @dataclass(frozen=True) class Twice: """An artifact the gate wrote, computed again into {out} and compared.""" artifact: str argv: tuple[str, ...] glob: str = "" @dataclass(frozen=True) class CommitRule: subject: str paths: tuple[str, ...] body: str = "" @dataclass(frozen=True) class Job: name: str steps: tuple[Step, ...] = () gate: tuple[Step, ...] = () twice: tuple[Twice, ...] = () commits: tuple[CommitRule, ...] = () schedule: str = "" worktree: bool = True lock: bool = True network: bool = False min_free_gb: float = 30.0 max_load_wait: int = 3600 timeout: int = 21600 scratch: tuple[str, ...] = () report: str = "" # Job registry def check_subject(subject: str, body: str = "") -> list[str]: """What the repository's commit rules refuse in this message, checked when the job list loads instead of two hours into the job.""" from devtools.commitrules import problems return problems(f"{subject}\n\n{body}" if body else subject) # The first-party scripts that call the GitHub API and may receive # GITHUB_TOKEN: run as `python