mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-13 23:39:21 +02:00
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>
32 lines
972 B
TypeScript
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,
|
|
}),
|
|
);
|
|
}
|