refactor: read the site build commit in one place

sitegen.config.build_commit (GITHUB_SHA in CI, HEAD locally, a full
commit id or an error) replaces the copies in bootstrap, pagemarkdown
and dataexports.

The page stamps now refuse a GITHUB_SHA that is not a commit id. The
data exports now name GITHUB_SHA when it is set, and still name no
commit outside a checkout.
This commit is contained in:
Abdessamad Derraz committed 2026-11-20 20:03:26 +01:00
1 parent ad49fe8967
commit e6e4095081
4 files changed
+29 -29

No files matched your search

+1 -15
View File
@@ -15,14 +15,13 @@ Invoke-RestMethod reads any type that is neither JSON nor XML as text.
from __future__ import annotations
import os
import re
import subprocess
from pathlib import Path
from core.artifacts import write_if_changed
from model.guides import PS1_NAME, SH_NAME
from installer_build.pins import PIN, installer_sha256
from sitegen.config import build_commit
REPO_RAW = "https://raw.githubusercontent.com/Abdess/retrobios"
@@ -46,19 +45,6 @@ SERVED_ADVICE = ("The file was changed on its way here, most often by a proxy or
"network, or with that web protection paused.")
def build_commit(root: Path) -> str:
"""The commit the site is built from: GITHUB_SHA in CI, HEAD locally."""
commit = os.environ.get("GITHUB_SHA", "").strip()
if not commit:
commit = subprocess.run(
["git", "rev-parse", "HEAD"], cwd=root, check=True,
capture_output=True, text=True,
).stdout.strip()
if not re.fullmatch(r"[0-9a-f]{40}", commit):
raise ValueError(f"not a commit id: {commit!r}")
return commit
def installer_url(commit: str) -> str:
return f"{REPO_RAW}/{commit}/install.py"