Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/client/src/ci.ts?version=261&format=json
164 linesFirst import 96% · groups 2% · onboard 1% · review 1%Last change groups in version 257, 4 versions changed it

You're reading version 261. The newest is 318, and 1 version since then changed this file. Go to the newestCompare with 318

1// What the project's CI says (#39): the server runs abso.json's setup, build
2// and check on each new version of shared. status and log show it; abso ci
3// shows it whole, and one version's job with the end of its output.
4
5import { ApiError, type CiJob, type CiMark, type CiStatus } from "./api.ts";
6import { bool, type Parsed, str, UsageError } from "./args.ts";
7import { type Env, type Output, open, plural } from "./commands.ts";
8import { when } from "./history.ts";
9
10/** Seconds since an ISO time, as "35 s" or "4 min". */
11function ago(iso: string, now: number): string {
12 const s = Math.max(0, Math.round((now - Date.parse(iso)) / 1000));
13 return s < 120 ? `${s} s` : `${Math.round(s / 60)} min`;
16/** An ISO time as HH:MM UTC, with the date when it isn't today. */
17function clock(iso: string, now: number): string {
18 const t = new Date(iso).toISOString();
19 return t.slice(0, 10) === new Date(now).toISOString().slice(0, 10)
20 ? `${t.slice(11, 16)} UTC`
21 : `${t.slice(0, 16).replace("T", " ")} UTC`;
24/** The lines status shows about CI: is shared green or red, and where the preview is. Nothing from a server without CI. */
25export function ciText(ci: CiStatus | undefined, shared: number, now = Date.now()): string[] {
26 if (ci === undefined) return [];
27 const lines: string[] = [];
28 const running =
29 ci.running === null
30 ? ""
31 : ` Version ${ci.running.version} is being checked (${ago(ci.running.since, now)} so far${ci.running.bisect ? ", a bisect step" : ""}).`;
32 const red = ci.red;
33 if (red !== null) {
34 if (red.bisecting) {
35 lines.push(
36 `Shared is red: version ${red.version} fails its check, and CI is bisecting for the version that broke it${red.lastGood === null ? "" : ` (version ${red.lastGood} passed)`}.${running}`,
37 );
38 } else if (red.agent !== null) {
39 lines.push(
40 `Shared is red since version ${red.version}, by ${red.agent}${red.message === null ? "" : ` ("${red.message}")`}${red.lastGood === null ? "" : `; version ${red.lastGood} was the last to pass`}. abso ci ${red.version} shows why.${running}`,
41 );
42 } else {
43 lines.push(
44 `Shared is red: version ${red.version} fails its check${red.lastGood === null ? ", and no version has passed yet" : `; version ${red.lastGood} was the last to pass`}. abso ci ${red.version} shows why.${running}`,
45 );
46 }
47 } else if (ci.checked !== null) {
48 const v = ci.checked.version;
49 // Newer versions with no job running: skipped (said below) or not reached yet.
50 const newer =
51 shared > v ? (ci.running !== null ? running : ci.skipped ? "" : ` Versions after ${v} aren't checked yet.`) : "";
52 if (ci.checked.result === "pass") lines.push(`Shared is green: version ${v} passed its check.${newer}`);
53 else if (ci.checked.result === "fail") lines.push(`Version ${v} failed its check. abso ci ${v} shows why.${newer}`);
54 else
55 lines.push(
56 `CI couldn't check version ${v} (the box failed twice, or the pipeline file has nothing to run).${newer}`,
57 );
58 } else {
59 lines.push(
60 ci.running === null
61 ? "Not checked yet: CI has not finished a job on this project."
62 : `Not checked yet.${running}`,
63 );
64 }
65 // Not running, and not queued either (#39, GAME - CEO: "aren't checked yet" read as queued while CI was off).
66 if (ci.skipped) {
67 const s = ci.skipped;
68 lines.push(
69 `CI didn't run ${s.from < s.version ? `versions ${s.from}-${s.version}` : `version ${s.version}`}: ${s.reason}. ${s.from < s.version ? "They" : "It"} won't be checked unless a later version's job covers ${s.from < s.version ? "them" : "it"}.`,
70 );
71 }
72 if (ci.waiting) lines.push(`CI is waiting: ${ci.waiting.reason}; next try ${clock(ci.waiting.until, now)}.`);
73 if (ci.latest?.url) {
74 const behind =
75 ci.behind === null || ci.behind === 0 ? "shared itself" : `${plural(ci.behind, "version")} behind shared`;
76 lines.push(
77 `Preview of the newest passing build (version ${ci.latest.version}, ${behind}), no token needed: ${ci.latest.url}`,
78 );
79 }
80 return lines;
83/** A shared version's mark in abso log; "not checked" says nothing, since most versions in a busy hour are covered by a newer one's job. */
84export function ciMarkText(mark: CiMark | undefined): string {
85 switch (mark) {
86 case "pass":
87 return ", check passed";
88 case "fail":
89 return ", check FAILED";
90 case "running":
91 return ", being checked";
92 case "waiting":
93 return ", waiting for CI";
94 default:
95 return "";
96 }
99function jobText(job: CiJob): string[] {
100 if (job.result === "running") return [`Version ${job.version} is being checked now.`];
101 if (job.result === "waiting") return [`Version ${job.version} isn't checked yet: CI hasn't reached it.`];
102 if (job.result === "not checked")
103 return [
104 `Version ${job.version} had no job of its own: a newer version's job covered it, or none ran. abso bisect checks it in your box.`,
105 ];
106 const covered =
107 job.from !== undefined && job.from < job.version ? ` (standing in for versions ${job.from}-${job.version})` : "";
108 const took = [
109 job.seconds === undefined ? "" : `${job.seconds} s`,
110 job.cold ? "cold box" : "",
111 job.bisect ? "a bisect step" : "",
112 ]
113 .filter((w) => w !== "")
114 .join(", ");
115 const head =
116 job.result === "pass"
117 ? `Version ${job.version} passed${covered}${took === "" ? "" : ` (${took})`}${job.built ? "; its build is kept for the preview" : ""}.`
118 : job.result === "fail"
119 ? `Version ${job.version} failed at ${job.step ?? "a step"}${job.exit === undefined || job.exit === null ? "" : ` (exit ${job.exit})`}${covered}${took === "" ? "" : `, ${took}`}.`
120 : `Version ${job.version} wasn't checked${job.step === undefined ? "" : ` (${job.step})`}: the box failed twice, or the pipeline file has nothing to run.`;
121 const output = job.output?.trimEnd() ?? "";
122 return [
123 head,
124 ...(output === "" ? [] : [`The end of its output${job.at ? `, ${when(Date.parse(job.at))}` : ""}:`, output]),
125 ];
128export async function runCi(args: Parsed, env: Env): Promise<Output> {
129 if (args.positionals.length > 1)
130 throw new UsageError("ci takes at most one version: abso ci [<version>] | abso ci --revoke");
131 const { api } = open(env);
132 const typed = args.positionals[0] ?? str(args, "version");
133 try {
134 if (bool(args, "revoke")) {
135 if (typed !== undefined) throw new UsageError("--revoke takes no version");
136 const ci = await api.ciRevoke();
137 return {
138 text: [
139 `Every preview link handed out so far is ended.${ci.latest?.url ? ` The new one: ${ci.latest.url}` : " A new one comes with the next passing build."}`,
140 ].join("\n"),
141 json: { ...ci },
142 };
143 }
144 if (typed !== undefined) {
145 if (!/^\d+$/.test(typed)) throw new UsageError(`a version is a number (got ${JSON.stringify(typed)})`);
146 const job = await api.ci(Number(typed));
147 return { text: jobText(job).join("\n"), json: { ...job } };
148 }
149 const [ci, status] = await Promise.all([api.ci(), api.status()]);
150 const lines = ciText(ci, status.version);
151 return {
152 text: [
153 `shared is at version ${status.version}.`,
154 ...lines,
155 "abso ci <version> shows one version's job and the end of its output.",
156 ].join("\n"),
157 json: { ...ci, version: status.version },
158 };
159 } catch (e) {
160 if (e instanceof ApiError && e.status === 404)
161 throw new ApiError("this server has no CI yet (#39); abso serve still builds a preview of a version", 404);
162 throw e;
163 }