@intentius/chant 0.124.92 → 0.124.94
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/__golden__/notify-defaults-plain.json +52 -0
- package/dist/__golden__/notify-defaults-relay.json +92 -0
- package/dist/ci-job-guard.d.ts +22 -8
- package/dist/ci-job-guard.d.ts.map +1 -1
- package/dist/ci-job-guard.js +93 -49
- package/dist/ci-jobs.d.ts +22 -0
- package/dist/ci-jobs.d.ts.map +1 -1
- package/dist/ci-jobs.js +23 -0
- package/dist/ci-product.d.ts +41 -1
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +45 -5
- package/dist/cli/handlers/run-wave.js +17 -3
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +4 -1
- package/dist/components/product-pipeline.d.ts +30 -0
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +28 -3
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +17 -4
- package/dist/gate-resume-run.d.ts +7 -0
- package/dist/gate-resume-run.d.ts.map +1 -1
- package/dist/gate-resume-run.js +42 -3
- package/dist/lexicon.d.ts +64 -1
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/gate-applied.d.ts +18 -0
- package/dist/lifecycle/gate-applied.d.ts.map +1 -1
- package/dist/notify.d.ts +8 -0
- package/dist/notify.d.ts.map +1 -1
- package/dist/notify.js +8 -3
- package/dist/op/before-merge.d.ts +8 -0
- package/dist/op/before-merge.d.ts.map +1 -1
- package/dist/op/before-merge.js +6 -0
- package/dist/op/gate-run-locator.d.ts +17 -0
- package/dist/op/gate-run-locator.d.ts.map +1 -1
- package/dist/op/index.d.ts +4 -2
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +3 -2
- package/dist/op/op-waves-names.d.ts +65 -2
- package/dist/op/op-waves-names.d.ts.map +1 -1
- package/dist/op/op-waves-names.js +129 -0
- package/dist/op/op-waves-remainder.d.ts +110 -0
- package/dist/op/op-waves-remainder.d.ts.map +1 -0
- package/dist/op/op-waves-remainder.js +120 -0
- package/dist/op/op-waves-render-spec.d.ts +63 -5
- package/dist/op/op-waves-render-spec.d.ts.map +1 -1
- package/dist/op/op-waves-render-spec.js +68 -10
- package/dist/op/op-waves-run.d.ts +29 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +194 -6
- package/dist/op/op-waves-split-resume.d.ts +57 -0
- package/dist/op/op-waves-split-resume.d.ts.map +1 -0
- package/dist/op/op-waves-split-resume.js +94 -0
- package/dist/op/op-waves-stand-down.d.ts +9 -1
- package/dist/op/op-waves-stand-down.d.ts.map +1 -1
- package/dist/op/op-waves-stand-down.js +14 -2
- package/dist/op/op-waves.d.ts +38 -2
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +13 -2
- package/dist/release-floors.d.ts +9 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +9 -1
- package/dist/wave-runtime.mjs +368 -368
- package/package.json +1 -1
- package/src/__golden__/notify-defaults-plain.json +52 -0
- package/src/__golden__/notify-defaults-relay.json +92 -0
- package/src/ci-job-guard.default-branch.test.ts +125 -0
- package/src/ci-job-guard.ts +64 -10
- package/src/ci-jobs.ts +26 -0
- package/src/ci-product.ts +54 -5
- package/src/cli/handlers/run-wave.ts +16 -3
- package/src/cli/main.ts +4 -1
- package/src/components/product-pipeline.ts +49 -4
- package/src/floor-table.data.ts +17 -4
- package/src/gate-resume-run.ts +38 -3
- package/src/lexicon.ts +64 -1
- package/src/lifecycle/gate-applied.ts +16 -0
- package/src/notify-bundle.test.ts +3 -2
- package/src/notify-relay-name.test.ts +72 -0
- package/src/notify.ts +16 -3
- package/src/op/before-merge.ts +12 -0
- package/src/op/gate-run-locator.ts +14 -0
- package/src/op/index.ts +6 -1
- package/src/op/op-waves-names.ts +130 -2
- package/src/op/op-waves-remainder.test.ts +342 -0
- package/src/op/op-waves-remainder.ts +146 -0
- package/src/op/op-waves-render-spec.test.ts +107 -0
- package/src/op/op-waves-render-spec.ts +81 -10
- package/src/op/op-waves-run.ts +204 -7
- package/src/op/op-waves-split-resume.test.ts +149 -0
- package/src/op/op-waves-split-resume.ts +109 -0
- package/src/op/op-waves-stand-down.ts +15 -2
- package/src/op/op-waves.ts +46 -3
- package/src/release-floors.ts +13 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #5052: a killed split apply is resumed on GitLab and Forgejo too. The
|
|
3
|
+
* gate job's applied line names, on GitLab, the wave's applying and record
|
|
4
|
+
* jobs by name, which `resumeGateRun` retries; on Forgejo, the run's own
|
|
5
|
+
* dispatch inputs, which it dispatches with.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, test } from "vitest";
|
|
8
|
+
import type { ForgeFetch } from "../pr-forge";
|
|
9
|
+
import { resumeGateRun, type GateRunLocator } from "../gate-resume-run";
|
|
10
|
+
import { NEXT_RELEASE } from "../release-floors";
|
|
11
|
+
import { OP_WAVES_RESUME_ENV, OP_WAVES_SPLIT_RESUME_FLOOR, opWaveSplitResumeEnv, opWaveSplitResumeLocator, parseOpWaveSplitResume } from "./op-waves-split-resume";
|
|
12
|
+
|
|
13
|
+
function fakeForge(routes: Record<string, unknown>) {
|
|
14
|
+
const calls: Array<{ method: string; url: string; body?: string }> = [];
|
|
15
|
+
const fetch: ForgeFetch = async (url, init) => {
|
|
16
|
+
calls.push({ method: init.method, url, ...(init.body ? { body: init.body } : {}) });
|
|
17
|
+
const key = `${init.method} ${new URL(url).pathname}`;
|
|
18
|
+
if (!(key in routes)) return { ok: false, status: 404, text: async () => `no route for ${key}` };
|
|
19
|
+
const body = routes[key];
|
|
20
|
+
return { ok: true, status: 200, text: async () => (body === null ? "" : JSON.stringify(body)) };
|
|
21
|
+
};
|
|
22
|
+
return { fetch, calls, posts: () => calls.filter((c) => c.method === "POST").map((c) => new URL(c.url).pathname) };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const split = [
|
|
26
|
+
{ jobName: "apply-wave-2-plan", phase: "plan" as const, wave: 2 },
|
|
27
|
+
{ jobName: "apply-wave-2-gate", phase: "gate" as const, wave: 2 },
|
|
28
|
+
{ jobName: "apply-wave-2", phase: "apply" as const, wave: 2 },
|
|
29
|
+
{ jobName: "apply-wave-2-record", phase: "record" as const, wave: 2 },
|
|
30
|
+
{ jobName: "apply-wave-3", phase: "apply" as const, wave: 3 },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
const GITLAB_ENV = { GITLAB_CI: "true", CI_API_V4_URL: "https://gl/api/v4", CI_PROJECT_ID: "7", CI_PIPELINE_ID: "100", CI_JOB_ID: "555", CI_JOB_NAME: "apply-wave-2-gate" };
|
|
34
|
+
const FORGEJO_ENV = {
|
|
35
|
+
GITHUB_ACTIONS: "true",
|
|
36
|
+
FORGEJO_ACTIONS: "true",
|
|
37
|
+
GITHUB_REPOSITORY: "acme/infra",
|
|
38
|
+
GITHUB_RUN_ID: "9",
|
|
39
|
+
GITHUB_SERVER_URL: "https://fj",
|
|
40
|
+
GITHUB_WORKFLOW_REF: "acme/infra/.forgejo/workflows/terragucci.yml@refs/heads/main",
|
|
41
|
+
GITHUB_REF_NAME: "main",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
describe("the gate job's resume target (#5052)", () => {
|
|
45
|
+
test("the floor is NEXT_RELEASE", () => {
|
|
46
|
+
expect(OP_WAVES_SPLIT_RESUME_FLOOR).toBe(NEXT_RELEASE);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("GitLab: the wave's applying and record jobs; Forgejo: the product's input names; GitHub and other jobs: nothing", () => {
|
|
50
|
+
expect(opWaveSplitResumeEnv(split, split[1]!, "gitlab")).toEqual({ [OP_WAVES_RESUME_ENV]: '{"apply":["apply-wave-2"],"record":"apply-wave-2-record"}' });
|
|
51
|
+
expect(opWaveSplitResumeEnv(split, split[1]!, "forgejo", { pr: "apply_pr", head: "apply_head" })).toEqual({ [OP_WAVES_RESUME_ENV]: '{"inputs":{"pr":"apply_pr","head":"apply_head"}}' });
|
|
52
|
+
expect(opWaveSplitResumeEnv(split, split[1]!, "forgejo")).toEqual({ [OP_WAVES_RESUME_ENV]: "{}" });
|
|
53
|
+
expect(opWaveSplitResumeEnv(split, split[1]!, "github")).toEqual({});
|
|
54
|
+
expect(opWaveSplitResumeEnv(split, split[2]!, "gitlab")).toEqual({});
|
|
55
|
+
expect(parseOpWaveSplitResume("not json")).toBeUndefined();
|
|
56
|
+
expect(parseOpWaveSplitResume('{"inputs":{"pr":"no spaces allowed"}}')).toEqual({});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("GitLab: the locator carries the job names", () => {
|
|
60
|
+
expect(opWaveSplitResumeLocator(undefined, GITLAB_ENV)).toBeUndefined();
|
|
61
|
+
const loc = opWaveSplitResumeLocator({ forge: "gitlab", api: "https://gl/api/v4", repo: "7", run: "100", job: "555" }, { ...GITLAB_ENV, ...opWaveSplitResumeEnv(split, split[1]!, "gitlab") });
|
|
62
|
+
expect(loc).toMatchObject({ forge: "gitlab", run: "100", job: "555", retry: { apply: ["apply-wave-2"], record: "apply-wave-2-record" } });
|
|
63
|
+
// Told nothing, the gate job names no run, as before.
|
|
64
|
+
expect(opWaveSplitResumeLocator({ forge: "gitlab", api: "https://gl/api/v4", repo: "7", run: "100", job: "555" }, GITLAB_ENV)).toBeUndefined();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("Forgejo: the locator carries the run's decided head, pull request and digest, under the product's names", () => {
|
|
68
|
+
const loc = { forge: "forgejo" as const, api: "https://fj/api/v1", repo: "acme/infra", run: "9", workflow: "terragucci.yml", ref: "main" };
|
|
69
|
+
const env = { ...FORGEJO_ENV, ...opWaveSplitResumeEnv(split, split[1]!, "forgejo", { pr: "apply_pr", head: "apply_head", digest: "apply_digest" }), CHANT_BEFORE_MERGE_PR: "12", CHANT_BEFORE_MERGE_HEAD: "a".repeat(40), CHANT_BEFORE_MERGE_DIGEST: "sha256:d", CHANT_WAVES_COMMIT: "" };
|
|
70
|
+
expect(opWaveSplitResumeLocator(loc, env)).toEqual({ ...loc, inputs: { apply_pr: "12", apply_head: "a".repeat(40), apply_digest: "sha256:d" } });
|
|
71
|
+
// A push's follow-on: the wave and the commit it goes on with, under chant's names.
|
|
72
|
+
const follow = { ...FORGEJO_ENV, [OP_WAVES_RESUME_ENV]: "{}", CHANT_WAVES_WAVE: "4", CHANT_WAVES_COMMIT: "c".repeat(40) };
|
|
73
|
+
expect(opWaveSplitResumeLocator(loc, follow)).toEqual({ ...loc, inputs: { wave: "4", commit: "c".repeat(40) } });
|
|
74
|
+
expect(opWaveSplitResumeLocator(loc, FORGEJO_ENV)).toBeUndefined();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("GitHub: the gate job's run, as before", () => {
|
|
78
|
+
const loc: GateRunLocator = { forge: "github", api: "https://api.github.com", repo: "acme/infra", run: "42", attempt: 1 };
|
|
79
|
+
expect(opWaveSplitResumeLocator(loc, {})).toEqual(loc);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe("resumeGateRun of a killed split apply (#5052)", () => {
|
|
84
|
+
const gitlab: GateRunLocator = { forge: "gitlab", api: "https://gl/api/v4", repo: "7", run: "100", job: "555", jobName: "apply-wave-2-gate", retry: { apply: ["apply-wave-2"], record: "apply-wave-2-record" } };
|
|
85
|
+
|
|
86
|
+
test("GitLab: retries the applying job that was killed, then the record job that ran after it", async () => {
|
|
87
|
+
const forge = fakeForge({
|
|
88
|
+
"GET /api/v4/projects/7/pipelines/100/jobs": [
|
|
89
|
+
{ id: 555, name: "apply-wave-2-gate", status: "success" },
|
|
90
|
+
{ id: 556, name: "apply-wave-2", status: "failed" },
|
|
91
|
+
{ id: 557, name: "apply-wave-2-record", status: "failed" },
|
|
92
|
+
],
|
|
93
|
+
"POST /api/v4/projects/7/jobs/556/retry": { id: 600 },
|
|
94
|
+
"POST /api/v4/projects/7/jobs/557/retry": { id: 601 },
|
|
95
|
+
});
|
|
96
|
+
expect(await resumeGateRun(gitlab, { token: "t", fetch: forge.fetch })).toMatchObject({ status: "resumed", how: "retried job 556 (apply-wave-2) and its record job 557" });
|
|
97
|
+
expect(forge.posts()).toEqual(["/api/v4/projects/7/jobs/556/retry", "/api/v4/projects/7/jobs/557/retry"]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("GitLab: a record job GitLab skipped is left to GitLab; a dry run starts nothing", async () => {
|
|
101
|
+
const jobs = [
|
|
102
|
+
{ id: 556, name: "apply-wave-2", status: "canceled" },
|
|
103
|
+
{ id: 557, name: "apply-wave-2-record", status: "skipped" },
|
|
104
|
+
];
|
|
105
|
+
const forge = fakeForge({ "GET /api/v4/projects/7/pipelines/100/jobs": jobs, "POST /api/v4/projects/7/jobs/556/retry": { id: 600 } });
|
|
106
|
+
expect(await resumeGateRun(gitlab, { token: "t", fetch: forge.fetch })).toMatchObject({ status: "resumed", how: "retried job 556 (apply-wave-2)" });
|
|
107
|
+
const dry = fakeForge({ "GET /api/v4/projects/7/pipelines/100/jobs": jobs });
|
|
108
|
+
expect(await resumeGateRun(gitlab, { token: "t", fetch: dry.fetch, dryRun: true })).toMatchObject({ status: "would-resume", how: "would retry job 556 (apply-wave-2)" });
|
|
109
|
+
expect(dry.posts()).toEqual([]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("GitLab: an applying job going again is left alone; one that applied falls to the gate job, which succeeded", async () => {
|
|
113
|
+
const going = fakeForge({ "GET /api/v4/projects/7/pipelines/100/jobs": [{ id: 600, name: "apply-wave-2", status: "running" }] });
|
|
114
|
+
expect(await resumeGateRun(gitlab, { token: "t", fetch: going.fetch })).toMatchObject({ status: "skipped", reason: "job 600 (apply-wave-2) is running, not finished" });
|
|
115
|
+
const done = fakeForge({
|
|
116
|
+
"GET /api/v4/projects/7/pipelines/100/jobs": [{ id: 555, name: "apply-wave-2-gate", status: "success" }, { id: 600, name: "apply-wave-2", status: "success" }],
|
|
117
|
+
"GET /api/v4/projects/7/jobs/555": { status: "success", name: "apply-wave-2-gate" },
|
|
118
|
+
});
|
|
119
|
+
expect(await resumeGateRun(gitlab, { token: "t", fetch: done.fetch })).toMatchObject({ status: "skipped", reason: "job 555 succeeded" });
|
|
120
|
+
expect(done.posts()).toEqual([]);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("GitLab: the gate job killed before its applying jobs started is retried itself", async () => {
|
|
124
|
+
const forge = fakeForge({
|
|
125
|
+
"GET /api/v4/projects/7/pipelines/100/jobs": [{ id: 555, name: "apply-wave-2-gate", status: "failed" }, { id: 556, name: "apply-wave-2", status: "skipped" }],
|
|
126
|
+
"GET /api/v4/projects/7/jobs/555": { status: "failed", name: "apply-wave-2-gate" },
|
|
127
|
+
"POST /api/v4/projects/7/jobs/555/retry": { id: 700 },
|
|
128
|
+
});
|
|
129
|
+
expect(await resumeGateRun(gitlab, { token: "t", fetch: forge.fetch })).toMatchObject({ status: "resumed", how: "retried job 555 as job 700" });
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("Forgejo: dispatches with the run's inputs; a later push of the branch does not count as the resume, a later dispatch does", async () => {
|
|
133
|
+
const forgejo: GateRunLocator = { forge: "forgejo", api: "https://fj/api/v1", repo: "acme/infra", run: "9", workflow: "terragucci.yml", ref: "main", inputs: { apply_pr: "12", apply_head: "a".repeat(40), apply_digest: "sha256:d" } };
|
|
134
|
+
const forge = fakeForge({
|
|
135
|
+
"GET /api/v1/repos/acme/infra/actions/runs/9": { status: "failure" },
|
|
136
|
+
"GET /api/v1/repos/acme/infra/actions/runs": { workflow_runs: [{ id: 10, prettyref: "main", event: "push", created: "2026-10-02T00:01:00Z" }] },
|
|
137
|
+
"POST /api/v1/repos/acme/infra/actions/workflows/terragucci.yml/dispatches": null,
|
|
138
|
+
});
|
|
139
|
+
const out = await resumeGateRun(forgejo, { token: "t", since: "2026-10-02T00:00:00Z", fetch: forge.fetch });
|
|
140
|
+
expect(out).toMatchObject({ status: "resumed", how: `dispatched terragucci.yml on main with apply_pr=12, apply_head=${"a".repeat(40)}, apply_digest=sha256:d` });
|
|
141
|
+
expect(JSON.parse(forge.calls.at(-1)!.body!)).toEqual({ ref: "main", inputs: forgejo.inputs });
|
|
142
|
+
|
|
143
|
+
const resumed = fakeForge({
|
|
144
|
+
"GET /api/v1/repos/acme/infra/actions/runs/9": { status: "failure" },
|
|
145
|
+
"GET /api/v1/repos/acme/infra/actions/runs": { workflow_runs: [{ id: 11, prettyref: "main", event: "workflow_dispatch", created: "2026-10-02T00:02:00Z" }] },
|
|
146
|
+
});
|
|
147
|
+
expect(await resumeGateRun(forgejo, { token: "t", since: "2026-10-02T00:00:00Z", fetch: resumed.fetch })).toMatchObject({ status: "skipped", reason: expect.stringContaining("run 11") });
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How `chant run resume` starts a killed split apply again (#5052), on the
|
|
3
|
+
* forges whose gate job's run locator alone does not do it.
|
|
4
|
+
*
|
|
5
|
+
* Under `approvals.remainder` (#5047) a split wave's gate job writes the
|
|
6
|
+
* applied line, and its applying job is the one that may be killed. On
|
|
7
|
+
* GitHub the line names the gate job's run, and a re-run of its failed jobs
|
|
8
|
+
* runs the applying and record jobs again. GitLab retries one job by its id,
|
|
9
|
+
* and the gate job knows only the names of the jobs after it; Forgejo has no
|
|
10
|
+
* re-run and dispatches the workflow on the branch, which before merge is
|
|
11
|
+
* not the decided head. So the generator tells the gate job, in
|
|
12
|
+
* {@link OP_WAVES_RESUME_ENV}, what a resume needs:
|
|
13
|
+
*
|
|
14
|
+
* - GitLab: the names of the wave's applying jobs and its record job. The
|
|
15
|
+
* line's locator carries them as `retry`, and the resume retries the
|
|
16
|
+
* newest try of each applying job that failed or was cancelled, then the
|
|
17
|
+
* record job.
|
|
18
|
+
* - Forgejo: the product's names of the dispatch inputs. The line's locator
|
|
19
|
+
* carries the run's own inputs (the decided head of a before-merge run,
|
|
20
|
+
* the wave and commit of a follow-on) as `inputs`, and the resume
|
|
21
|
+
* dispatches with them, so the new run plans the same commit and its gate
|
|
22
|
+
* job applies the rest under the same approval.
|
|
23
|
+
*
|
|
24
|
+
* Without the variable, the gate job's line names no run on those forges,
|
|
25
|
+
* as before.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { BEFORE_MERGE_DIGEST_ENV, BEFORE_MERGE_HEAD_ENV, BEFORE_MERGE_PR_ENV } from "./before-merge";
|
|
29
|
+
import { OP_WAVES_COMMIT_ENV, OP_WAVES_WAVE_ENV } from "./follow-on-run";
|
|
30
|
+
import type { GateRunLocator } from "./gate-run-locator";
|
|
31
|
+
import type { OpWaveSplitJob } from "./op-waves-split";
|
|
32
|
+
|
|
33
|
+
export { OP_WAVES_SPLIT_RESUME_FLOOR } from "../release-floors";
|
|
34
|
+
|
|
35
|
+
/** The variable a split wave's gate job reads what a resume needs from, as JSON. */
|
|
36
|
+
export const OP_WAVES_RESUME_ENV = "CHANT_WAVES_RESUME";
|
|
37
|
+
|
|
38
|
+
/** The dispatch inputs a Forgejo resume fills, by chant's names. */
|
|
39
|
+
export type OpWaveResumeInput = "pr" | "head" | "digest" | "wave" | "commit";
|
|
40
|
+
|
|
41
|
+
/** What {@link OP_WAVES_RESUME_ENV} holds: GitLab's job names, or Forgejo's input names (each chant's own when left out). */
|
|
42
|
+
export interface OpWaveSplitResume {
|
|
43
|
+
apply?: string[];
|
|
44
|
+
record?: string;
|
|
45
|
+
inputs?: Partial<Record<OpWaveResumeInput, string>>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The variable a split wave's gate job carries (#5052): on GitLab the names
|
|
50
|
+
* of wave `gate.wave`'s applying jobs and its record job, on Forgejo the
|
|
51
|
+
* product's dispatch input names. Empty on GitHub, whose re-run needs none,
|
|
52
|
+
* and for a job that is no gate job.
|
|
53
|
+
*/
|
|
54
|
+
export function opWaveSplitResumeEnv(
|
|
55
|
+
split: readonly Pick<OpWaveSplitJob, "jobName" | "phase" | "wave">[],
|
|
56
|
+
gate: Pick<OpWaveSplitJob, "phase" | "wave">,
|
|
57
|
+
forge: "github" | "forgejo" | "gitlab",
|
|
58
|
+
inputs?: Partial<Record<OpWaveResumeInput, string>>,
|
|
59
|
+
): Record<string, string> {
|
|
60
|
+
if (gate.phase !== "gate" || forge === "github") return {};
|
|
61
|
+
if (forge === "forgejo") return { [OP_WAVES_RESUME_ENV]: JSON.stringify(inputs && Object.keys(inputs).length > 0 ? { inputs } : {}) };
|
|
62
|
+
const apply = split.filter((j) => j.wave === gate.wave && j.phase === "apply").map((j) => j.jobName);
|
|
63
|
+
const record = split.find((j) => j.wave === gate.wave && j.phase === "record")?.jobName;
|
|
64
|
+
return { [OP_WAVES_RESUME_ENV]: JSON.stringify({ apply, ...(record ? { record } : {}) }) };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const NAME = /^[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
68
|
+
|
|
69
|
+
/** Read {@link OP_WAVES_RESUME_ENV}; undefined when unset or not one. */
|
|
70
|
+
export function parseOpWaveSplitResume(raw: string | undefined): OpWaveSplitResume | undefined {
|
|
71
|
+
if (raw === undefined || raw.trim() === "") return undefined;
|
|
72
|
+
let v: unknown;
|
|
73
|
+
try {
|
|
74
|
+
v = JSON.parse(raw);
|
|
75
|
+
} catch {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return undefined;
|
|
79
|
+
const o = v as Record<string, unknown>;
|
|
80
|
+
const apply = Array.isArray(o.apply) && o.apply.every((n) => typeof n === "string" && n.trim() !== "") ? (o.apply as string[]) : undefined;
|
|
81
|
+
const record = typeof o.record === "string" && o.record.trim() !== "" ? o.record : undefined;
|
|
82
|
+
const inputs =
|
|
83
|
+
o.inputs && typeof o.inputs === "object" && !Array.isArray(o.inputs) && Object.entries(o.inputs).every(([k, n]) => ["pr", "head", "digest", "wave", "commit"].includes(k) && typeof n === "string" && NAME.test(n))
|
|
84
|
+
? (o.inputs as Partial<Record<OpWaveResumeInput, string>>)
|
|
85
|
+
: undefined;
|
|
86
|
+
return { ...(apply ? { apply } : {}), ...(record ? { record } : {}), ...(inputs ? { inputs } : {}) };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The run locator a split wave's gate job writes on its applied line
|
|
91
|
+
* (#5052), from its own locator and what {@link OP_WAVES_RESUME_ENV} says:
|
|
92
|
+
* GitHub's as it is; GitLab's with `retry`, when the variable names applying
|
|
93
|
+
* jobs; Forgejo's with the run's own dispatch inputs, when the variable is
|
|
94
|
+
* set. Undefined where a resume could not start the applying jobs again.
|
|
95
|
+
*/
|
|
96
|
+
export function opWaveSplitResumeLocator(locator: GateRunLocator | undefined, env: Record<string, string | undefined> = process.env): GateRunLocator | undefined {
|
|
97
|
+
if (!locator) return undefined;
|
|
98
|
+
if (locator.forge === "github") return locator;
|
|
99
|
+
const told = parseOpWaveSplitResume(env[OP_WAVES_RESUME_ENV]);
|
|
100
|
+
if (!told) return undefined;
|
|
101
|
+
if (locator.forge === "gitlab") return told.apply && told.apply.length > 0 ? { ...locator, retry: { apply: told.apply, ...(told.record ? { record: told.record } : {}) } } : undefined;
|
|
102
|
+
const of: Record<OpWaveResumeInput, string> = { pr: BEFORE_MERGE_PR_ENV, head: BEFORE_MERGE_HEAD_ENV, digest: BEFORE_MERGE_DIGEST_ENV, wave: OP_WAVES_WAVE_ENV, commit: OP_WAVES_COMMIT_ENV };
|
|
103
|
+
const inputs: Record<string, string> = {};
|
|
104
|
+
for (const [input, variable] of Object.entries(of) as Array<[OpWaveResumeInput, string]>) {
|
|
105
|
+
const value = env[variable]?.trim();
|
|
106
|
+
if (value) inputs[told.inputs?.[input] ?? input] = value;
|
|
107
|
+
}
|
|
108
|
+
return { ...locator, inputs };
|
|
109
|
+
}
|
|
@@ -86,13 +86,26 @@ export async function newerCommitOnBranch(cwd: string, env: NodeJS.ProcessEnv =
|
|
|
86
86
|
/** The default port: {@link newerCommitOnBranch} with the job's environment. */
|
|
87
87
|
export const gitOpWaveNewerCommit: OpWaveNewerCommitPort = (cwd, head) => newerCommitOnBranch(cwd, process.env, head);
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* The repository's default branch as the job's forge names it (#5032):
|
|
91
|
+
* `CHANT_DEFAULT_BRANCH` (a GitHub or Forgejo waves job sets it from the
|
|
92
|
+
* event), else GitLab's `CI_DEFAULT_BRANCH`. Undefined when neither is set.
|
|
93
|
+
*/
|
|
94
|
+
export function opWaveDefaultBranch(env: NodeJS.ProcessEnv = process.env): string | undefined {
|
|
95
|
+
const named = (env.CHANT_DEFAULT_BRANCH || env.CI_DEFAULT_BRANCH || "").trim();
|
|
96
|
+
return named === "" ? undefined : named;
|
|
97
|
+
}
|
|
98
|
+
|
|
89
99
|
/**
|
|
90
100
|
* Whether the spec at the newer commit (`atTip`, null when the file is gone
|
|
91
101
|
* there) applies every one of `targets` in wave `waveName` on `branch`.
|
|
102
|
+
* #5032: a spec with `defaultBranch` runs on `defaultBranch`, the name the
|
|
103
|
+
* forge gives the repository's default branch, beside its `branches`.
|
|
92
104
|
*/
|
|
93
|
-
export function tipAppliesTargets(atTip: OpWavesSpec | null, branch: string, waveName: string, targets: readonly string[]): boolean {
|
|
105
|
+
export function tipAppliesTargets(atTip: OpWavesSpec | null, branch: string, waveName: string, targets: readonly string[], defaultBranch?: string): boolean {
|
|
94
106
|
if (!atTip || !Array.isArray(atTip.waves)) return false;
|
|
95
|
-
|
|
107
|
+
const onDefault = atTip.defaultBranch === true && defaultBranch !== undefined && branch === defaultBranch;
|
|
108
|
+
if (!onDefault && !(atTip.branches ?? (atTip.defaultBranch === true ? [] : ["main"])).includes(branch)) return false;
|
|
96
109
|
const wave = atTip.waves.find((w) => w?.name === waveName);
|
|
97
110
|
if (!wave) return false;
|
|
98
111
|
if (wave.discover === true) return true;
|
package/src/op/op-waves.ts
CHANGED
|
@@ -483,8 +483,19 @@ export interface OpWavesSpec {
|
|
|
483
483
|
* so a change cannot drop the rule for its own gates.
|
|
484
484
|
*/
|
|
485
485
|
neverOverMcp?: boolean;
|
|
486
|
-
/** Branches whose pushes run the waves. Default `["main"]`. */
|
|
486
|
+
/** Branches whose pushes run the waves. Default `["main"]`, or none beside the default branch with `defaultBranch`. */
|
|
487
487
|
branches?: string[];
|
|
488
|
+
/**
|
|
489
|
+
* The pushes to the repository's default branch run the waves, by the
|
|
490
|
+
* name the forge gives it at run time (#5032): GitHub and Forgejo
|
|
491
|
+
* `github.event.repository.default_branch`, GitLab `$CI_DEFAULT_BRANCH`.
|
|
492
|
+
* `branches` names more beside it, and `main` is no longer the default.
|
|
493
|
+
* The job guard admits the default branch and those, the GitLab rules
|
|
494
|
+
* match the same, and the stand-down counts a newer commit on it. A
|
|
495
|
+
* product that renders the waves into a workflow of its own sets this
|
|
496
|
+
* when it never learns the branch's name. Default false.
|
|
497
|
+
*/
|
|
498
|
+
defaultBranch?: boolean;
|
|
488
499
|
/**
|
|
489
500
|
* An apply stands down when a newer commit on the branch will apply the
|
|
490
501
|
* same targets (#4581): its wave applies nothing, the job exits 6
|
|
@@ -753,6 +764,30 @@ export interface OpWavesApprovals {
|
|
|
753
764
|
* approval of a digest passes that digest as often as it is planned.
|
|
754
765
|
*/
|
|
755
766
|
spend?: boolean;
|
|
767
|
+
/**
|
|
768
|
+
* An apply that stopped applies the rest under its approval (#5047). With
|
|
769
|
+
* `spend`, read at the base commit. The applied line a wave writes before
|
|
770
|
+
* it applies under an approval carries each change its plans make (a run's
|
|
771
|
+
* resource and its digest), the commit and the run, when every run that
|
|
772
|
+
* changes something plans through the step on the `resource` lock grain
|
|
773
|
+
* (an engine that records each resource as it applies it). The job that
|
|
774
|
+
* applies the whole wave, or a split wave's record job, writes how the
|
|
775
|
+
* apply ended. A wave run again at the same commit whose plans make only
|
|
776
|
+
* changes of the newest such apply that did not finish (no finished line,
|
|
777
|
+
* or a failed one), with the same digests, applies them under that
|
|
778
|
+
* approval: the changes it no longer makes are done. A split wave's
|
|
779
|
+
* applying job applies a run whose plan moved the same way. A wave whose
|
|
780
|
+
* plans change nothing closes an apply that stopped as applied. Default
|
|
781
|
+
* false. See `./op-waves-remainder.ts`.
|
|
782
|
+
*/
|
|
783
|
+
remainder?: boolean;
|
|
784
|
+
/**
|
|
785
|
+
* With `spend` (#5047), read at the base commit: a wave its gate lets
|
|
786
|
+
* through (`not-required`) spends an approval of its digest that stands,
|
|
787
|
+
* so it does not stand for the next plans. Default false: only a wave that
|
|
788
|
+
* applies under an approval spends it.
|
|
789
|
+
*/
|
|
790
|
+
spendStanding?: boolean;
|
|
756
791
|
/**
|
|
757
792
|
* Approval rules (#4290): a wave takes each rule whose `targets` glob
|
|
758
793
|
* matches one of its runs' targets (a rule with no `targets` covers every
|
|
@@ -996,6 +1031,7 @@ export function assertOpWavesSpec(spec: OpWavesSpec): void {
|
|
|
996
1031
|
}
|
|
997
1032
|
assertOpWaveHooks(where, spec.hooks);
|
|
998
1033
|
if (spec.standDown !== undefined && typeof spec.standDown !== "boolean") throw new Error(`${where}: \`standDown\` must be true or false.`);
|
|
1034
|
+
if (spec.defaultBranch !== undefined && typeof spec.defaultBranch !== "boolean") throw new Error(`${where}: \`defaultBranch\` must be true or false.`);
|
|
999
1035
|
{
|
|
1000
1036
|
const problems = opWaveReleaseProblems(spec);
|
|
1001
1037
|
if (problems.length > 0) throw new Error(`${where}: ${problems.join("; ")}.`);
|
|
@@ -1052,7 +1088,13 @@ export function assertOpWavesSpec(spec: OpWavesSpec): void {
|
|
|
1052
1088
|
if (typeof value !== "boolean") throw new Error(`${where}: approvals.preview must be true or false.`);
|
|
1053
1089
|
continue;
|
|
1054
1090
|
}
|
|
1055
|
-
if (key
|
|
1091
|
+
if (key === "remainder" || key === "spendStanding") {
|
|
1092
|
+
// #5047: a stopped apply's rest, and an approval left standing, both under the spend rule.
|
|
1093
|
+
if (typeof value !== "boolean") throw new Error(`${where}: approvals.${key} must be true or false.`);
|
|
1094
|
+
if (value && (a as OpWavesApprovals).spend !== true) throw new Error(`${where}: approvals.${key} works on the lines approvals.spend writes, so it needs approvals.spend: true.`);
|
|
1095
|
+
continue;
|
|
1096
|
+
}
|
|
1097
|
+
if (key !== "spend") throw new Error(`${where}: approvals.${key} is not a setting; the ones there are approvals.spend, approvals.remainder, approvals.spendStanding, approvals.preview, approvals.quorum, approvals.reviewLedger, approvals.involved and approvals.pullRequest.`);
|
|
1056
1098
|
if (typeof value !== "boolean") throw new Error(`${where}: approvals.spend must be true or false.`);
|
|
1057
1099
|
}
|
|
1058
1100
|
if ((a as OpWavesApprovals).quorum?.length && (spec.point !== undefined || spec.waves.some((w) => w.point !== undefined))) {
|
|
@@ -1478,7 +1520,8 @@ export function opWaveShare<T extends { target: string }>(runs: readonly T[], sh
|
|
|
1478
1520
|
* product's command in place of `chant` (#4607, {@link opWaveBinArgv}).
|
|
1479
1521
|
* With `renderSpec` (#4982) every command passes `--render-spec`: the job
|
|
1480
1522
|
* renders the spec at base through the product's command
|
|
1481
|
-
* (`./op-waves-render-spec.ts
|
|
1523
|
+
* (`./op-waves-render-spec.ts`; with `runsAtHead` the runs at the applied
|
|
1524
|
+
* commit, #5046), and `spec` is the pipeline's shape.
|
|
1482
1525
|
* With `beforeMerge` (#4984) every command reads its base from
|
|
1483
1526
|
* `CHANT_WAVES_BASE` when the run checked out a pull request's decided
|
|
1484
1527
|
* head, else from the spec's `base` (or `HEAD^1`), as a push run does.
|
package/src/release-floors.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* this constant to the next patch (#4501). The check fails while a floor
|
|
20
20
|
* still names this constant after its version shipped.
|
|
21
21
|
*/
|
|
22
|
-
export const NEXT_RELEASE = "0.124.
|
|
22
|
+
export const NEXT_RELEASE = "0.124.94";
|
|
23
23
|
|
|
24
24
|
/** The first chant with `chant dev local` and `chant dev bundle-check`, `@intentius/chant/local-chant` and `@intentius/chant/bundle-check` (`chantRuntimeTarget`, `chantExternalPlugin`, `checkBundle`): a product built against a chant checkout, and its bundle checked, without its own scripts (#4787). */
|
|
25
25
|
export const LOCAL_CHANT_FLOOR = "0.124.86";
|
|
@@ -234,6 +234,18 @@ export const TARGET_SIGNED_CHECKS_FLOOR = "0.124.89";
|
|
|
234
234
|
/** The first chant whose Op waves generators take `renderSpec` (the wave jobs run `chant run wave --render-spec`, and `CHANT_WAVES_SPEC_COMMAND` names the product command that prints the spec at the commit in `CHANT_WAVES_SPEC_AT`), so a product whose spec is built from its config at base renders its wave jobs, policy step, evidence job and cloud trade through chant (#4982). */
|
|
235
235
|
export const RUNTIME_WAVES_SPEC_FLOOR = "0.124.89";
|
|
236
236
|
|
|
237
|
+
/** The first chant whose Op waves `renderSpec` takes `runsAtHead` (the jobs carry `CHANT_WAVES_SPEC_RUNS=head`): the job's own spec is rendered at the applied commit, with `CHANT_WAVES_SPEC_BASE` set to the base commit beside `CHANT_WAVES_SPEC_AT`, so the runs a change adds apply at its merge, while the gate policy, holds, hooks and evidence rules still come from the render at base (#5046). */
|
|
238
|
+
export const RUNTIME_WAVES_SPEC_RUNS_AT_HEAD_FLOOR = NEXT_RELEASE;
|
|
239
|
+
|
|
240
|
+
/** The first chant whose Op waves keep the record of an apply under an approval themselves (#5047): with `approvals.spend`, `approvals.remainder` writes each change the approved plans make, the commit and the run on the applied line (a split wave's gate job writes it), the job that applies the whole wave or the record job writes how the apply ended, and a wave run again at that commit applies the rest under the same approval when its plans make only changes the stopped apply did not finish; a wave that plans no change closes a stopped apply, and `approvals.spendStanding` spends an approval of the digest a wave its gate let through applies. */
|
|
241
|
+
export const OP_WAVES_REMAINDER_FLOOR = NEXT_RELEASE;
|
|
242
|
+
|
|
243
|
+
/** The first chant whose `chant run resume` starts a killed split apply again on GitLab and Forgejo (#5052): under `approvals.remainder` the gate job's applied line names its run there too, GitLab's with the wave's applying and record jobs by name (`retry`), which the resume retries, and Forgejo's with the run's dispatch inputs (`inputs`), which the resume dispatches with, so the new run applies the rest at the same decided head or commit. */
|
|
244
|
+
export const OP_WAVES_SPLIT_RESUME_FLOOR = NEXT_RELEASE;
|
|
245
|
+
|
|
246
|
+
/** The first chant whose `approvals.remainder` resumes the waves terragucci's own records resume (#5056): the terraform step gives a live choudoufu root's plan (`live-plan-set`) its `resourceDigests`, so its applied line names the changes, and the cover leaves out the cost member `(monthly cost)`, whose digest follows from the plans, on both sides. */
|
|
247
|
+
export const OP_WAVES_REMAINDER_PARITY_FLOOR = NEXT_RELEASE;
|
|
248
|
+
|
|
237
249
|
/** The first chant whose `chant run resume` (`resumeGateRun`) on GitLab retries a wave job's `<wave job>-evidence` with the wave job when the evidence job already ran, and whose `ci evidence sign --from-job` waits for a job it reads to finish, so a resumed wave's evidence job signs from the new try (#4978). */
|
|
238
250
|
export const GITLAB_WAVE_EVIDENCE_RETRY_FLOOR = "0.124.89";
|
|
239
251
|
|