Commit 6be1b91
Show build date (localized) and Git short SHA in footer (#97)
Summary:
### Motivation
- Improve traceability of website builds by displaying:
- the app version (from `package.json`),
- the build timestamp (localized at runtime via `toLocaleString()`), and
- the Git commit short SHA used for the build.
### Summary of Changes
- Inject build metadata at build time via Vite `define`:
- `import.meta.env.PACKAGE_VERSION` (existing) → from `package.json`.
- `import.meta.env.PACKAGE_BUILD_DATE` → ISO string from `BUILD_DATE` env or `new Date().toISOString()`.
- `import.meta.env.GIT_COMMIT_SHA_SHORT` → from `GIT_COMMIT_SHA_SHORT` env or `git rev-parse --short HEAD`, with fallback to `"unknown"`.
- Extend TypeScript env typings (`src/vite-env.d.ts`) with the two new fields.
- Render in footer (localized date):
- Example format: `Version 0.1.1 · Built 9/10/2025, 4:21:45 PM · git:abc1234`.
### Files Touched
- `website/vite.config.ts`
- Injected `PACKAGE_BUILD_DATE` and `GIT_COMMIT_SHA_SHORT` into `import.meta.env` using Vite `define`.
- Safe fallbacks: if not in a Git repo/CI without Git, value becomes `"unknown"`.
- `website/src/vite-env.d.ts`
- Added typings for `PACKAGE_BUILD_DATE` and `GIT_COMMIT_SHA_SHORT`.
- `website/src/App.tsx`
- Footer now shows: version, localized build date (`toLocaleString()`), and short SHA.
### Implementation Details
- Build-time values are set once when Vite starts (dev) or during `vite build` (prod):
- Dev server must be restarted to refresh the build date/SHA.
- `toLocaleString()` uses the user's browser locale/timezone for display.
- CI environments can optionally pass explicit values to ensure reproducible metadata:
- `BUILD_DATE=2025-09-10T08:00:00Z`
- `GIT_COMMIT_SHA_SHORT=abc123`
- If `git` is unavailable or the working directory is not a Git repo, SHA falls back to `"unknown"`.
### How to Test
1) Development
```bash
cd website
npm run dev
# Open the app. Footer should display:
# Version <pkgVersion> · Built <localizedDateTime> · <shortSHA or unknown>
```
2) Production build
```bash
cd website
npm run build
npm run preview
# Verify footer shows version, localized build date, and short SHA
```
3) Override via environment variables (optional)
```bash
# Dev
BUILD_DATE=2025-09-10T08:00:00Z GIT_COMMIT_SHA_SHORT=abc123 npm run dev
# Build
BUILD_DATE=2025-09-10T08:00:00Z GIT_COMMIT_SHA_SHORT=abc123 npm run build
```
### Risk/Impact
- Low. Purely presentational. No runtime network calls introduced.
- Backward-compatible: existing `PACKAGE_VERSION` use remains unchanged; new values have safe fallbacks.
### Notes for CI
- Ensure the repo is a Git checkout if you want automatic SHA detection, or provide `GIT_COMMIT_SHA_SHORT` explicitly.
- The build date defaults to the build machine time unless `BUILD_DATE` is provided.
Pull Request resolved: #97
Reviewed By: sfzhu93
Differential Revision: D82164288
Pulled By: FindHao
fbshipit-source-id: 1b24f0d33357a9273f4b04d8b5409b2cb6d05c7f1 parent 3ff7ac6 commit 6be1b91
3 files changed
+53
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
534 | 534 | | |
535 | 535 | | |
536 | 536 | | |
537 | | - | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
538 | 545 | | |
539 | 546 | | |
540 | 547 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
5 | 15 | | |
6 | 16 | | |
7 | 17 | | |
8 | 18 | | |
9 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
10 | 50 | | |
11 | 51 | | |
12 | 52 | | |
| |||
36 | 76 | | |
37 | 77 | | |
38 | 78 | | |
39 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
40 | 82 | | |
41 | 83 | | |
0 commit comments