fix: show git commit in About instead of "unknown"

This commit is contained in:
Linus Rath
2026-05-02 00:28:08 +02:00
parent 8041700668
commit 599fa66822
4 changed files with 22 additions and 5 deletions
+14 -5
View File
@@ -4,11 +4,20 @@ import { execSync } from "child_process";
import { readFileSync } from "fs";
import { join } from "path";
let gitCommitHash = "unknown";
try {
gitCommitHash = execSync("git rev-parse --short HEAD").toString().trim();
} catch {
// git not available
// Prefer an explicit build arg (passed in by CI / Docker, where .git is
// excluded from the build context) and fall back to `git rev-parse` for
// local builds.
let gitCommitHash = process.env.GIT_COMMIT?.trim() || "";
if (!gitCommitHash) {
try {
gitCommitHash = execSync("git rev-parse --short HEAD").toString().trim();
} catch {
gitCommitHash = "unknown";
}
}
// Normalise full 40-char SHAs (e.g. ${{ github.sha }}) to the short form.
if (/^[0-9a-f]{40}$/i.test(gitCommitHash)) {
gitCommitHash = gitCommitHash.slice(0, 7);
}
let appVersion = "0.0.0";