Skip to content

livery.workshop._govern_entry

livery.workshop._govern_entry

Isolated Tier 1 entry point for the govern job.

Invoked as python3 -I -m livery.workshop._govern_entry [--if-changed] inside an isolated environment holding pinned livery-workshop alone. Never imports tasks.py, never runs apply_cascade (never folds .repo.env), and never installs non-privileged workspace members. Reads workshop.toml, packages/*/workshop.toml, and CODEOWNERS strictly as data and asserts repository settings through livery.forge.

Functions:

Name Description
run_govern

Reconcile repository settings from root's contracts in isolation.

main

CLI entry point for python3 -I -m livery.workshop._govern_entry.

run_govern

run_govern(root: Path, *, if_changed: bool = False, in_ci: bool | None = None) -> None

Reconcile repository settings from root's contracts in isolation.

In CI, refuses to fall back to FORGE_TOKEN: FORGE_ADMIN_TOKEN (or its host-qualified form) must be present in the govern environment. Outside CI, falls back to the normal admin ladder.

Source code in packages/workshop/src/livery/workshop/_govern_entry.py
def run_govern(
    root: Path,
    *,
    if_changed: bool = False,
    in_ci: bool | None = None,
) -> None:
    """Reconcile repository settings from *root*'s contracts in isolation.

    In CI, refuses to fall back to ``FORGE_TOKEN``: ``FORGE_ADMIN_TOKEN``
    (or its host-qualified form) must be present in the ``govern``
    environment. Outside CI, falls back to the normal admin ladder.
    """
    if if_changed:
        changed = contract_changed(root)
        if not changed:
            print("  no contract or owners path changed in HEAD; nothing to reconcile")
            return
        print(f"  governed paths changed: {', '.join(changed)}")

    running_in_ci = _in_ci() if in_ci is None else in_ci
    if running_in_ci:
        contract = load_contract(root / "workshop.toml")
        forge_table = contract.get("forge") or {}
        kind = str(forge_table.get("kind", ""))
        url = str(forge_table.get("url", ""))
        token, var = admin_token(kind, url)
        if not token or not var.startswith("FORGE_ADMIN_TOKEN"):
            fail(
                "isolated govern refuses to fall back to FORGE_TOKEN in CI:"
                " set FORGE_ADMIN_TOKEN in the govern environment"
            )
    assert_configuration(root)

main

main(argv: Sequence[str] | None = None) -> int

CLI entry point for python3 -I -m livery.workshop._govern_entry.

Source code in packages/workshop/src/livery/workshop/_govern_entry.py
def main(argv: Sequence[str] | None = None) -> int:
    """CLI entry point for ``python3 -I -m livery.workshop._govern_entry``."""
    parser = argparse.ArgumentParser(
        prog="livery.workshop._govern_entry",
        description=(
            "Reconcile forge repository settings without entering the workspace."
        ),
    )
    parser.add_argument(
        "--root",
        default=".",
        help="workspace root directory (default: current directory)",
    )
    parser.add_argument(
        "--if-changed",
        action="store_true",
        help="reconcile only when HEAD changed a governed contract or owners file",
    )
    parsed = parser.parse_args(list(argv) if argv is not None else None)
    try:
        run_govern(Path(parsed.root).resolve(), if_changed=parsed.if_changed)
    except Failed as error:
        print(f"govern: {error}", file=sys.stderr)
        return 1
    return 0