From ef1920a19cef7e109409ad284f2debfa33d416c7 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Fri, 19 Jun 2026 19:39:53 +0200 Subject: [PATCH 1/3] Allow injection of the commit hash and timestamp for hermetic builds. Hermetic build systems, such as Nix, typically don't provide the `.git` directory, which means that building Phanpy will fall back to the randomly-generated commit hash and current timestamp. As a workaround, I propose allowing the packager to specify this during build time with environment variables. I have also added some extra logging to make it clear what's going on. --- .prettierrc | 1 + vite.config.js | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000000..0176969226 --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +singleQuote: true diff --git a/vite.config.js b/vite.config.js index 931dc3b566..c6c68e18e5 100644 --- a/vite.config.js +++ b/vite.config.js @@ -23,6 +23,8 @@ const { PHANPY_APP_ERROR_LOGGING: ERROR_LOGGING, PHANPY_REFERRER_POLICY: REFERRER_POLICY, PHANPY_DISALLOW_ROBOTS: DISALLOW_ROBOTS, + PHANPY_COMMIT_HASH: COMMIT_HASH, + PHANPY_COMMIT_TIME: COMMIT_TIME, PHANPY_DEV, } = loadEnv('production', process.cwd(), allowedEnvPrefixes); @@ -30,18 +32,33 @@ const now = new Date(); let commitHash; let commitTime; let fakeCommitHash = false; -try { - const gitResult = execSync('git log -1 --format="%h %cI"').toString().trim(); - const [hash, time] = gitResult.split(' '); - commitHash = hash; - commitTime = new Date(time); -} catch (error) { - // If error, means git is not installed or not a git repo (could be downloaded instead of git cloned) - // Fallback to random hash which should be different on every build run 🤞 - commitHash = uid(); - commitTime = now; - fakeCommitHash = true; +if (COMMIT_HASH && COMMIT_TIME) { + console.log('Using provided commit hash and timestamp'); + commitHash = COMMIT_HASH; + commitTime = new Date(COMMIT_TIME); +} else { + try { + console.log('Fetching commit hash and timestamp from Git'); + const gitResult = execSync('git log -1 --format="%h %cI"') + .toString() + .trim(); + const [hash, time] = gitResult.split(' '); + commitHash = hash; + commitTime = new Date(time); + } catch (error) { + // If error, means git is not installed or not a git repo (could be downloaded instead of git cloned) + // Fallback to random hash which should be different on every build run 🤞 + console.log( + 'Falling back to randomly-generated commit hash, and current timestamp', + ); + commitHash = uid(); + commitTime = now; + fakeCommitHash = true; + } } +console.log( + ` commit hash: ${commitHash}\n commit time: ${commitTime.toISOString()}`, +); let rollbarCode = fs.readFileSync(resolve(__dirname, './rollbar.js'), 'utf-8'); rollbarCode = rollbarCode.replace('__PHANPY_COMMIT_HASH__', `'${commitHash}'`); From e450df1e1b525eb466fbece1be3d5d5c1fb03ed2 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Fri, 19 Jun 2026 21:02:45 +0200 Subject: [PATCH 2/3] Allow mocking out the build time too. --- vite.config.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vite.config.js b/vite.config.js index c6c68e18e5..2dba89b5d8 100644 --- a/vite.config.js +++ b/vite.config.js @@ -25,10 +25,11 @@ const { PHANPY_DISALLOW_ROBOTS: DISALLOW_ROBOTS, PHANPY_COMMIT_HASH: COMMIT_HASH, PHANPY_COMMIT_TIME: COMMIT_TIME, + PHANPY_NOW: NOW, PHANPY_DEV, } = loadEnv('production', process.cwd(), allowedEnvPrefixes); -const now = new Date(); +const now = NOW ? new Date(NOW) : new Date(); let commitHash; let commitTime; let fakeCommitHash = false; @@ -57,7 +58,11 @@ if (COMMIT_HASH && COMMIT_TIME) { } } console.log( - ` commit hash: ${commitHash}\n commit time: ${commitTime.toISOString()}`, + [ + ` commit hash: ${commitHash}`, + ` commit time: ${commitTime.toISOString()}`, + ` build time: ${now.toISOString()}`, + ].join('\n'), ); let rollbarCode = fs.readFileSync(resolve(__dirname, './rollbar.js'), 'utf-8'); From e09e527f0d4335986abbde15cf15d09d70400b72 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Sat, 20 Jun 2026 07:52:19 +0200 Subject: [PATCH 3/3] Delete .prettierrc. --- .prettierrc | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 0176969226..0000000000 --- a/.prettierrc +++ /dev/null @@ -1 +0,0 @@ -singleQuote: true