#!/usr/bin/env node /** * systemd ExecStartPre helper: pull/ff-only only when a restart manifest * requested a code deployment. Crashes without a manifest never pull. * * Env: * QUESTWARD_REPO — git working tree (default: cwd) * QUESTWARD_DATA — directory containing restart-request.json (default: /server/data) * QUESTWARD_GIT_BRANCH — remote branch (default: master) * (TILE_MMO_* env vars are still accepted as fallbacks.) */ import { spawnSync } from "node:child_process"; import { join } from "node:path"; import { consumeRestartManifest, restartManifestPath } from "../server/src/deploy/manifest.js"; const repo = process.env.QUESTWARD_REPO || process.env.TILE_MMO_REPO || process.cwd(); const dataDir = process.env.QUESTWARD_DATA || process.env.TILE_MMO_DATA || join(repo, "server", "data"); const branch = process.env.QUESTWARD_GIT_BRANCH || process.env.TILE_MMO_GIT_BRANCH || "master"; const manifestPath = restartManifestPath(dataDir); const manifest = consumeRestartManifest(manifestPath); if (!manifest) { console.log("[deploy] No restart manifest; starting checked-out version."); process.exit(0); } console.log("[deploy] Consumed restart manifest:", JSON.stringify(manifest)); if (!manifest.deployCode) { console.log("[deploy] World-only / non-code restart; skipping git pull."); process.exit(0); } function git (args) { const result = spawnSync("git", args, { cwd: repo, stdio: "inherit", windowsHide: true }); if (result.status !== 0) { console.error(`[deploy] git ${args.join(" ")} failed with status ${result.status}`); process.exit(result.status ?? 1); } } git(["fetch", "origin", branch]); if (manifest.targetCommit) { git(["merge", "--ff-only", manifest.targetCommit]); } else { git(["merge", "--ff-only", `origin/${branch}`]); } console.log("[deploy] Fast-forward complete."); process.exit(0);