Files
archy/neode-ui/native-aiui-provenance.ts

22 lines
954 B
TypeScript

import { execFileSync } from 'node:child_process'
/** Docker demo contexts intentionally omit Git history. Their CI revision is
* informational and must never satisfy production release qualification. */
export function nativeAIUIProvenance(
repo: string,
env: NodeJS.ProcessEnv = process.env,
git: (args: string[]) => string = args => execFileSync('git', ['-C', repo, ...args], { encoding: 'utf8' }).trim(),
) {
const demo = env.DOCKER_BUILD === 'true' && ['1', 'true'].includes(env.VITE_DEMO ?? '')
if (demo) {
const revision = env.ARCHY_SOURCE_REVISION ?? ''
if (!/^[0-9a-f]{40}$/.test(revision)) throw new Error('Docker demo requires a full lowercase SOURCE_REVISION commit')
return { mode: 'native-demo', source_commit: revision, source_dirty: true }
}
return {
mode: 'native',
source_commit: git(['rev-parse', 'HEAD']),
source_dirty: git(['status', '--porcelain', '--untracked-files=all']).length > 0,
}
}