import { readFileSync } from "fs"; import path from "path"; /* What is deployed, and what is running. Two different questions. * * `.release.json` is written by scripts/deploy.sh just before the build: the sha it pulled, the * sha it replaced, and when. `NEXT_PUBLIC_RELEASE` is compiled into the bundle by that same build. * Normally the two agree. When they don't — the file names a newer sha than the running bundle — * a deploy pulled and built but the process was never restarted, which is the failure the deploy * script's own health check exists to catch and the console should show anyway. */ export type Version = { deployed: { sha: string; from: string; at: Date } | null; running: string | null; node: string; uptimeMin: number; }; export function version(): Version { let deployed: Version["deployed"] = null; try { const j = JSON.parse(readFileSync(path.join(process.cwd(), ".release.json"), "utf8")) as { sha?: string; from?: string; at?: string }; if (j.sha && j.at) deployed = { sha: String(j.sha), from: String(j.from || ""), at: new Date(j.at) }; } catch { /* no file: a box deployed before the script wrote one, or local dev */ } return { deployed, running: process.env.NEXT_PUBLIC_RELEASE || null, node: process.version, uptimeMin: Math.floor(process.uptime() / 60), }; }