From 89f2f4fd19d42f192a7cdda25823cd200044f643 Mon Sep 17 00:00:00 2001 From: Lucas Winther Date: Wed, 2 Sep 2026 22:21:19 +0200 Subject: [PATCH] fix(settings): shorten a commit sha in the colophon pages.yml passes BUILD_VERSION: ${{ github.sha }}, so the colophon shipped in 61e7093 was printing all forty characters of the sha. It now shortens a long hex string to seven, the way git does. Found in the deployed service worker, which embeds the same version constant: o="61e7093c36f9a0111a5f1c8776aba4894c88ebc4". The pattern requires at least one a-f, so a long run of digits that is not a valid date can never be mistaken for a sha and truncated. Anything that is not a timestamp or a sha is still printed exactly as the builder gave it. Co-Authored-By: Claude Opus 5 (1M context) --- src/ui/buildVersion.test.ts | 9 +++++++++ src/ui/buildVersion.ts | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/src/ui/buildVersion.test.ts b/src/ui/buildVersion.test.ts index 7598f99..b3ade9a 100644 --- a/src/ui/buildVersion.test.ts +++ b/src/ui/buildVersion.test.ts @@ -11,6 +11,15 @@ test("build.ts's default timestamp becomes a date", () => { expect(describeBuild("1788307200000")).toBe("2026-09-02"); }); +test("a commit sha is shortened the way git shortens one", () => { + // pages.yml passes BUILD_VERSION: ${{ github.sha }}, so the deployed + // colophon was printing all forty characters of + // 61e7093c36f9a0111a5f1c8776aba4894c88ebc4. + expect(describeBuild("61e7093c36f9a0111a5f1c8776aba4894c88ebc4")).toBe("61e7093"); + // An already-short sha is left as it is. + expect(describeBuild("61e7093")).toBe("61e7093"); +}); + test("a version someone chose is printed as given", () => { // A sha, a tag and a release number must survive untouched: guessing at a // format the builder did not ask for is worse than showing their string. diff --git a/src/ui/buildVersion.ts b/src/ui/buildVersion.ts index 031bedb..6971a3c 100644 --- a/src/ui/buildVersion.ts +++ b/src/ui/buildVersion.ts @@ -23,6 +23,13 @@ export function readBuildVersionEnv(): string | undefined { /** A millisecond epoch, which is what build.ts falls back to. */ const EPOCH_MS = /^\d{10,}$/; +/** + * A full commit sha. `pages.yml` passes `github.sha`, so the deployed colophon + * was printing all forty characters. Requires at least one a-f so a long run of + * digits that is not a valid date is never mistaken for one. + */ +const LONG_SHA = /^(?=.*[a-f])[0-9a-f]{12,}$/i; + /** * `BUILD_VERSION` may be anything the person building chose — a git sha, a tag, * a release number — so an unrecognised value is printed as given rather than @@ -39,6 +46,7 @@ export function describeBuild(raw: string | undefined): string { const at = new Date(Number(raw)); if (!Number.isNaN(at.getTime())) return at.toISOString().slice(0, 10); } + if (LONG_SHA.test(raw)) return raw.slice(0, 7); return raw; }