From 4c1d382af7f3112b586a340d92b033b936b2ba65 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 00:00:51 -0600 Subject: [PATCH] feat(pm-console): a Releases screen: what is deployed and released, and putting either out again What the owner has been doing by asking for it in a chat ("deploy the latest", "stand it up from nothing", "is the app released?") had no place in the app. More, Releases is that place. - This site: which commit Cloudflare serves and whether the laptop runs the same (from the edge's health answer), the last three deploys as GitHub records them, each a link to its run, and two buttons: "Deploy again", and "From nothing first", which has the deploy stand a throwaway copy of the Worker up from nothing, check it and remove it before deploying. - Android app: the build that is released and when it was built, a link to the release, the last builds, a download, and "Build again". - Each button asks first, saying what will happen, and starts the same workflow a merge starts, on main. Nothing else can be named: no other workflow, branch or input. Starting one is recorded, and is never held to be done late. - The runs are read through the laptop (fleet gh). With the laptop away the screen still says what is being served and what is released, and says the runs could not be read. The Phones screen no longer says GitHub signs the app: it builds it; it is signed where the key is. Checked: 196 tests pass; eight planted faults each caught; the screen opened and every button pressed in a phone-sized Chrome against the test copies; the accessibility rules pass on it in both themes (they first found its run links too small to tap, which is fixed). Not checked: a run started from the app on the laptop itself, which goes through fleet gh there. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF --- pm-stack/console/README.md | 33 ++++++-- pm-stack/console/public/app.css | 6 ++ pm-stack/console/public/app.js | 90 +++++++++++++++++++++- pm-stack/console/scripts/demo-state.ts | 38 ++++++++++ pm-stack/console/src/actions.ts | 4 + pm-stack/console/src/ops.ts | 52 +++++++++++++ pm-stack/console/src/server.ts | 2 + pm-stack/console/test/app.test.ts | 29 +++++++ pm-stack/console/test/console.test.ts | 100 +++++++++++++++++++++++++ 9 files changed, 346 insertions(+), 8 deletions(-) diff --git a/pm-stack/console/README.md b/pm-stack/console/README.md index a5293e6c71..5f1c0962e9 100644 --- a/pm-stack/console/README.md +++ b/pm-stack/console/README.md @@ -18,13 +18,13 @@ public, matched exactly: `/manifest.webmanifest` and the four icons under `/console/` is one page with five tabs. The first four are what the owner does every day; everything else is under More. -| Tab | What it is for | -| -------- | ---------------------------------------------------------------------------------------------------------------- | -| Now | Tasks in progress with their next step, sessions that are moving, and what the owner did lately | -| Next | The queue in the order it will be claimed; move a task first, sooner or later; why tasks are blocked | -| Needs me | Open questions (one tap to answer, undo for a few seconds), things only hands can do, reviews | -| Ask | Say what you want in your own words (typed or dictated). It becomes an issue and a top-of-queue task in one pass | -| More | Queue by state, pull requests, ranked issues, agents, services, notifications, phones, and the dashboard's pages | +| Tab | What it is for | +| -------- | -------------------------------------------------------------------------------------------------------------------------- | +| Now | Tasks in progress with their next step, sessions that are moving, and what the owner did lately | +| Next | The queue in the order it will be claimed; move a task first, sooner or later; why tasks are blocked | +| Needs me | Open questions (one tap to answer, undo for a few seconds), things only hands can do, reviews | +| Ask | Say what you want in your own words (typed or dictated). It becomes an issue and a top-of-queue task in one pass | +| More | Queue by state, pull requests, ranked issues, agents, services, notifications, phones, releases, and the dashboard's pages | The page never waits on a live fan-out. The server keeps three documents ready (`core`, `questions`, `ops`), each built from sections that are @@ -69,6 +69,25 @@ after run is reported once ("A unit keeps failing", with what the unit is for), and so is its mending. That is what tells the owner when the laptop's checkout has stopped following `main`. +### Releases + +More, Releases says what is out and lets either be put out again. A +merge already does both by itself; this is for looking, and for doing it +over. + +- **This site**: which commit Cloudflare serves and whether the laptop + runs the same (from the edge's health answer), and the last deploys as + GitHub records them. "Deploy again" starts the deploy workflow on + `main`; "From nothing first" has it stand a throwaway copy of the + Worker up from nothing, check it and remove it before deploying. +- **Android app**: the build that is released, the last builds, a + download, and "Build again". + +The runs are read, and a run is started, through the laptop +(`fleet gh`); with the laptop away the screen still says what is being +served and what is released. Starting one is never held to be done +late. + ### Phones The Android app's home-screen widget reads a short summary (three counts diff --git a/pm-stack/console/public/app.css b/pm-stack/console/public/app.css index 821674d8a0..e3b8d550c0 100644 --- a/pm-stack/console/public/app.css +++ b/pm-stack/console/public/app.css @@ -554,6 +554,12 @@ summary { font-size: 0.8rem; color: var(--quiet); } +/* A list of runs, each a link to its page: a line tall enough to tap. */ +.runs a { + display: block; + padding: 6px 0; + font-size: 0.88rem; +} pre { margin: 8px 0 0; padding: 10px; diff --git a/pm-stack/console/public/app.js b/pm-stack/console/public/app.js index 520ed48f92..b8a5b47d1b 100644 --- a/pm-stack/console/public/app.js +++ b/pm-stack/console/public/app.js @@ -865,6 +865,7 @@ function viewMore() { tile("more/phone", "Phones", "the Android app and its home-screen widget"), tile("more/signin", "Sign-in", "Google first, the emailed code as the fallback"), tile("more/away", "Laptop away", "what Cloudflare does by itself when the laptop cannot be reached"), + tile("more/releases", "Releases", "what is deployed, the Android app, and putting either out again"), ), ]; for (const g of ops.more || []) { @@ -1053,6 +1054,92 @@ async function viewNotify() { ]; } +// ---- releases ---------------------------------------------------------- + +const RUN_STATE = { + success: "Done", + failure: "Failed", + cancelled: "Cancelled", + timed_out: "Ran out of time", + in_progress: "Running now", + queued: "Waiting to start", +}; + +/** One run of a deploy or a build, in a line: how it stands, when it + * started, of which commit, and whether someone started it by hand. */ +export function runSaid(run, now = Date.now()) { + const state = RUN_STATE[run.state] || capital(String(run.state || "unknown").replace(/_/g, " ")); + return [state, ago(run.at, now), String(run.commit || "").slice(0, 7), run.byHand ? "started by hand" : null].filter(Boolean).join(" · "); +} + +/** What is being served, in a sentence, from the edge's health answer: + * which commit Cloudflare serves, and whether the laptop runs the same. */ +export function servingSaid(health) { + if (!health || health.edge !== true || !health.version) return "This is served straight from the laptop."; + const edge = String(health.version).slice(0, 7); + const host = health.hostVersion ? String(health.hostVersion).slice(0, 7) : null; + if (!host) return `Cloudflare is serving ${edge}. The laptop has not said what it runs.`; + if (host === edge) return `Cloudflare and the laptop are both on ${edge}.`; + return `Cloudflare is serving ${edge}; the laptop runs ${host}. After a merge the laptop follows within a minute or two.`; +} + +/** Releases: what is deployed and what is released, as Cloudflare and + * GitHub themselves say, and the buttons that put either out again. A + * merge does both by itself; this is for looking, and for doing it over. */ +async function viewReleases() { + let health = null; + try { + const res = await fetch("/console/health", { cache: "no-store" }); + health = res.ok ? await res.json() : null; + } catch { + health = null; + } + const [runs, android] = await Promise.all([api("releases").catch((error) => ({ error: error.message })), me.edge ? api("android").catch(() => null) : null]); + const list = (got) => { + if (!Array.isArray(got)) return [h("p", { class: "why" }, `Its runs could not be read: ${got?.error || runs.error || "no answer"}`)]; + if (got.length === 0) return [h("p", { class: "meta" }, "It has not run yet.")]; + return [h("div", { class: "runs" }, ...got.slice(0, 3).map((r) => ext(r.url, runSaid(r))))]; + }; + const start = (what, scratch, title, text, said) => async (e) => { + const yes = await ask({ title, text, okLabel: "Start it" }); + if (yes !== null) act("deploy.start", { what, scratch }, said, e.target); + }; + const release = android?.release || health?.androidRelease || null; + const page = `https://github.com/${me.repo || "developing-today/code"}/releases/tag/pm-console-android`; + return [ + h("h2", {}, "This site"), + card( + h("h3", {}, servingSaid(health)), + ...list(runs.site), + h( + "div", + { class: "row end" }, + h( + "button", + { + class: "small ghost", + onclick: start("site", true, "Stand it up from nothing, then deploy?", "GitHub first stands a throwaway copy of the Worker up from nothing, checks it and removes it, then deploys main to the real one. It takes a few minutes more.", "Started: from nothing first, then the deploy"), + }, + "From nothing first", + ), + h("button", { class: "small", onclick: start("site", false, "Deploy the site again?", "GitHub deploys main to Cloudflare again, checks it, and puts the last version back if the check fails.", "Deploy started") }, "Deploy again"), + ), + ), + h("h2", {}, "Android app"), + card( + h("h3", {}, release ? `Released: ${release.name}` : "No release yet"), + release ? h("p", { class: "meta" }, `Built ${ago(release.built)}. `, ext(page, "The release on GitHub")) : h("p", { class: "meta" }, "A build is released within about ten minutes of being made."), + ...list(runs.app), + h( + "div", + { class: "row end" }, + h("button", { class: "small ghost", onclick: start("app", false, "Build the app again?", "GitHub builds the app from main. It is then signed where its key is and released, within about ten minutes.", "Build started") }, "Build again"), + me.androidApp || release ? h("a", { class: "button", href: "/console/pm-console.apk" }, "Download") : null, + ), + ), + ]; +} + // ---- phones ------------------------------------------------------------ /** A request from the Android app on this phone to be linked, until it is answered. */ @@ -1346,7 +1433,7 @@ function androidNote(me, android) { const source = androidSource(me, android); if (!source) return null; if (source.by === "github") { - return h("p", { class: "meta" }, `Build ${source.name}, built, signed and released by GitHub ${ago(source.at)}. It installs over the one you have.`); + return h("p", { class: "meta" }, `Build ${source.name}, built by GitHub and released ${ago(source.at)}. It installs over the one you have.`); } return h( "p", @@ -1610,6 +1697,7 @@ const VIEWS = { "more/phone": ["Phones", viewPhone], "more/signin": ["Sign-in", viewSignin], "more/away": ["Laptop away", viewAway], + "more/releases": ["Releases", viewReleases], }; let route = "now"; let drawSeq = 0; diff --git a/pm-stack/console/scripts/demo-state.ts b/pm-stack/console/scripts/demo-state.ts index 0a9aac9f2e..8542274230 100644 --- a/pm-stack/console/scripts/demo-state.ts +++ b/pm-stack/console/scripts/demo-state.ts @@ -353,6 +353,44 @@ const demoRun: Run = async (argv) => { stderr: "", }; } + // The Releases screen: GitHub's record of the site's deploys and the + // app's builds, and a start that is taken and does nothing here. + const path = argv.find((a) => a.startsWith("repos/")) ?? ""; + if (path.includes("/actions/workflows/") && path.includes("/runs")) { + const site = path.includes("pm-console-edge-deploy.yml"); + const run = ( + id: number, + sha: string, + status: string, + conclusion: string | null, + event: string, + minutes: number, + ) => ({ + id, + head_sha: sha, + status, + conclusion, + event, + created_at: iso(minutes), + html_url: `https://github.com/developing-today/code/actions/runs/${id}`, + }); + const runs = site + ? [ + run(45120541236, "ca5c04493289cde76fa0d7f287bbd46e0395c491", "completed", "success", "push", 9), + run(45119509023, "326ac803beddb586530c6e48b76ce1db630e8aca", "completed", "success", "push", 18), + run( + 45098200037, + "2bec21c17fae00000000000000000000000000aa", + "completed", + "success", + "workflow_dispatch", + 235, + ), + ] + : [run(45118133709, "0f311ae99323955fbe908d8db814dc8de41d56f0", "completed", "success", "push", 31)]; + return { code: 0, stdout: JSON.stringify({ workflow_runs: runs }), stderr: "" }; + } + if (path.endsWith("/dispatches")) return { code: 0, stdout: "", stderr: "" }; return { code: 0, stdout: "[]", stderr: "" }; }; diff --git a/pm-stack/console/src/actions.ts b/pm-stack/console/src/actions.ts index c29563a431..957993208e 100644 --- a/pm-stack/console/src/actions.ts +++ b/pm-stack/console/src/actions.ts @@ -129,6 +129,10 @@ export function actions(ops: Ops, work: Work, push?: Push, devices?: Devices): R "issue.rank": { run: (a) => ops.setRank(a.issue, a.rank), touch: ["priorities"], audit: ids("issue", "rank") }, "issue.comment": { run: (a) => ops.comment(a.issue, a.text), touch: [], audit: ids("issue") }, "pr.merge": { run: (a) => ops.mergePr(a.pr), touch: ["prs"], audit: ids("pr") }, + // Start the site's deploy or the app's build again. Never held to + // be done late: a deploy that starts hours after it was asked for + // is a surprise. + "deploy.start": { run: (a) => ops.deploy(a.what, a.scratch), touch: [], audit: ids("what", "scratch") }, "unit.act": { run: (a) => ops.serviceAct(a.unit, a.action), touch: ["services"], diff --git a/pm-stack/console/src/ops.ts b/pm-stack/console/src/ops.ts index e6ea4c975e..a461f80aba 100644 --- a/pm-stack/console/src/ops.ts +++ b/pm-stack/console/src/ops.ts @@ -56,6 +56,8 @@ export type Rank = (typeof RANKS)[number] | "none"; const PRIORITY_PAGES = 10; export const QUEUE_STATUSES = ["queued", "claimed", "blocked", "parked"] as const; const UNIT_NAME = /^[A-Za-z0-9@._-]+\.(service|timer)$/; +/** The workflows that put the site and the app out, by what they put out. */ +const DEPLOYS = { site: "pm-console-edge-deploy.yml", app: "pm-console-android.yml" } as const; const UNIT_ACTIONS = ["start", "stop", "restart"] as const; export type UnitAction = (typeof UNIT_ACTIONS)[number]; @@ -675,6 +677,56 @@ export class Ops { return { number: n, merged: done.merged, sha: done.sha }; } + // ---- deploys and releases --------------------------------------------- + + /** What GitHub's own record says of the site's deploys and the app's + * builds: the last few runs of each on main, newest first. One that + * could not be read says so by itself; the other still shows. */ + async releases() { + const runs = async (workflow: string) => { + const got = (await this.gh([ + `repos/${this.cfg.repo}/actions/workflows/${workflow}/runs?branch=main&per_page=5`, + ])) as { + workflow_runs?: { + id: number; + head_sha: string; + status: string; + conclusion: string | null; + event: string; + created_at: string; + html_url: string; + }[]; + } | null; + return (got?.workflow_runs ?? []).map((r) => ({ + id: r.id, + commit: r.head_sha.slice(0, 12), + // Once it is over, how it ended; before that, where it is. + state: r.status === "completed" ? (r.conclusion ?? "unknown") : r.status, + byHand: r.event === "workflow_dispatch", + at: r.created_at, + url: r.html_url, + })); + }; + const part = async (p: Promise): Promise => + p.catch((e: Error) => ({ error: e.message })); + const [site, app] = await Promise.all([part(runs(DEPLOYS.site)), part(runs(DEPLOYS.app))]); + return { site, app }; + } + + /** Start the site's deploy, or the app's build, again from main: the + * same workflow a merge starts. `scratch` asks the site's deploy to + * first stand a throwaway copy up from nothing and remove it. */ + async deploy(what: unknown, scratch: unknown) { + if (what !== "site" && what !== "app") throw new OpError(400, "what: site or app"); + const fromNothing = what === "site" && scratch === true; + await this.gh(["-X", "POST", `repos/${this.cfg.repo}/actions/workflows/${DEPLOYS[what]}/dispatches`], { + ref: "main", + // GitHub takes a workflow's inputs as text. + ...(fromNothing ? { inputs: { scratch: "true" } } : {}), + }); + return { started: what, scratch: fromNothing }; + } + // ---- one screen -------------------------------------------------------- async overview() { diff --git a/pm-stack/console/src/server.ts b/pm-stack/console/src/server.ts index e7cad9f596..993c160ef2 100644 --- a/pm-stack/console/src/server.ts +++ b/pm-stack/console/src/server.ts @@ -283,6 +283,8 @@ export async function handle(req: Request, deps: Deps, peer: string | null = nul return json(await ops.services()); case "prs": return json(await ops.prs()); + case "releases": + return json(await ops.releases()); } } if (seg.length === 2 && seg[0] === "doc" && deps.docs && DOC_NAMES.includes(seg[1] as DocName)) { diff --git a/pm-stack/console/test/app.test.ts b/pm-stack/console/test/app.test.ts index 6f175a4231..3272c7010f 100644 --- a/pm-stack/console/test/app.test.ts +++ b/pm-stack/console/test/app.test.ts @@ -15,6 +15,8 @@ import { endpointMark, levelHeadings, prCheck, + runSaid, + servingSaid, subscriptionState, testSaid, } from "../public/app.js"; @@ -302,3 +304,30 @@ test("a card's title is not announced as a skipped heading level", () => { expect(levels(["H2", "H3"])).toEqual([null, null]); expect(levels([])).toEqual([]); }); + +test("a deploy or build is told in a line, and what is being served in a sentence", () => { + const NOW = Date.parse("2026-11-23T06:00:00Z"); + const run = { state: "success", at: "2026-11-23T05:51:40Z", commit: "ca5c04493289", byHand: false }; + expect(runSaid(run, NOW)).toBe("Done · 8 min ago · ca5c044"); + expect(runSaid({ ...run, state: "in_progress", byHand: true, at: "2026-11-23T05:59:30Z" }, NOW)).toBe( + "Running now · just now · ca5c044 · started by hand", + ); + expect(runSaid({ ...run, state: "failure" }, NOW)).toBe("Failed · 8 min ago · ca5c044"); + // A state this page was never told of is still said, in words. + expect(runSaid({ ...run, state: "action_required" }, NOW)).toBe("Action required · 8 min ago · ca5c044"); + expect(runSaid({ state: null, at: null, commit: null }, NOW)).toBe("Unknown"); + + expect(servingSaid({ edge: true, version: "ca5c04493289", hostVersion: "ca5c04493289" })).toBe( + "Cloudflare and the laptop are both on ca5c044.", + ); + expect(servingSaid({ edge: true, version: "ca5c04493289", hostVersion: "326ac803bedd" })).toBe( + "Cloudflare is serving ca5c044; the laptop runs 326ac80. After a merge the laptop follows within a minute or two.", + ); + expect(servingSaid({ edge: true, version: "ca5c04493289", hostVersion: null })).toBe( + "Cloudflare is serving ca5c044. The laptop has not said what it runs.", + ); + // Not behind the edge at all: said plainly, never guessed. + for (const health of [null, {}, { edge: false, version: "x" }, { edge: true }]) { + expect(servingSaid(health)).toBe("This is served straight from the laptop."); + } +}); diff --git a/pm-stack/console/test/console.test.ts b/pm-stack/console/test/console.test.ts index 3db1b4d146..e9920ecd24 100644 --- a/pm-stack/console/test/console.test.ts +++ b/pm-stack/console/test/console.test.ts @@ -27,6 +27,7 @@ import { verifyJwt, } from "../src/auth.ts"; import { type Config, ConfigError, type Issuer, readConfig } from "../src/config.ts"; +import { HOLDABLE } from "../src/edge-proto.ts"; import { manageable, OpError, Ops, parseUnitFiles, parseUnits, type Run, triagePacket } from "../src/ops.ts"; import { assetLinks, type Deps, handle } from "../src/server.ts"; @@ -403,6 +404,105 @@ const CFG: Config = readConfig({ }); describe("operations", () => { + test("deploys and builds are read from GitHub's own record, and started again from main", async () => { + // Oracle: the two answers are GitHub's own shape for a workflow's + // runs, and what is expected of them is written out by hand. + const siteRuns = { + workflow_runs: [ + { + id: 45120541236, + head_sha: "ca5c04493289cde76fa0d7f287bbd46e0395c491", + status: "completed", + conclusion: "success", + event: "push", + created_at: "2026-11-23T05:51:40Z", + html_url: "https://github.com/developing-today/code/actions/runs/45120541236", + }, + { + id: 45119999999, + head_sha: "326ac803beddb586530c6e48b76ce1db630e8aca", + status: "in_progress", + conclusion: null, + event: "workflow_dispatch", + created_at: "2026-11-23T05:42:59Z", + html_url: "https://github.com/developing-today/code/actions/runs/45119999999", + }, + ], + }; + const r = recorder((argv) => { + const path = argv.find((a) => a.startsWith("repos/")) ?? ""; + if (path.includes("pm-console-edge-deploy.yml/runs")) return JSON.stringify(siteRuns); + if (path.includes("pm-console-android.yml/runs")) return { code: 1, stderr: "HTTP 502: Bad Gateway" }; + return ""; + }); + const ops = new Ops(CFG, r.run); + const got = await ops.releases(); + expect(got.site).toEqual([ + { + id: 45120541236, + commit: "ca5c04493289", + state: "success", + byHand: false, + at: "2026-11-23T05:51:40Z", + url: "https://github.com/developing-today/code/actions/runs/45120541236", + }, + { + id: 45119999999, + commit: "326ac803bedd", + state: "in_progress", // not over: where it is, not how it ended + byHand: true, + at: "2026-11-23T05:42:59Z", + url: "https://github.com/developing-today/code/actions/runs/45119999999", + }, + ]); + // The app's runs could not be read: that is said for them alone, and the site's still show. + expect((got.app as { error: string }).error).toContain("502"); + // Only finished-or-not runs on main are asked for, a handful of each. + expect(r.calls.map((c) => c.argv.slice(1))).toEqual([ + [ + "gh", + "api", + "repos/developing-today/code/actions/workflows/pm-console-edge-deploy.yml/runs?branch=main&per_page=5", + ], + ["gh", "api", "repos/developing-today/code/actions/workflows/pm-console-android.yml/runs?branch=main&per_page=5"], + ]); + + // Starting one again is the workflow's own start, on main, and nothing else. + const w = recorder(); + const table = actions(new Ops(CFG, w.run), {} as never); + expect(await table["deploy.start"].run({ what: "site" })).toEqual({ started: "site", scratch: false }); + expect(await table["deploy.start"].run({ what: "site", scratch: true })).toEqual({ + started: "site", + scratch: true, + }); + expect(await table["deploy.start"].run({ what: "app", scratch: true })).toEqual({ started: "app", scratch: false }); + const at = (workflow: string) => [ + "gh", + "api", + "-X", + "POST", + `repos/developing-today/code/actions/workflows/${workflow}/dispatches`, + "--input", + "-", + ]; + expect(w.calls.map((c) => [c.argv.slice(1), JSON.parse(c.stdin ?? "null")])).toEqual([ + [at("pm-console-edge-deploy.yml"), { ref: "main" }], + [at("pm-console-edge-deploy.yml"), { ref: "main", inputs: { scratch: "true" } }], + [at("pm-console-android.yml"), { ref: "main" }], // the app's build has no such input + ]); + // Anything else is refused before GitHub is asked: no other workflow, branch or input can be named. + for (const what of ["pm-dispatch.yml", "../x", "", null, { site: true }, "SITE"]) { + await expect(table["deploy.start"].run({ what })).rejects.toThrow(/site or app/); + } + expect(w.calls.length).toBe(3); + // What is recorded of it is which of the two, and whether from nothing; and it is never held to be done late. + expect(table["deploy.start"].audit({ what: "site", scratch: true, extra: "x" })).toEqual({ + what: "site", + scratch: true, + }); + expect(HOLDABLE.has("deploy.start")).toBe(false); + }); + test("queue actions run the fleet verb with the reason as one argument", async () => { const r = recorder(); const ops = new Ops(CFG, r.run);