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) <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5
parent
0fcfdd27cd
commit
89f2f4fd19
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user