7, "wing" => "Deploy", "title" => "The branch decides", "promise" => "main goes live, staging goes to a twin with its own data, and any other branch goes nowhere.", "block" => "Push main for live, staging for https://-staging. Each environment has its own RC_DATA, so its own databases; the same code, never the same data.", "show" => function (?array $me): string { // The latest push to each place: live, staging and nowhere. $latest = []; foreach (fact("pushes.json") ?? [] as $p) $latest[$p["env"]] ??= $p; $out = '" . $other; }, "check" => function (): array { $pushes = fact("pushes.json") ?? []; foreach ($pushes as $p) { // preview/* goes to -preview (the builder's loop, DECISIONS.md); anything else nowhere. $want = match (true) { $p["ref"] === "refs/heads/main" => "live", $p["ref"] === "refs/heads/staging" => "staging", str_starts_with($p["ref"], "refs/heads/preview/") => "preview", default => "nowhere" }; if ($p["env"] !== $want) return [false, "{$p['ref']} was sent to {$p['env']}"]; } $live = fact("deploy.json")["live"]["commit"] ?? ""; foreach ($pushes as $p) if ($p["env"] === "nowhere" && $p["commit"] === $live && !in_array($live, array_column(array_filter($pushes, fn($q) => $q["env"] === "live"), "commit"), true)) return [false, "a work-in-progress commit ({$p['ref']}) is what live runs"]; // Ours against the other environment's, each read through its own web address. [, , $mine] = (new Browser())->get("https://" . env("RC_HOST") . "/api/4/list"); [$code, , $theirs] = (new Browser())->get("https://" . other_env_host() . "/api/4/list"); if ($code !== 200 || !isset($theirs["instance"])) return [false, "the other environment's zoo did not answer ($code)"]; if ($theirs["instance"] === $mine["instance"]) return [false, "live and staging are the same database"]; $sig = fn($g) => json_encode(array_map(fn($x) => [$x["user"]["username"], $x["note"], $x["at"]], $g)); if ($sig($mine["guestbook"]) === $sig($theirs["guestbook"])) return [false, "the live and staging guestbooks match"]; $nowhere = count(array_filter($pushes, fn($p) => $p["env"] === "nowhere")); return [true, count($pushes) . " pushes each went where its branch says ($nowhere nowhere); " . env("RC_ENV") . " and {$theirs['env']} keep different guestbooks", ["mine" => count($mine["guestbook"]), "theirs" => count($theirs["guestbook"]), "other_env" => $theirs["env"]]]; }, ];