Deploys: exact sha, replay protection, health check and automatic rollback
CI / Test (jest) (push) Successful in 47s
CI / Lint (eslint) (push) Successful in 52s
CI / Security (npm audit) (push) Successful in 17s
CI / Deploy (push) Skipped
CI / Notify (push) Skipped
CI / Test (jest) (pull_request) Failing after 12s
CI / Lint (eslint) (pull_request) Successful in 14s
CI / Security (npm audit) (pull_request) Successful in 11s
CI / Deploy (pull_request) Skipped
CI / Notify (pull_request) Skipped

#45 phase 2.

- GET /healthz (unauthenticated): running git sha, version, database
  reachability, connected workers, uptime. 503 when the database is down.
- deploy/pulse_deploy.sh, versioned for the first time (it only existed
  as a hand-edited file on CT 122). It takes <sha> <ts> from the signed
  webhook payload and:
  - refuses requests older than 5 minutes, or not newer than the last
    accepted one (replays);
  - refuses commits that aren't on main;
  - checks out exactly that sha (before, it deployed whatever main was);
  - runs npm ci --omit=dev (before, npm install --production) and
    restarts;
  - waits for /healthz to report the sha with a working database, and
    otherwise rolls back to the previous commit.
- tests/deploy-script.test.js runs the script in a sandbox (temporary git
  origin, fake systemctl/npm/curl): exact-sha deploy with .env kept, replay,
  stale request, off-main commit, malformed input, and rollback of an
  unhealthy build.
- CI's deploy job now succeeds only once production reports the tested sha
  as healthy, before tagging. Before, it only checked that the server
  answered.
- README: CI/CD and deploy documentation, including installing the script
  and the hooks.json arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-22 02:25:35 -05:00
1 parent b10ea154dd
commit cb12fec28c
5 files changed
+311 -17

No files matched your search

+34
View File
@@ -1321,6 +1321,40 @@ async function waitForCommandResult(executionId, commandId, timeout) {
// Health check for deploys and monitoring (#45 phase 2). Unauthenticated on purpose,
// so CI and the deploy script can reach it; it reveals only the running commit,
// whether the database answers and how many workers are connected.
const GIT_SHA = (() => {
try {
return require('child_process')
.execFileSync('git', ['rev-parse', 'HEAD'], { cwd: __dirname, timeout: 5000, stdio: ['ignore', 'pipe', 'ignore'] })
.toString().trim();
} catch {
return 'unknown';
}
})();
app.get('/healthz', async (req, res) => {
let db = false;
try {
await Promise.race([
pool.query('SELECT 1'),
new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 3000))
]);
db = true;
} catch { /* reported as db: false */ }
const connectedWorkers = new Set([...workers.values()].map(w => w.dbWorkerId).filter(Boolean)).size;
res.set('Cache-Control', 'no-store');
res.status(db ? 200 : 503).json({
status: db ? 'ok' : 'degraded',
version: SERVER_VERSION,
sha: GIT_SHA,
db,
workers: connectedWorkers,
uptime_s: Math.round(process.uptime())
});
});
// HTML page routes (registered before the API routes)
const authenticatePage = makeAuthenticatePage(pool);
PAGES.forEach((p) => {