@intentius/chant 0.124.37 → 0.124.39
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/components.d.ts.map +1 -1
- package/dist/cli/handlers/components.js +1 -0
- package/dist/cli/handlers/graph.js +5 -1
- package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle.js +2 -1
- package/dist/cli/handlers/scenario.d.ts.map +1 -1
- package/dist/cli/handlers/scenario.js +1 -0
- package/dist/cli/handlers/search.d.ts.map +1 -1
- package/dist/cli/handlers/search.js +3 -1
- package/dist/lifecycle/observe.d.ts +3 -0
- package/dist/lifecycle/observe.d.ts.map +1 -1
- package/dist/lifecycle/observe.js +1 -1
- package/dist/wave-runtime.mjs +189 -189
- package/dist/workspace/ci-builds.d.ts +12 -1
- package/dist/workspace/ci-builds.d.ts.map +1 -1
- package/dist/workspace/ci-builds.js +26 -0
- package/dist/workspace/ci-green-cli.js +1 -1
- package/dist/workspace/ci-green-forge.d.ts +3 -1
- package/dist/workspace/ci-green-forge.d.ts.map +1 -1
- package/dist/workspace/ci-green-forge.js +20 -2
- package/dist/workspace/ci-green-workflow.d.ts +6 -4
- package/dist/workspace/ci-green-workflow.d.ts.map +1 -1
- package/dist/workspace/ci-green-workflow.js +26 -8
- package/package.json +1 -1
- package/src/cli/handlers/components.ts +1 -0
- package/src/cli/handlers/graph.test.ts +17 -0
- package/src/cli/handlers/graph.ts +4 -1
- package/src/cli/handlers/lifecycle.ts +2 -1
- package/src/cli/handlers/scenario.ts +1 -0
- package/src/cli/handlers/search.ts +3 -1
- package/src/lifecycle/observe.test.ts +14 -1
- package/src/lifecycle/observe.ts +4 -1
- package/src/workspace/ci-builds.e2e.test.ts +7 -2
- package/src/workspace/ci-builds.test.ts +46 -1
- package/src/workspace/ci-builds.ts +25 -1
- package/src/workspace/ci-green-builds.test.ts +26 -0
- package/src/workspace/ci-green-cli.ts +1 -1
- package/src/workspace/ci-green-forge.test.ts +31 -0
- package/src/workspace/ci-green-forge.ts +21 -3
- package/src/workspace/ci-green-workflow.test.ts +4 -4
- package/src/workspace/ci-green-workflow.ts +22 -8
|
@@ -158,6 +158,32 @@ describe("the tick for a newest phase (#4169)", () => {
|
|
|
158
158
|
});
|
|
159
159
|
});
|
|
160
160
|
|
|
161
|
+
describe("the tick for a missing every phase (#4216)", () => {
|
|
162
|
+
const CHECK_WORKFLOW = "name: ci\non:\n push:\n branches: [main]\n workflow_dispatch: {}\njobs:\n check:\n runs-on: ubuntu-latest\n steps:\n - run: true\n";
|
|
163
|
+
|
|
164
|
+
test("a commit the forge never ran check on gets one request, started at its ci/build tag, and the record keeps it", async () => {
|
|
165
|
+
const { root, origin } = workspace();
|
|
166
|
+
writeFiles(root, { ".github/workflows/ci.yml": CHECK_WORKFLOW });
|
|
167
|
+
const a = commitAt(root, 2, "app/a.txt");
|
|
168
|
+
git(root, "push", "-q", "origin", "main");
|
|
169
|
+
// GitHub skipped a's push run of ci.yml; release-suites ran.
|
|
170
|
+
const runs = new Map([[a, [run("suites", "success")]]]);
|
|
171
|
+
const forge = fakeForge(runs);
|
|
172
|
+
const tick = await ciTick({ cwd: root, forge, now: NOW });
|
|
173
|
+
expect(tick.requested.map((r) => [r.commit, r.phases, r.reason])).toEqual([[a, ["check"], "missing"]]);
|
|
174
|
+
expect(forge.dispatched).toEqual([`ci.yml@ci/build/${a}`]);
|
|
175
|
+
expect(remoteTags(origin)).toEqual([`ci/build/${a}`]);
|
|
176
|
+
expect(remoteRecord(origin, a)).toMatchObject({ state: "pending", missing: { phases: ["check"] }, request: { reason: "missing", dispatched: true }, phases: { check: { reason: "requested" } } });
|
|
177
|
+
|
|
178
|
+
// The started run passes: the commit goes green and the request is done.
|
|
179
|
+
runs.set(a, [run("suites", "success"), run("check", "success")]);
|
|
180
|
+
const second = await ciTick({ cwd: root, forge, now: NOW });
|
|
181
|
+
expect(second.made).toEqual([`ci/green/${a}`]);
|
|
182
|
+
expect(second.requested).toEqual([]);
|
|
183
|
+
expect(forge.dispatched).toHaveLength(1);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
161
187
|
describe("chant ci run --at (#4169)", () => {
|
|
162
188
|
test("pushes a request for every required phase and starts the workflows holding them", async () => {
|
|
163
189
|
const { root, origin } = workspace();
|
|
@@ -192,7 +192,7 @@ export async function runCiWorkflow(ctx: CommandContext): Promise<number> {
|
|
|
192
192
|
console.log(
|
|
193
193
|
e.build === "newest"
|
|
194
194
|
? `Wrote ${path}'s triggers and concurrency: ${e.phases.join(", ")} build${e.phases.length === 1 ? "s" : ""} the newest commit on ${green.branch} when a run ends, and a ci/build/<sha> tag by hand.`
|
|
195
|
-
: `Wrote ${path}'s concurrency: ${e.phases.join(", ")} build${e.phases.length === 1 ? "s" : ""} every commit on ${green.branch}, none cancelled.`,
|
|
195
|
+
: `Wrote ${path}'s triggers and concurrency: ${e.phases.join(", ")} build${e.phases.length === 1 ? "s" : ""} every commit on ${green.branch}, none cancelled, and a ci/build/<sha> tag by hand when the forge ran nothing.`,
|
|
196
196
|
);
|
|
197
197
|
}
|
|
198
198
|
return 0;
|
|
@@ -64,3 +64,34 @@ describe("the GitHub check-run client (#3573)", () => {
|
|
|
64
64
|
expect(() => ciForgeFromEnv("forgejo", {})).toThrow(/GitHub only/);
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
|
+
|
|
68
|
+
describe("re-running a failed check run (#4219)", () => {
|
|
69
|
+
const run = (id: number) => ({ id, name: "suites", status: "completed", conclusion: "failure", completedAt: null, url: null });
|
|
70
|
+
const forgeWith = (jobs: Record<number, unknown>) => {
|
|
71
|
+
const calls: string[] = [];
|
|
72
|
+
const fetch: ForgeFetch = async (url, init) => {
|
|
73
|
+
calls.push(`${init.method} ${new URL(url).pathname}`);
|
|
74
|
+
const m = /\/actions\/jobs\/(\d+)$/.exec(new URL(url).pathname);
|
|
75
|
+
if (init.method === "GET" && m) return { ok: true, status: 200, text: async () => JSON.stringify(jobs[Number(m[1])] ?? {}) };
|
|
76
|
+
return { ok: true, status: 201, text: async () => "" };
|
|
77
|
+
};
|
|
78
|
+
return { forge: githubCiForge({ apiBase: "https://api.github.com", repo: "acme/app", token: "t", fetch }), calls };
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
test("re-runs the failed jobs of the job's workflow run, so an aggregate's shards go again with it, once per run", async () => {
|
|
82
|
+
const { forge, calls } = forgeWith({ 7: { id: 7, run_id: 500 }, 8: { id: 8, run_id: 500 } });
|
|
83
|
+
await forge.rerun!(run(7));
|
|
84
|
+
await forge.rerun!(run(8));
|
|
85
|
+
expect(calls).toEqual([
|
|
86
|
+
"GET /repos/acme/app/actions/jobs/7",
|
|
87
|
+
"POST /repos/acme/app/actions/runs/500/rerun-failed-jobs",
|
|
88
|
+
"GET /repos/acme/app/actions/jobs/8",
|
|
89
|
+
]);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("falls back to the job's own re-run when the job names no workflow run", async () => {
|
|
93
|
+
const { forge, calls } = forgeWith({ 9: { id: 9 } });
|
|
94
|
+
await forge.rerun!(run(9));
|
|
95
|
+
expect(calls).toEqual(["GET /repos/acme/app/actions/jobs/9", "POST /repos/acme/app/actions/jobs/9/rerun"]);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -57,7 +57,9 @@ export interface CiForge {
|
|
|
57
57
|
checkRuns(sha: string): Promise<CheckRun[]>;
|
|
58
58
|
/**
|
|
59
59
|
* Run a failed check run's job again (#4169), so a flake costs one more
|
|
60
|
-
* run before the commit counts red
|
|
60
|
+
* run before the commit counts red: on GitHub, every failed job of its
|
|
61
|
+
* workflow run, so the jobs an aggregate needs go again with it (#4219).
|
|
62
|
+
* Absent on a forge chant can't ask.
|
|
61
63
|
*/
|
|
62
64
|
rerun?(run: CheckRun): Promise<void>;
|
|
63
65
|
/**
|
|
@@ -86,6 +88,7 @@ export function githubCiForge(opts: GithubCiForgeOptions): CiForge {
|
|
|
86
88
|
const root = opts.apiBase.replace(/\/+$/, "");
|
|
87
89
|
const fetchImpl = opts.fetch ?? (globalThis.fetch as unknown as ForgeFetch);
|
|
88
90
|
const headers = { Authorization: `Bearer ${opts.token}`, Accept: "application/vnd.github+json" };
|
|
91
|
+
const rerunRuns = new Set<number>();
|
|
89
92
|
return {
|
|
90
93
|
kind: "github",
|
|
91
94
|
async checkRuns(sha) {
|
|
@@ -115,9 +118,24 @@ export function githubCiForge(opts: GithubCiForgeOptions): CiForge {
|
|
|
115
118
|
}
|
|
116
119
|
return out;
|
|
117
120
|
},
|
|
118
|
-
// An Actions job's check run has the job's id
|
|
121
|
+
// An Actions job's check run has the job's id. Re-running only that job
|
|
122
|
+
// would re-run an aggregate such as `suites` against the shards' old
|
|
123
|
+
// results, so the failed jobs of its workflow run go again together,
|
|
124
|
+
// each run once per tick (#4219). Both calls need `actions: write`.
|
|
119
125
|
async rerun(run) {
|
|
120
|
-
|
|
126
|
+
const jobUrl = `${root}/repos/${opts.repo}/actions/jobs/${run.id}`;
|
|
127
|
+
const res = await fetchImpl(jobUrl, { method: "GET", headers });
|
|
128
|
+
const text = await res.text();
|
|
129
|
+
if (!res.ok) throw new ForgeApiError("GET", jobUrl, res.status, text);
|
|
130
|
+
const job: unknown = text ? JSON.parse(text) : null;
|
|
131
|
+
const runId = isObject(job) && typeof job.run_id === "number" ? job.run_id : null;
|
|
132
|
+
if (runId === null) {
|
|
133
|
+
await post(`${jobUrl}/rerun`, {});
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (rerunRuns.has(runId)) return;
|
|
137
|
+
rerunRuns.add(runId);
|
|
138
|
+
await post(`${root}/repos/${opts.repo}/actions/runs/${runId}/rerun-failed-jobs`, {});
|
|
121
139
|
},
|
|
122
140
|
async dispatch(workflow, ref) {
|
|
123
141
|
await post(`${root}/repos/${opts.repo}/actions/workflows/${encodeURIComponent(workflow)}/dispatches`, { ref });
|
|
@@ -346,8 +346,8 @@ describe("the triggers of a phase that sets build (#4169)", () => {
|
|
|
346
346
|
[".github/workflows/suites.yml", "newest", ["suites"], true],
|
|
347
347
|
]);
|
|
348
348
|
const ci = parseYAMLDocument(edits[0].text) as Yaml;
|
|
349
|
-
// The triggers of an every phase stay, pull requests included.
|
|
350
|
-
expect(ci.on).toEqual({ push: { branches: ["main"] }, pull_request: null });
|
|
349
|
+
// The triggers of an every phase stay, pull requests included, and it can be started by hand (#4216).
|
|
350
|
+
expect(ci.on).toEqual({ push: { branches: ["main"] }, pull_request: null, workflow_dispatch: {} });
|
|
351
351
|
expect(ci.concurrency).toEqual({ group: "chant-build-lint-${{ github.ref == 'refs/heads/main' && github.sha || github.ref }}", "cancel-in-progress": "${{ github.ref != 'refs/heads/main' }}" });
|
|
352
352
|
expect(edits[0].text).toContain(`# Comments above a block stay.\n${BUILD_BLOCK_MARKER}\nconcurrency:`);
|
|
353
353
|
const suites = parseYAMLDocument(edits[1].text) as Yaml;
|
|
@@ -388,7 +388,7 @@ describe("the triggers of a phase that sets build (#4169)", () => {
|
|
|
388
388
|
];
|
|
389
389
|
const edits = buildTriggerEdits(green(), sources, { compose: true });
|
|
390
390
|
const ci = parseYAMLDocument(edits[0].text) as Yaml;
|
|
391
|
-
expect(ci.on).toEqual({ push: { branches: ["main", "chant/compose/**"] }, pull_request: null });
|
|
391
|
+
expect(ci.on).toEqual({ push: { branches: ["main", "chant/compose/**"] }, pull_request: null, workflow_dispatch: {} });
|
|
392
392
|
expect(ci.concurrency).toEqual({
|
|
393
393
|
group: "chant-build-lint-${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/chant/compose/')) && github.sha || github.ref }}",
|
|
394
394
|
"cancel-in-progress": "${{ !(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/chant/compose/')) }}",
|
|
@@ -399,7 +399,7 @@ describe("the triggers of a phase that sets build (#4169)", () => {
|
|
|
399
399
|
expect(buildTriggerEdits(green(), edits.map((e) => ({ path: e.path, text: e.text })), { compose: true }).map((e) => e.changed)).toEqual([false, false]);
|
|
400
400
|
// A push with no branch list already runs on every branch, so its triggers stay.
|
|
401
401
|
const anyBranch = LINT_WF.replace(" push:\n branches: [main]\n", " push:\n");
|
|
402
|
-
expect((parseYAMLDocument(buildTriggerEdits(green(), [{ path: ".github/workflows/ci.yml", text: anyBranch }], { compose: true })[0].text) as Yaml).on).toEqual({ push: null, pull_request: null });
|
|
402
|
+
expect((parseYAMLDocument(buildTriggerEdits(green(), [{ path: ".github/workflows/ci.yml", text: anyBranch }], { compose: true })[0].text) as Yaml).on).toEqual({ push: null, pull_request: null, workflow_dispatch: {} });
|
|
403
403
|
// Without compose the bytes are what #4169 wrote.
|
|
404
404
|
expect(buildTriggerEdits(green(), sources).map((e) => e.text)).toEqual(buildTriggerEdits(green(), sources, { compose: false }).map((e) => e.text));
|
|
405
405
|
const tick = parseYAMLDocument(renderCiGreenWorkflow({ green: green(), workflows: ["ci"], chantVersion: "0.124.33", workspaceRoot: ".", compose: true })) as Yaml;
|
|
@@ -327,9 +327,11 @@ export interface BuildTriggerEdit {
|
|
|
327
327
|
* ref that never cancels a run in progress, so GitHub keeps the newest
|
|
328
328
|
* push waiting and drops the ones between, and each tag's build runs in a
|
|
329
329
|
* group of its own.
|
|
330
|
-
* - `every`: the triggers stay,
|
|
331
|
-
*
|
|
332
|
-
*
|
|
330
|
+
* - `every`: the triggers stay, with `workflow_dispatch` added so the tick
|
|
331
|
+
* can start a run the forge never started on a commit (#4216), and the
|
|
332
|
+
* group is the commit itself on the branch, so no push cancels or replaces
|
|
333
|
+
* another's run; elsewhere, such as a pull request or a `ci/build/<sha>`
|
|
334
|
+
* tag, a new push cancels the run it supersedes.
|
|
333
335
|
*
|
|
334
336
|
* With `compose` (#4220, a workspace declaring `ci.workflow`), both builds
|
|
335
337
|
* also run on pushes to `chant/compose/**`: `newest` adds the filter to the
|
|
@@ -337,7 +339,7 @@ export interface BuildTriggerEdit {
|
|
|
337
339
|
* and `every`'s group keys a compose branch's runs by commit, as the trunk
|
|
338
340
|
* branch's.
|
|
339
341
|
*
|
|
340
|
-
* Only the top-level `on:`
|
|
342
|
+
* Only the top-level `on:` and `concurrency:` blocks change,
|
|
341
343
|
* each under {@link BUILD_BLOCK_MARKER}; the rest of the file is kept as it
|
|
342
344
|
* is. Throws when one workflow holds a phase of each build, which no one
|
|
343
345
|
* concurrency group can serve.
|
|
@@ -375,12 +377,16 @@ export function buildTriggerEdits(green: CiGreen, sources: readonly WorkflowSour
|
|
|
375
377
|
text = writeTopLevel(text, "concurrency", { group: `chant-build-${tag}-\${{ github.ref }}`, "cancel-in-progress": false });
|
|
376
378
|
} else {
|
|
377
379
|
const main = `refs/heads/${green.branch}`;
|
|
380
|
+
const on = triggersOf(isObject(doc) ? doc.on : undefined);
|
|
381
|
+
let next = on;
|
|
378
382
|
// A push filter that lists branches gains the compose branches; one with no list already runs on every branch.
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
text = writeTopLevel(text, "on", { ...on, push: { ...pushOn, branches: [...pushOn.branches, COMPOSE_BRANCHES] } });
|
|
383
|
+
const pushOn = isObject(on.push) ? on.push : undefined;
|
|
384
|
+
if (compose && pushOn && Array.isArray(pushOn.branches) && !pushOn.branches.includes(COMPOSE_BRANCHES)) {
|
|
385
|
+
next = { ...next, push: { ...pushOn, branches: [...pushOn.branches, COMPOSE_BRANCHES] } };
|
|
383
386
|
}
|
|
387
|
+
// #4216: the tick starts the workflow by hand at a ci/build/<sha> tag when the forge ran nothing on a commit.
|
|
388
|
+
if (!("workflow_dispatch" in next)) next = { ...next, workflow_dispatch: {} };
|
|
389
|
+
if (next !== on) text = writeTopLevel(text, "on", next);
|
|
384
390
|
// #4220: a compose branch's commits each get a verdict, so its runs are keyed by commit, as the trunk branch's are.
|
|
385
391
|
const keyed = compose ? `(github.ref == '${main}' || startsWith(github.ref, 'refs/heads/${COMPOSE_BRANCH_PREFIX}'))` : `github.ref == '${main}'`;
|
|
386
392
|
const unkeyed = compose ? `!${keyed}` : `github.ref != '${main}'`;
|
|
@@ -396,6 +402,14 @@ export function buildTriggerEdits(green: CiGreen, sources: readonly WorkflowSour
|
|
|
396
402
|
return out;
|
|
397
403
|
}
|
|
398
404
|
|
|
405
|
+
/** A workflow's `on:` as a map: `on: push` and `on: [push, pull_request]` name triggers with no settings. */
|
|
406
|
+
function triggersOf(on: unknown): Record<string, unknown> {
|
|
407
|
+
if (isObject(on)) return on;
|
|
408
|
+
if (typeof on === "string") return { [on]: null };
|
|
409
|
+
if (Array.isArray(on)) return Object.fromEntries(on.filter((t): t is string => typeof t === "string").map((t) => [t, null]));
|
|
410
|
+
return {};
|
|
411
|
+
}
|
|
412
|
+
|
|
399
413
|
/**
|
|
400
414
|
* Replace the top-level `key:` block of a YAML file with `value` (or with
|
|
401
415
|
* `value`'s lines, the key's own line first), under
|