BlueGit

timfa questward

Files

questward / deploy / update-if-requested.mjs

update-if-requested.mjs

a75d35b0 History
update-if-requested.mjs 1.8 KiB Download Raw
1#!/usr/bin/env node
2/**
3 * systemd ExecStartPre helper: pull/ff-only only when a restart manifest
4 * requested a code deployment. Crashes without a manifest never pull.
5 *
6 * Env:
7 * QUESTWARD_REPO — git working tree (default: cwd)
8 * QUESTWARD_DATA — directory containing restart-request.json (default: <repo>/server/data)
9 * QUESTWARD_GIT_BRANCH — remote branch (default: master)
10 * (TILE_MMO_* env vars are still accepted as fallbacks.)
11 */
12import { spawnSync } from "node:child_process";
13import { join } from "node:path";
14import { consumeRestartManifest, restartManifestPath } from "../server/src/deploy/manifest.js";
15
16const repo = process.env.QUESTWARD_REPO || process.env.TILE_MMO_REPO || process.cwd();
17const dataDir = process.env.QUESTWARD_DATA || process.env.TILE_MMO_DATA || join(repo, "server", "data");
18const branch = process.env.QUESTWARD_GIT_BRANCH || process.env.TILE_MMO_GIT_BRANCH || "master";
19const manifestPath = restartManifestPath(dataDir);
20
21const manifest = consumeRestartManifest(manifestPath);
22if (!manifest)
23{
24 console.log("[deploy] No restart manifest; starting checked-out version.");
25 process.exit(0);
26}
27
28console.log("[deploy] Consumed restart manifest:", JSON.stringify(manifest));
29
30if (!manifest.deployCode)
31{
32 console.log("[deploy] World-only / non-code restart; skipping git pull.");
33 process.exit(0);
34}
35
36function git (args)
37{
38 const result = spawnSync("git", args, {
39 cwd: repo,
40 stdio: "inherit",
41 windowsHide: true
42 });
43 if (result.status !== 0)
44 {
45 console.error(`[deploy] git ${args.join(" ")} failed with status ${result.status}`);
46 process.exit(result.status ?? 1);
47 }
48}
49
50git(["fetch", "origin", branch]);
51if (manifest.targetCommit)
52{
53 git(["merge", "--ff-only", manifest.targetCommit]);
54}
55else
56{ git(["merge", "--ff-only", `origin/${branch}`]); }
57
58console.log("[deploy] Fast-forward complete.");
59process.exit(0);