@intentius/chant 0.124.29 → 0.124.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +4 -1
- package/dist/cli/handlers/fan-out.d.ts.map +1 -1
- package/dist/cli/handlers/fan-out.js +27 -5
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +64 -0
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +99 -0
- package/dist/cli/registry.d.ts +35 -1
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/pr-pipeline.d.ts +24 -0
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +16 -0
- package/dist/components/pr-run.d.ts +20 -2
- package/dist/components/pr-run.d.ts.map +1 -1
- package/dist/components/pr-run.js +26 -13
- package/dist/components/wave-plan.d.ts +11 -0
- package/dist/components/wave-plan.d.ts.map +1 -1
- package/dist/components/wave-plan.js +26 -0
- package/dist/lifecycle/release-ledger.d.ts +8 -3
- package/dist/lifecycle/release-ledger.d.ts.map +1 -1
- package/dist/lifecycle/release-ledger.js +2 -0
- package/dist/lifecycle/run-ledger.d.ts +1 -1
- package/dist/lifecycle/run-ledger.d.ts.map +1 -1
- package/dist/lifecycle/run-ledger.js +9 -0
- package/dist/op/activities/activity-contracts.d.ts +1 -0
- package/dist/op/activities/activity-contracts.d.ts.map +1 -1
- package/dist/op/activities/activity-contracts.js +1 -0
- package/dist/op/activities/shell.d.ts +6 -0
- package/dist/op/activities/shell.d.ts.map +1 -1
- package/dist/op/activities/shell.js +1 -1
- package/dist/op/local-executor.d.ts +35 -1
- package/dist/op/local-executor.d.ts.map +1 -1
- package/dist/op/local-executor.js +31 -6
- package/dist/op/redact.d.ts +34 -0
- package/dist/op/redact.d.ts.map +1 -0
- package/dist/op/redact.js +94 -0
- package/dist/op/runtime.d.ts +27 -0
- package/dist/op/runtime.d.ts.map +1 -1
- package/dist/op/runtime.js +20 -0
- package/dist/op/step-console.d.ts +2 -0
- package/dist/op/step-console.d.ts.map +1 -1
- package/dist/op/step-console.js +5 -2
- package/dist/pr-forge.d.ts +40 -0
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +56 -6
- package/dist/pr-loop.d.ts +10 -0
- package/dist/pr-loop.d.ts.map +1 -1
- package/dist/pr-loop.js +7 -0
- package/dist/pr-report-url.d.ts +8 -0
- package/dist/pr-report-url.d.ts.map +1 -1
- package/dist/pr-report-url.js +47 -1
- package/dist/run-event-stream.d.ts +2 -2
- package/dist/run-event-stream.d.ts.map +1 -1
- package/dist/run-event-stream.js +2 -2
- package/dist/run-event.d.ts +15 -0
- package/dist/run-event.d.ts.map +1 -1
- package/dist/run-event.js +2 -0
- package/dist/wave-runtime.mjs +171 -171
- package/dist/workspace/ci-green-forge.d.ts +2 -0
- package/dist/workspace/ci-green-forge.d.ts.map +1 -1
- package/dist/workspace/ci-green.d.ts +2 -0
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +4 -2
- package/dist/workspace/ci-run-index.d.ts +96 -0
- package/dist/workspace/ci-run-index.d.ts.map +1 -0
- package/dist/workspace/ci-run-index.js +162 -0
- package/dist/workspace/ci-run-index.schema.json +50 -0
- package/dist/workspace/ci-run.d.ts +299 -0
- package/dist/workspace/ci-run.d.ts.map +1 -0
- package/dist/workspace/ci-run.js +691 -0
- package/dist/workspace/ci-runner-key.d.ts +120 -0
- package/dist/workspace/ci-runner-key.d.ts.map +1 -0
- package/dist/workspace/ci-runner-key.js +217 -0
- package/dist/workspace/ci-secrets.d.ts +65 -0
- package/dist/workspace/ci-secrets.d.ts.map +1 -0
- package/dist/workspace/ci-secrets.js +211 -0
- package/dist/workspace/ci-serve.d.ts +227 -0
- package/dist/workspace/ci-serve.d.ts.map +1 -0
- package/dist/workspace/ci-serve.js +468 -0
- package/dist/workspace/pr-report.schema.json +5 -0
- package/dist/workspace/reason-codes.d.ts +6 -2
- package/dist/workspace/reason-codes.d.ts.map +1 -1
- package/dist/workspace/reason-codes.js +7 -2
- package/dist/workspace/run-event.schema.json +14 -3
- package/dist/workspace/status-stewards.d.ts +2 -0
- package/dist/workspace/status-stewards.d.ts.map +1 -1
- package/dist/workspace/status-stewards.js +1 -0
- package/dist/workspace/status.schema.json +12 -1
- package/dist/workspace/trust/trust-write.d.ts +109 -0
- package/dist/workspace/trust/trust-write.d.ts.map +1 -0
- package/dist/workspace/trust/trust-write.js +320 -0
- package/dist/workspace/trust-write.schema.json +265 -0
- package/package.json +1 -1
- package/src/cli/handlers/build.test.ts +15 -0
- package/src/cli/handlers/build.ts +4 -1
- package/src/cli/handlers/fan-out.test.ts +82 -0
- package/src/cli/handlers/fan-out.ts +34 -5
- package/src/cli/handlers/pr.ts +5 -0
- package/src/cli/main.test.ts +1 -0
- package/src/cli/main.ts +64 -0
- package/src/cli/parse-args.ts +71 -0
- package/src/cli/registry.ts +35 -1
- package/src/components/pr-pipeline.ts +32 -0
- package/src/components/pr-run.test.ts +127 -0
- package/src/components/pr-run.ts +32 -12
- package/src/components/wave-plan.ts +30 -0
- package/src/lifecycle/release-ledger.ts +9 -3
- package/src/lifecycle/run-ledger.ts +7 -1
- package/src/op/activities/activity-contracts.ts +1 -0
- package/src/op/activities/shell.ts +7 -1
- package/src/op/local-executor.ts +58 -7
- package/src/op/redact.ts +93 -0
- package/src/op/runtime.ts +42 -0
- package/src/op/step-console.ts +7 -2
- package/src/pr-forge.test.ts +54 -0
- package/src/pr-forge.ts +92 -6
- package/src/pr-loop.test.ts +13 -1
- package/src/pr-loop.ts +16 -0
- package/src/pr-report-url.ts +53 -1
- package/src/run-event-stream.ts +4 -3
- package/src/run-event.ts +17 -0
- package/src/workspace/ci-green-forge.ts +2 -0
- package/src/workspace/ci-green.ts +6 -2
- package/src/workspace/ci-run-index.schema.json +50 -0
- package/src/workspace/ci-run-index.test.ts +353 -0
- package/src/workspace/ci-run-index.ts +192 -0
- package/src/workspace/ci-run.test.ts +716 -0
- package/src/workspace/ci-run.ts +833 -0
- package/src/workspace/ci-runner-key.test.ts +166 -0
- package/src/workspace/ci-runner-key.ts +250 -0
- package/src/workspace/ci-secrets.test.ts +106 -0
- package/src/workspace/ci-secrets.ts +213 -0
- package/src/workspace/ci-serve.test.ts +367 -0
- package/src/workspace/ci-serve.ts +574 -0
- package/src/workspace/pr-report.schema.json +5 -0
- package/src/workspace/reason-codes.test.ts +2 -0
- package/src/workspace/reason-codes.ts +7 -2
- package/src/workspace/run-event.schema.json +14 -3
- package/src/workspace/status-stewards.ts +3 -0
- package/src/workspace/status.schema.json +12 -1
- package/src/workspace/trust/trust-write.test.ts +179 -0
- package/src/workspace/trust/trust-write.ts +377 -0
- package/src/workspace/trust-write.schema.json +265 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The run index (#4098, epic #4101): where the chant runner says which jobs it
|
|
3
|
+
* ran, at the `--report-url` root, for behold and the demo kiosk to find runs
|
|
4
|
+
* without a forge or a workflow file.
|
|
5
|
+
*
|
|
6
|
+
* ```
|
|
7
|
+
* <url>/runs/index.json
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* One document, `ci-run-index/v1` (`ci-run-index.schema.json`). Each settled
|
|
11
|
+
* `chant ci run` job with `--report-url` set adds an entry to its front, so
|
|
12
|
+
* the newest run is first, and the list is cut to the newest `limit` entries,
|
|
13
|
+
* 200 by default. An entry's `key` is the folder the job's report went to
|
|
14
|
+
* (`reportKey`, `<pr>/<commit>`), so a reader goes from the index to
|
|
15
|
+
* `<url>/<key>/pr-<job>.json`.
|
|
16
|
+
*
|
|
17
|
+
* The update reads the index, changes it and writes it back through the same
|
|
18
|
+
* `file://` and `s3://` paths the report upload uses (pr-report-url.ts). A
|
|
19
|
+
* `file://` write goes through a temporary name and a rename. Two runners
|
|
20
|
+
* updating one index at once can lose an entry, and that is out of scope:
|
|
21
|
+
* `chant ci serve` is one host. Within one process the updates for one URL
|
|
22
|
+
* take turns, so `ci serve --max-jobs 2` does not race itself.
|
|
23
|
+
*
|
|
24
|
+
* An index that can't be parsed is replaced with a warning. An index this
|
|
25
|
+
* chant can't read for any other reason, or a newer contract, is left alone
|
|
26
|
+
* with a warning. Nothing here fails a job.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import type { RunOrigin } from "../lifecycle/release-ledger";
|
|
30
|
+
import type { CommandContext } from "../cli/registry";
|
|
31
|
+
import { formatError } from "../cli/format";
|
|
32
|
+
import { parseReportUrl, reportGet, reportPut, type ReportGet, type ReportPut, type ReportTarget } from "../pr-report-url";
|
|
33
|
+
import { readerVersion } from "./declaration";
|
|
34
|
+
|
|
35
|
+
export const CI_RUN_INDEX_SCHEMA_ID = "https://intentius.io/chant/schemas/workspace/ci-run-index/v1/ci-run-index.schema.json";
|
|
36
|
+
export const CI_RUN_INDEX_CONTRACT = 1;
|
|
37
|
+
/** The first chant that writes the index. */
|
|
38
|
+
export const CI_RUN_INDEX_FLOOR = "0.124.31";
|
|
39
|
+
/** Where the index is kept, below the report URL. */
|
|
40
|
+
export const CI_RUN_INDEX_KEY = "runs/index.json";
|
|
41
|
+
/** How many entries the index keeps unless told otherwise. */
|
|
42
|
+
export const CI_RUN_INDEX_LIMIT = 200;
|
|
43
|
+
|
|
44
|
+
/** One job the runner ran. */
|
|
45
|
+
export interface CiRunIndexEntry {
|
|
46
|
+
job: "plan" | "apply";
|
|
47
|
+
/** The pull request, or null when the job found none. */
|
|
48
|
+
pr: number | null;
|
|
49
|
+
commit: string;
|
|
50
|
+
status: "ok" | "fail";
|
|
51
|
+
/** Why a failed job failed: the `failure.code` of its run record. */
|
|
52
|
+
failure?: { code: string };
|
|
53
|
+
member?: string;
|
|
54
|
+
started: string;
|
|
55
|
+
ended: string;
|
|
56
|
+
runId: string;
|
|
57
|
+
/** The folder the job's report is under, below the report URL: `<pr>/<commit>[/<member>]`. */
|
|
58
|
+
key: string;
|
|
59
|
+
runOrigin: RunOrigin;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface CiRunIndex {
|
|
63
|
+
$schema: typeof CI_RUN_INDEX_SCHEMA_ID;
|
|
64
|
+
contract: typeof CI_RUN_INDEX_CONTRACT;
|
|
65
|
+
chant: string;
|
|
66
|
+
/** When the index was last written. */
|
|
67
|
+
updated: string;
|
|
68
|
+
/** Newest first. */
|
|
69
|
+
runs: CiRunIndexEntry[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const messageOf = (err: unknown): string => (err instanceof Error ? err.message : String(err));
|
|
73
|
+
|
|
74
|
+
/** The index as `text` holds it, or why it can't be used: `corrupt` is replaced, `newer` is left alone. */
|
|
75
|
+
export function parseCiRunIndex(text: string): { index: CiRunIndex } | { corrupt: string } | { newer: number } {
|
|
76
|
+
let doc: unknown;
|
|
77
|
+
try {
|
|
78
|
+
doc = JSON.parse(text);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
return { corrupt: `it is not JSON (${messageOf(err)})` };
|
|
81
|
+
}
|
|
82
|
+
if (doc === null || typeof doc !== "object" || Array.isArray(doc)) return { corrupt: "it is not an object" };
|
|
83
|
+
const d = doc as { contract?: unknown; runs?: unknown };
|
|
84
|
+
if (typeof d.contract === "number" && d.contract > CI_RUN_INDEX_CONTRACT) return { newer: d.contract };
|
|
85
|
+
if (d.contract !== CI_RUN_INDEX_CONTRACT) return { corrupt: "it is not a ci-run-index document" };
|
|
86
|
+
if (!Array.isArray(d.runs)) return { corrupt: "it has no runs list" };
|
|
87
|
+
const runs = d.runs.filter((r): r is CiRunIndexEntry => r !== null && typeof r === "object" && typeof (r as { runId?: unknown }).runId === "string");
|
|
88
|
+
return { index: { ...(doc as CiRunIndex), runs } };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** `entry` at the front of `runs`, replacing an entry with its run id, cut to the newest `limit`. */
|
|
92
|
+
export function addRunEntry(runs: readonly CiRunIndexEntry[], entry: CiRunIndexEntry, limit: number): CiRunIndexEntry[] {
|
|
93
|
+
return [entry, ...runs.filter((r) => r.runId !== entry.runId)].slice(0, limit);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The turn each index URL is waiting for, so updates in one process run one after another. */
|
|
97
|
+
const turns = new Map<string, Promise<void>>();
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Add `entry` to the index at `target`. Never throws: a problem is a warning
|
|
101
|
+
* and the index stays as it was, or is replaced when it was unreadable JSON.
|
|
102
|
+
*/
|
|
103
|
+
export function updateCiRunIndex(input: {
|
|
104
|
+
target: ReportTarget;
|
|
105
|
+
entry: CiRunIndexEntry;
|
|
106
|
+
limit?: number;
|
|
107
|
+
warn: (message: string) => void;
|
|
108
|
+
now?: () => Date;
|
|
109
|
+
put?: ReportPut;
|
|
110
|
+
get?: ReportGet;
|
|
111
|
+
}): Promise<void> {
|
|
112
|
+
const where = `${input.target.url}/${CI_RUN_INDEX_KEY}`;
|
|
113
|
+
const put = input.put ?? reportPut(input.target);
|
|
114
|
+
const get = input.get ?? reportGet(input.target);
|
|
115
|
+
const limit = Math.max(1, Math.floor(input.limit ?? CI_RUN_INDEX_LIMIT));
|
|
116
|
+
const work = async (): Promise<void> => {
|
|
117
|
+
let runs: CiRunIndexEntry[] = [];
|
|
118
|
+
try {
|
|
119
|
+
const text = await get(CI_RUN_INDEX_KEY);
|
|
120
|
+
if (text !== null) {
|
|
121
|
+
const parsed = parseCiRunIndex(text);
|
|
122
|
+
if ("corrupt" in parsed) input.warn(`the run index at ${where} is replaced, since ${parsed.corrupt}`);
|
|
123
|
+
else if ("newer" in parsed) return input.warn(`the run index at ${where} is contract ${parsed.newer}, which this chant does not write; it is left as it is`);
|
|
124
|
+
else runs = parsed.index.runs;
|
|
125
|
+
}
|
|
126
|
+
} catch (err) {
|
|
127
|
+
return input.warn(`could not read the run index at ${where}, so it is not updated: ${messageOf(err)}`);
|
|
128
|
+
}
|
|
129
|
+
const index: CiRunIndex = {
|
|
130
|
+
$schema: CI_RUN_INDEX_SCHEMA_ID,
|
|
131
|
+
contract: CI_RUN_INDEX_CONTRACT,
|
|
132
|
+
chant: readerVersion(),
|
|
133
|
+
updated: (input.now?.() ?? new Date()).toISOString(),
|
|
134
|
+
runs: addRunEntry(runs, input.entry, limit),
|
|
135
|
+
};
|
|
136
|
+
try {
|
|
137
|
+
await put(CI_RUN_INDEX_KEY, JSON.stringify(index, null, 2) + "\n", "application/json");
|
|
138
|
+
} catch (err) {
|
|
139
|
+
input.warn(`could not write the run index at ${where}: ${messageOf(err)}`);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const previous = turns.get(where) ?? Promise.resolve();
|
|
143
|
+
const next = previous.then(work, work);
|
|
144
|
+
const settled = next.catch(() => undefined);
|
|
145
|
+
turns.set(where, settled);
|
|
146
|
+
void settled.then(() => {
|
|
147
|
+
if (turns.get(where) === settled) turns.delete(where);
|
|
148
|
+
});
|
|
149
|
+
return next.catch((err) => input.warn(`could not update the run index at ${where}: ${messageOf(err)}`));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** The index at `target`, or null when none is there. Throws a line a person can read when it can't be read. */
|
|
153
|
+
export async function readCiRunIndex(target: ReportTarget, get: ReportGet = reportGet(target)): Promise<CiRunIndex | null> {
|
|
154
|
+
const where = `${target.url}/${CI_RUN_INDEX_KEY}`;
|
|
155
|
+
const text = await get(CI_RUN_INDEX_KEY);
|
|
156
|
+
if (text === null) return null;
|
|
157
|
+
const parsed = parseCiRunIndex(text);
|
|
158
|
+
if ("corrupt" in parsed) throw new Error(`the run index at ${where} is unusable: ${parsed.corrupt}`);
|
|
159
|
+
if ("newer" in parsed) throw new Error(`the run index at ${where} is contract ${parsed.newer}; this chant reads contract ${CI_RUN_INDEX_CONTRACT}`);
|
|
160
|
+
return parsed.index;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** The text `chant ci runs` prints: one line per run, newest first. */
|
|
164
|
+
export function formatCiRunIndex(index: CiRunIndex): string {
|
|
165
|
+
if (index.runs.length === 0) return "no runs in the index";
|
|
166
|
+
return index.runs
|
|
167
|
+
.map((r) => {
|
|
168
|
+
const pr = r.pr === null ? "no PR" : `PR ${r.pr}`;
|
|
169
|
+
const why = r.status === "fail" ? ` (${r.failure?.code ?? "failed"})` : "";
|
|
170
|
+
return `${r.ended} ${r.job.padEnd(5)} ${r.status}${why} ${pr} ${r.commit.slice(0, 12)} ${r.runId} ${r.key}`;
|
|
171
|
+
})
|
|
172
|
+
.join("\n");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const RUNS_USAGE = "chant ci runs --report-url <s3://<bucket>/<prefix> | file://<directory>> [--json]";
|
|
176
|
+
|
|
177
|
+
/** `chant ci runs` (#4098): list the index at the report URL. */
|
|
178
|
+
export async function runCiRuns(ctx: CommandContext): Promise<number> {
|
|
179
|
+
try {
|
|
180
|
+
const raw = ctx.args.reportUrl;
|
|
181
|
+
if (!raw) throw new Error("--report-url names where the index is kept");
|
|
182
|
+
const target = parseReportUrl(raw);
|
|
183
|
+
if ("error" in target) throw new Error(target.error);
|
|
184
|
+
const index = await readCiRunIndex(target);
|
|
185
|
+
if (index === null) throw new Error(`there is no run index at ${target.url}/${CI_RUN_INDEX_KEY}`);
|
|
186
|
+
console.log(ctx.args.json ? JSON.stringify(index, null, 2) : formatCiRunIndex(index));
|
|
187
|
+
return 0;
|
|
188
|
+
} catch (err) {
|
|
189
|
+
console.error(formatError({ message: `chant ci runs: ${messageOf(err)}`, hint: RUNS_USAGE }));
|
|
190
|
+
return 1;
|
|
191
|
+
}
|
|
192
|
+
}
|