From 6df0ec503b6038aba4b539db78d1a94ff412ab16 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:32:16 +0100 Subject: [PATCH] refactor: stamp site data with build_timestamp --- scripts/sitegen/build.py | 7 ++++--- scripts/sitegen/config.py | 5 ----- scripts/sitegen/dataexports.py | 7 ++++--- scripts/sitegen/versions.py | 5 +++-- tests/test_site_reference.py | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/scripts/sitegen/build.py b/scripts/sitegen/build.py index 52a080d64..05aa2a4e8 100644 --- a/scripts/sitegen/build.py +++ b/scripts/sitegen/build.py @@ -11,6 +11,7 @@ from collections.abc import Callable from dataclasses import dataclass from pathlib import Path +from core.artifacts import build_timestamp from romrecipes import ledger from model import releaserecord from model import siteinputs @@ -38,7 +39,7 @@ from sitegen import ( wanted as sitewanted, ) from sitegen.cards import wanted_link, system_install_choices, tables_out_of_search -from sitegen.config import GENERATED_DIRS, PUBLIC_DIRS, REPO_URL, data_timestamp, yaml +from sitegen.config import GENERATED_DIRS, PUBLIC_DIRS, REPO_URL, yaml from core.paths import REPO_ROOT from sitegen.crossref import generate_cross_reference from sitegen.dataexports import ( @@ -287,7 +288,7 @@ def _write_system_pages(run: _SiteRun) -> None: public / "api" / "v1" / "systems" / f"{slug}.json", "systems", # The published data keeps the collection's folders. system_export_item(slug, mfr, manufacturers[mfr]), - str(db.get("generated_at") or data_timestamp()), source_commit(), + build_timestamp(db), source_commit(), ) clash = split_system_stems() & {manufacturer_slug(m) for m in manufacturers} if clash: @@ -422,7 +423,7 @@ def _write_emulator_page(run: _SiteRun, name: str, profile: dict) -> None: write_single_item( run.public / "api" / "v1" / "emulators" / f"{name}.json", "emulators", {"id": name, "profile": profile}, - str(db.get("generated_at") or data_timestamp()), source_commit(), + build_timestamp(db), source_commit(), ) pages = emulator_pages( name, profile, db, run.consumers, run.suppl_names, run.data_registry, diff --git a/scripts/sitegen/config.py b/scripts/sitegen/config.py index b6c963f91..dff26ae42 100644 --- a/scripts/sitegen/config.py +++ b/scripts/sitegen/config.py @@ -48,11 +48,6 @@ def build_commit(root: Path = REPO_ROOT) -> str: return commit -def data_timestamp() -> str: - """The build time for data files (stats, API records), ISO 8601.""" - return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") - - def data_as_of(moment: datetime | None = None) -> str: """The build date for a reader, in words, with the machine form beside it. A raw ISO stamp ("2026-10-22T22:43:08Z") closed the home page.""" diff --git a/scripts/sitegen/dataexports.py b/scripts/sitegen/dataexports.py index e505ffe54..250f47a28 100644 --- a/scripts/sitegen/dataexports.py +++ b/scripts/sitegen/dataexports.py @@ -13,6 +13,7 @@ import sys from collections.abc import Callable from pathlib import Path +from core.artifacts import build_timestamp from core.artifacts import json_text as _json_text from core.hashing import file_digest from model import retired as model_retired @@ -22,7 +23,7 @@ from model.profiles import is_emulator from packs.crossref import FileConsumers from acquire.provenance import build_report from sitegen.apiitems import core_index_items, system_index_items -from sitegen.config import DATA_LICENSE, REPO_URL, build_commit, data_timestamp +from sitegen.config import DATA_LICENSE, REPO_URL, build_commit from core.paths import REPO_ROOT from sitegen.install import release_pack_platforms from sitegen.lookup import ( @@ -510,7 +511,7 @@ def _write_sqlite_export( commit = source_commit() metadata = { "schema_version": "1", - "generated_at": str(db.get("generated_at") or data_timestamp()), + "generated_at": build_timestamp(db), **({"commit": commit} if commit else {}), "source": REPO_URL, "scope": "metadata only, no BIOS or firmware payload bytes", @@ -690,7 +691,7 @@ def generate_data_exports( for directory in (api, downloads, schemas_dest): directory.mkdir(parents=True, exist_ok=True) - generated_at = str(db.get("generated_at") or data_timestamp()) + generated_at = build_timestamp(db) # The revision the data was read at: a tool comparing two downloads # could not tell which commit each came from. commit = source_commit() diff --git a/scripts/sitegen/versions.py b/scripts/sitegen/versions.py index b3c04c226..9d728a6cb 100644 --- a/scripts/sitegen/versions.py +++ b/scripts/sitegen/versions.py @@ -5,12 +5,13 @@ from __future__ import annotations import re from datetime import datetime +from core.artifacts import build_timestamp from model import releaserecord from model import siteinputs from model.composition import count_catalog_matched from model.platforms import load_platform_config from model.profiles import unique_emulator_profiles -from sitegen.config import RELEASE_URL, REPO_URL, data_timestamp +from sitegen.config import RELEASE_URL, REPO_URL def compute_stats(db: dict, coverages: dict, profiles: dict) -> dict: @@ -20,7 +21,7 @@ def compute_stats(db: dict, coverages: dict, profiles: dict) -> dict: systems.update(p.get("systems", [])) return { "schema_version": 1, - "generated_at": data_timestamp(), + "generated_at": build_timestamp(), "files": db.get("total_files", 0), "size_bytes": db.get("total_size", 0), "platforms": len(coverages), diff --git a/tests/test_site_reference.py b/tests/test_site_reference.py index bcfef96d0..86b115f42 100644 --- a/tests/test_site_reference.py +++ b/tests/test_site_reference.py @@ -710,7 +710,7 @@ class EveryEnvelopeCarriesTheCommit(unittest.TestCase): def test_the_writers_pass_it(self): source = script_source("generate_site.py") - self.assertIn('str(db.get("generated_at") or data_timestamp()), source_commit(),\n )\n' + self.assertIn('build_timestamp(db), source_commit(),\n )\n' " clash", source) block = source[source.index("public_profiles = {"):source.index("pages = emulator_pages(")] self.assertIn("write_single_item(", block)