Record Policy Nexus metadata apply and diagnose bootstrap
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a058f3-8ba0-7692-a042-9a870fc3d663
This commit is contained in:
parent
1d5f35539d
commit
a6d47c51cc
3 changed files with 46 additions and 2 deletions
|
|
@ -26,6 +26,7 @@ SECRET = "FORGEJO_SOURCE_TOKEN"
|
|||
TOKEN_PREFIX = "policy-nexus-source-read-"
|
||||
SCOPES = ["read:repository"]
|
||||
REPO_DIR = Path(__file__).resolve().parent.parent
|
||||
DIAGNOSTIC_PATH = Path("/tmp/policy-nexus-source-bootstrap-diagnostic.json")
|
||||
NON_CODE_UNITS = (
|
||||
"repo.actions",
|
||||
"repo.packages",
|
||||
|
|
@ -43,6 +44,14 @@ class ProvisionError(RuntimeError):
|
|||
pass
|
||||
|
||||
|
||||
def write_diagnostic(stage: str, error: Exception | None = None) -> None:
|
||||
detail = str(error) if isinstance(error, ProvisionError) else "unexpected internal error"
|
||||
DIAGNOSTIC_PATH.write_text(
|
||||
json.dumps({"stage": stage, "detail": detail}, sort_keys=True) + "\n"
|
||||
)
|
||||
DIAGNOSTIC_PATH.chmod(0o600)
|
||||
|
||||
|
||||
def api_request(
|
||||
token: str,
|
||||
method: str,
|
||||
|
|
@ -332,6 +341,7 @@ def provision(admin_token: str) -> None:
|
|||
|
||||
|
||||
def outer() -> int:
|
||||
DIAGNOSTIC_PATH.unlink(missing_ok=True)
|
||||
result = subprocess.run(
|
||||
[
|
||||
"warden",
|
||||
|
|
@ -350,6 +360,8 @@ def outer() -> int:
|
|||
check=False,
|
||||
timeout=900,
|
||||
)
|
||||
if result.returncode != 0 and not DIAGNOSTIC_PATH.exists():
|
||||
write_diagnostic("forgejo-admin-route")
|
||||
return result.returncode
|
||||
|
||||
|
||||
|
|
@ -362,7 +374,12 @@ def main() -> int:
|
|||
admin_token = os.environ.get("API_TOKEN", "")
|
||||
if not admin_token:
|
||||
raise ProvisionError("Warden did not provide API_TOKEN")
|
||||
provision(admin_token)
|
||||
try:
|
||||
provision(admin_token)
|
||||
except Exception as error:
|
||||
write_diagnostic("provision", error)
|
||||
raise
|
||||
DIAGNOSTIC_PATH.unlink(missing_ok=True)
|
||||
return 0
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue