Deploy through the predeploy gate instead of by hand.
`npm run deploy` now runs the gate (typecheck, unit suite, render check) before anything is copied, then rsyncs the source, rebuilds and restarts the service on the target from LUMINARY_DEPLOY_* variables, and fails if the server is not serving the same bundle hashes as the reviewed local build. npm runs a script named predeploy before deploy on its own, so the gate runs once; invoked as `node scripts/deploy.mjs` the script gates itself. Both scripts exit through process.exitCode, because process.exit() truncated the failure messages when they were piped. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
+38
-21
@@ -7,6 +7,9 @@
|
||||
* The signature is stored under node_modules/.cache: that directory is
|
||||
* gitignored and excluded from the deploy rsync, so it is per-checkout state
|
||||
* and never travels to the server.
|
||||
*
|
||||
* Exits via process.exitCode rather than process.exit(): piped stdout is async
|
||||
* and exiting early truncates the failure message.
|
||||
*/
|
||||
import { createHash } from 'node:crypto';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
@@ -37,6 +40,8 @@ const INPUTS = [
|
||||
/** Test files never reach the bundle, so their edits must not force a rebuild. */
|
||||
const NOT_BUNDLED = /(^|\/)(__tests__|__mocks__|__fixtures__)(\/|$)|\.(test|spec)\.[cm]?[jt]sx?$/;
|
||||
|
||||
class StepFailed extends Error {}
|
||||
|
||||
function walk(target) {
|
||||
if (!existsSync(target)) return [];
|
||||
if (statSync(target).isFile()) return [target];
|
||||
@@ -65,31 +70,43 @@ function run(name, args) {
|
||||
try {
|
||||
execFileSync('npm', args, { cwd: ROOT, stdio: 'inherit' });
|
||||
} catch {
|
||||
console.error(`\npredeploy FAILED at ${name}.`);
|
||||
process.exit(1);
|
||||
throw new StepFailed(name);
|
||||
}
|
||||
}
|
||||
|
||||
const signature = inputSignature();
|
||||
const previous = existsSync(CACHE) ? JSON.parse(readFileSync(CACHE, 'utf8')) : null;
|
||||
const upToDate =
|
||||
existsSync(path.join(ROOT, 'dist', 'index.html')) && previous?.digest === signature.digest;
|
||||
function main() {
|
||||
const signature = inputSignature();
|
||||
const previous = existsSync(CACHE) ? JSON.parse(readFileSync(CACHE, 'utf8')) : null;
|
||||
const upToDate =
|
||||
existsSync(path.join(ROOT, 'dist', 'index.html')) && previous?.digest === signature.digest;
|
||||
|
||||
run('typecheck', ['run', 'typecheck']);
|
||||
run('tests', ['run', 'test']);
|
||||
run('render check', ['run', 'check:render']);
|
||||
try {
|
||||
run('typecheck', ['run', 'typecheck']);
|
||||
run('tests', ['run', 'test']);
|
||||
run('render check', ['run', 'check:render']);
|
||||
if (upToDate) {
|
||||
console.log(
|
||||
`\npredeploy: build skipped - the ${signature.count} bundle inputs are unchanged since the last build.`,
|
||||
);
|
||||
} else {
|
||||
run('build', ['run', 'build']);
|
||||
}
|
||||
} catch (err) {
|
||||
if (!(err instanceof StepFailed)) throw err;
|
||||
console.error(`\npredeploy FAILED at ${err.message}.`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (upToDate) {
|
||||
console.log(
|
||||
`\npredeploy: build skipped - the ${signature.count} bundle inputs are unchanged since the last build.`,
|
||||
);
|
||||
} else {
|
||||
run('build', ['run', 'build']);
|
||||
mkdirSync(path.dirname(CACHE), { recursive: true });
|
||||
writeFileSync(
|
||||
CACHE,
|
||||
`${JSON.stringify({ digest: signature.digest, count: signature.count, at: new Date().toISOString() }, null, 2)}\n`,
|
||||
);
|
||||
if (!upToDate) {
|
||||
mkdirSync(path.dirname(CACHE), { recursive: true });
|
||||
writeFileSync(
|
||||
CACHE,
|
||||
`${JSON.stringify({ digest: signature.digest, count: signature.count, at: new Date().toISOString() }, null, 2)}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
console.log('\npredeploy PASSED.');
|
||||
return 0;
|
||||
}
|
||||
|
||||
console.log('\npredeploy PASSED.');
|
||||
process.exitCode = main();
|
||||
|
||||
Reference in New Issue
Block a user