// Build-time GitOps receipt data — captured ONCE at build (SSG), zero runtime calls.
// The footer renders these as the "receipt" line; values are baked into the static HTML.
import { execSync } from "node:child_process";

function git(cmd: string): string {
  try {
    return execSync(cmd, { encoding: "utf8" }).trim();
  } catch {
    return "unknown";
  }
}

export const buildInfo = {
  /** Short commit sha of the source HEAD this build was cut from.
   *  Container builds get it via the GIT_SHA build-arg (.dockerignore excludes .git);
   *  local builds fall back to asking git directly. */
  sha: process.env.GIT_SHA?.trim() || git("git rev-parse --short HEAD"),
  /** ISO date (UTC, minute precision) the build ran. */
  builtAt: new Date().toISOString().slice(0, 16).replace("T", " ") + "Z",
} as const;
