Files
PaperClipAI/ui/src/lib/vite-build-commit.ts
T
Devin FoleyandPaperclip 600e552d7b fix: attribute Sentry errors to the loaded source release (#13719)
Attribute optional server and browser Sentry events to their source build.
Use validated build commits for Docker and source/npm artifacts, preserve
explicit server release overrides, and keep cached browser bundles tied
to the commit they loaded.

Verify 127 focused tests, server/UI typechecks, Docker and source build
stamps, all 53 CI checks, and Greptile 5/5 with no unresolved comments.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-09-20 08:08:33 -07:00

32 lines
972 B
TypeScript

import { execFileSync } from "node:child_process";
function parseCommit(value: string | undefined): string | null {
const commit = value?.trim() ?? "";
return /^[0-9a-f]{40}$/i.test(commit) ? commit.toLowerCase() : null;
}
/** Only a full source commit may enter the public browser bundle. */
export function resolveBrowserBuildCommit(
value: string | undefined,
readGitCommit: () => string | undefined = () => undefined,
): string | null {
const suppliedCommit = parseCommit(value);
if (suppliedCommit) return suppliedCommit;
try {
return parseCommit(readGitCommit());
} catch {
return null;
}
}
export function readBrowserBuildCommit(repositoryDirectory: string): string | null {
return resolveBrowserBuildCommit(process.env.PAPERCLIP_BUILD_COMMIT, () =>
execFileSync("git", ["rev-parse", "HEAD"], {
cwd: repositoryDirectory,
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
timeout: 1000,
}),
);
}