chore(functions): add stamp-build.js + wire it into build script (Batch F follow-up)

This commit is contained in:
null 2026-07-16 03:10:10 -05:00
parent e02b6a9c9a
commit e39b32f4af
2 changed files with 22 additions and 2 deletions

View File

@ -7,7 +7,7 @@
}, },
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"build": "tsc", "build": "tsc && node ./stamp-build.js",
"test": "jest", "test": "jest",
"serve": "npm run build && firebase emulators:start --only functions", "serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell", "shell": "npm run build && firebase functions:shell",
@ -26,4 +26,4 @@
"ts-jest": "^29.4.11", "ts-jest": "^29.4.11",
"typescript": "^5.4.5" "typescript": "^5.4.5"
} }
} }

20
functions/stamp-build.js Normal file
View File

@ -0,0 +1,20 @@
// Writes dist/buildInfo.json after tsc so every deployed build carries its provenance.
// Why: "is commit X actually live?" was unanswerable except by behavior — functions:log's
// lagging window caused a false outage alarm and a mis-attributed landmine cause, and a
// stale committed dist shipped twice before anyone could tell (FUNCTIONS-DIST-STALE).
// With this, one log line at cold start answers it. Fail-safe: no git → "unknown".
const { execSync } = require('node:child_process')
const { writeFileSync, mkdirSync } = require('node:fs')
function run(cmd) {
try { return execSync(cmd, { encoding: 'utf8' }).trim() } catch { return 'unknown' }
}
const info = {
sha: run('git rev-parse --short HEAD'),
branch: run('git rev-parse --abbrev-ref HEAD'),
builtAt: new Date().toISOString(),
}
mkdirSync('dist', { recursive: true })
writeFileSync('dist/buildInfo.json', JSON.stringify(info, null, 2) + '\n')
console.log(`[stamp-build] ${info.sha} (${info.branch}) built ${info.builtAt}`)