1"""Isolated Tier 1 entry point for the ``govern`` job.
3Invoked as ``python3 -I -m livery.workshop._govern_entry [--if-changed]``
4inside an isolated environment holding pinned ``livery-workshop`` alone.
5Never imports ``tasks.py``, never runs ``apply_cascade`` (never folds
6``.repo.env``), and never installs non-privileged workspace members.
7Reads ``workshop.toml``, ``packages/*/workshop.toml``, and ``CODEOWNERS``
8strictly as data and asserts repository settings through ``livery.forge``.
9"""
26 """Whether this process runs inside a CI runner."""
27 return bool(
28 os.environ.get("GITHUB_ACTIONS")
29 or os.environ.get("GITEA_ACTIONS")
30 or os.environ.get("GITLAB_CI")
31 )
35 root: Path,
36 *,
37 if_changed: bool = False,
38 in_ci: bool | None = None,
39) -> None:
40 """Reconcile repository settings from *root*'s contracts in isolation.
42 In CI, refuses to fall back to ``FORGE_TOKEN``: ``FORGE_ADMIN_TOKEN``
43 (or its host-qualified form) must be present in the ``govern``
44 environment. Outside CI, falls back to the normal admin ladder.
45 """
46 if if_changed:
48 if not changed:48 ↛ 51line 48 didn't jump to line 51 because the condition on line 48 was always true(empty)
51 print(f" governed paths changed: {', '.join(changed)}")
53 running_in_ci = _in_ci() if in_ci is None else in_ci
54 if running_in_ci:54 ↛ 65line 54 didn't jump to line 65 because the condition on line 54 was always true
55 contract = load_contract(root / "workshop.toml")
56 forge_table = contract.get("forge") or {}
57 kind = str(forge_table.get("kind", ""))
58 url = str(forge_table.get("url", ""))
59 token, var = admin_token(kind, url)
60 if not token or not var.startswith("FORGE_ADMIN_TOKEN"):60 ↛ 65line 60 didn't jump to line 65 because the condition on line 60 was always true
61 fail(
62 "isolated govern refuses to fall back to FORGE_TOKEN in CI:"
63 " set FORGE_ADMIN_TOKEN in the govern environment"
64 )
65 assert_configuration(root)
69 """CLI entry point for ``python3 -I -m livery.workshop._govern_entry``."""
71 prog="livery.workshop._govern_entry",
72 description=(
73 "Reconcile forge repository settings without entering the workspace."
74 ),
75 )
77 "--root",
78 default=".",
79 help="workspace root directory (default: current directory)",
80 )
82 "--if-changed",
83 action="store_true",
84 help="reconcile only when HEAD changed a governed contract or owners file",
85 )
89 except Failed as error:
90 print(f"govern: {error}", file=sys.stderr)
91 return 1