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) <noreply@anthropic.com>
This commit is contained in:
1 parent
0fcfdd27cd
commit
89f2f4fd19
2 files changed
+17
No files matched your search
@@ -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