Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions pm-stack/console/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pm-stack/console/public/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
90 changes: 89 additions & 1 deletion pm-stack/console/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || []) {
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down
38 changes: 38 additions & 0 deletions pm-stack/console/scripts/demo-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "" };
};

Expand Down
4 changes: 4 additions & 0 deletions pm-stack/console/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
52 changes: 52 additions & 0 deletions pm-stack/console/src/ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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 <T>(p: Promise<T>): Promise<T | { error: string }> =>
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() {
Expand Down
2 changes: 2 additions & 0 deletions pm-stack/console/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
29 changes: 29 additions & 0 deletions pm-stack/console/test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
endpointMark,
levelHeadings,
prCheck,
runSaid,
servingSaid,
subscriptionState,
testSaid,
} from "../public/app.js";
Expand Down Expand Up @@ -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.");
}
});
Loading