6, "wing" => "Deploy",
"title" => "A push is a deploy",
"promise" => "Pushing to main puts the code live within a minute.",
"block" => "git push is the deploy. What is running, and since when, is in RC_FACTS/deploy.json, written by root, readable by the app.",
"show" => function (?array $me): string {
$d = fact("deploy.json") ?? [];
$out = '
';
foreach (["live", "staging"] as $env) {
$x = $d[$env] ?? null;
$out .= '- ' . $env . "" . ($x ? "
" . h(substr($x["commit"], 0, 10)) . " by " . h($x["by"]) . ", " . ago(strtotime($x["at"])) : "nothing yet") . " ";
}
return $out . "
";
},
// The commit running here must be the newest one pushed to this environment's branch.
"check" => function (): array {
$env = env("RC_ENV");
$running = fact("deploy.json")[$env] ?? null;
$pushes = fact("pushes.json");
if (!$running || $pushes === null) return [false, "RC_FACTS has no deploy.json or pushes.json"];
$last = array_values(array_filter($pushes, fn($p) => $p["env"] === $env && str_starts_with($p["result"], "deployed")))[0] ?? null;
if (!$last) return [false, "no successful push to $env is recorded"];
if ($last["commit"] !== $running["commit"]) return [false, "running " . substr($running["commit"], 0, 10) . " but the last push to $env was " . substr($last["commit"], 0, 10)];
$lag = strtotime($running["at"]) - strtotime($last["at"]);
if ($lag > 60) return [false, "the last push took {$lag}s to go live"];
return [true, "running " . substr($running["commit"], 0, 10) . ", the last push to $env, live {$lag}s after the push"];
},
];