diff --git a/vite.config.js b/vite.config.js index 931dc3b566..2dba89b5d8 100644 --- a/vite.config.js +++ b/vite.config.js @@ -23,25 +23,47 @@ 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_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; -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}`, + ` commit time: ${commitTime.toISOString()}`, + ` build time: ${now.toISOString()}`, + ].join('\n'), +); let rollbarCode = fs.readFileSync(resolve(__dirname, './rollbar.js'), 'utf-8'); rollbarCode = rollbarCode.replace('__PHANPY_COMMIT_HASH__', `'${commitHash}'`);