@intentius/chant 0.124.88 → 0.124.89
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/actor.d.ts +36 -1
- package/dist/actor.d.ts.map +1 -1
- package/dist/actor.js +39 -1
- package/dist/chant-install.d.ts.map +1 -1
- package/dist/chant-install.js +1 -2
- package/dist/ci-base.d.ts +30 -0
- package/dist/ci-base.d.ts.map +1 -0
- package/dist/ci-base.js +33 -0
- package/dist/ci-comment-commands.d.ts +177 -0
- package/dist/ci-comment-commands.d.ts.map +1 -0
- package/dist/ci-comment-commands.js +325 -0
- package/dist/ci-comment-replies.d.ts +40 -0
- package/dist/ci-comment-replies.d.ts.map +1 -0
- package/dist/ci-comment-replies.js +59 -0
- package/dist/ci-evidence-from-job.d.ts +25 -0
- package/dist/ci-evidence-from-job.d.ts.map +1 -1
- package/dist/ci-evidence-from-job.js +43 -2
- package/dist/ci-evidence-jobs.d.ts +30 -1
- package/dist/ci-evidence-jobs.d.ts.map +1 -1
- package/dist/ci-evidence-jobs.js +46 -3
- package/dist/ci-image.d.ts +21 -4
- package/dist/ci-image.d.ts.map +1 -1
- package/dist/ci-image.js +62 -10
- package/dist/ci-note-commands.d.ts +63 -3
- package/dist/ci-note-commands.d.ts.map +1 -1
- package/dist/ci-note-commands.js +69 -35
- package/dist/ci-product-words.d.ts +42 -0
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +25 -0
- package/dist/ci-product.d.ts +31 -0
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +34 -4
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +29 -2
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +2 -1
- package/dist/cli/handlers/ci-check.d.ts +1 -1
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +17 -7
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
- package/dist/cli/handlers/ci-evidence.js +33 -7
- package/dist/cli/handlers/components.d.ts.map +1 -1
- package/dist/cli/handlers/components.js +3 -1
- package/dist/cli/handlers/generated-check.d.ts +8 -0
- package/dist/cli/handlers/generated-check.d.ts.map +1 -1
- package/dist/cli/handlers/generated-check.js +31 -1
- package/dist/cli/handlers/lock.d.ts.map +1 -1
- package/dist/cli/handlers/lock.js +121 -4
- package/dist/cli/handlers/pr-comment.d.ts +21 -0
- package/dist/cli/handlers/pr-comment.d.ts.map +1 -0
- package/dist/cli/handlers/pr-comment.js +112 -0
- package/dist/cli/handlers/pr-env.d.ts.map +1 -1
- package/dist/cli/handlers/pr-env.js +6 -3
- package/dist/cli/handlers/pr.d.ts +23 -1
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +55 -9
- package/dist/cli/handlers/promote.d.ts.map +1 -1
- package/dist/cli/handlers/promote.js +2 -1
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +11 -2
- package/dist/cli/handlers/run-wave.d.ts.map +1 -1
- package/dist/cli/handlers/run-wave.js +28 -2
- package/dist/cli/handlers/run.d.ts.map +1 -1
- package/dist/cli/handlers/run.js +2 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +24 -2
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +16 -0
- package/dist/cli/registry.d.ts +11 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/auto-release.d.ts.map +1 -1
- package/dist/components/auto-release.js +2 -1
- package/dist/components/pr-checks.d.ts +70 -6
- package/dist/components/pr-checks.d.ts.map +1 -1
- package/dist/components/pr-checks.js +74 -13
- package/dist/components/pr-pipeline.d.ts +16 -12
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +3 -11
- package/dist/components/product-pipeline.d.ts +42 -1
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +64 -12
- package/dist/components/product-plan.d.ts +190 -5
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +220 -39
- package/dist/drift-record.d.ts +7 -0
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/drift-record.js +19 -0
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +54 -31
- package/dist/forge-check/contract.d.ts +11 -1
- package/dist/forge-check/contract.d.ts.map +1 -1
- package/dist/forge-check/contract.js +4 -1
- package/dist/forge-check/index.d.ts +2 -0
- package/dist/forge-check/index.d.ts.map +1 -1
- package/dist/forge-check/index.js +2 -0
- package/dist/gate-resume-run.d.ts +9 -1
- package/dist/gate-resume-run.d.ts.map +1 -1
- package/dist/gate-resume-run.js +26 -3
- package/dist/generated-check.d.ts +18 -4
- package/dist/generated-check.d.ts.map +1 -1
- package/dist/generated-check.js +37 -5
- package/dist/image-pins.d.ts +26 -0
- package/dist/image-pins.d.ts.map +1 -0
- package/dist/image-pins.js +19 -0
- package/dist/lexicon.d.ts +11 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/git.d.ts +11 -0
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +30 -3
- package/dist/lifecycle/publish-npm.d.ts +11 -0
- package/dist/lifecycle/publish-npm.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.js +27 -1
- package/dist/lifecycle/reach-locks.d.ts +131 -0
- package/dist/lifecycle/reach-locks.d.ts.map +1 -0
- package/dist/lifecycle/reach-locks.js +118 -0
- package/dist/lifecycle/release-cut.d.ts +3 -1
- package/dist/lifecycle/release-cut.d.ts.map +1 -1
- package/dist/lifecycle/release-cut.js +15 -0
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +1 -2
- package/dist/notify-product.d.ts +12 -3
- package/dist/notify-product.d.ts.map +1 -1
- package/dist/notify-product.js +10 -6
- package/dist/op/activities/source-release.d.ts.map +1 -1
- package/dist/op/activities/source-release.js +2 -1
- package/dist/op/activities/source-rollback.d.ts.map +1 -1
- package/dist/op/activities/source-rollback.js +2 -1
- package/dist/op/index.d.ts +2 -0
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +1 -0
- package/dist/op/op-waves-evidence-jobs.d.ts +6 -1
- package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
- package/dist/op/op-waves-evidence-jobs.js +9 -3
- package/dist/op/op-waves-render-spec.d.ts +100 -0
- package/dist/op/op-waves-render-spec.d.ts.map +1 -0
- package/dist/op/op-waves-render-spec.js +162 -0
- package/dist/op/op-waves-run.d.ts +2 -0
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +2 -1
- package/dist/op/op-waves.d.ts +4 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +4 -1
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +59 -3
- package/dist/op/wave-stop.d.ts +64 -0
- package/dist/op/wave-stop.d.ts.map +1 -0
- package/dist/op/wave-stop.js +127 -0
- package/dist/planned-files.d.ts +76 -0
- package/dist/planned-files.d.ts.map +1 -0
- package/dist/planned-files.js +108 -0
- package/dist/pr-forge-job.d.ts +22 -0
- package/dist/pr-forge-job.d.ts.map +1 -0
- package/dist/pr-forge-job.js +46 -0
- package/dist/pr-loop.d.ts +3 -6
- package/dist/pr-loop.d.ts.map +1 -1
- package/dist/pr-loop.js +4 -81
- package/dist/pr-plan-note.d.ts +97 -0
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +94 -1
- package/dist/pr-post.d.ts +28 -3
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +145 -13
- package/dist/pr-status.d.ts +16 -0
- package/dist/pr-status.d.ts.map +1 -0
- package/dist/pr-status.js +90 -0
- package/dist/ref-gate-init.d.ts +16 -2
- package/dist/ref-gate-init.d.ts.map +1 -1
- package/dist/ref-gate-init.js +24 -13
- package/dist/release-floors.d.ts +37 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +61 -25
- package/dist/render-module.d.ts +15 -0
- package/dist/render-module.d.ts.map +1 -0
- package/dist/render-module.js +73 -0
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +1 -2
- package/dist/wave-runtime.mjs +304 -301
- package/dist/workspace/ci-green-cli.d.ts.map +1 -1
- package/dist/workspace/ci-green-cli.js +3 -2
- package/dist/workspace/release-train.d.ts.map +1 -1
- package/dist/workspace/release-train.js +2 -1
- package/dist/workspace/release-workflow.d.ts +4 -3
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +10 -7
- package/dist/workspace/trust/check-evidence-report.d.ts +7 -2
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.js +15 -8
- package/dist/workspace/trust/ref-gate-cli.d.ts +10 -1
- package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
- package/dist/workspace/trust/ref-gate-cli.js +30 -10
- package/dist/workspace/workspace-run.d.ts.map +1 -1
- package/dist/workspace/workspace-run.js +2 -1
- package/package.json +1 -1
- package/src/actor.test.ts +68 -2
- package/src/actor.ts +61 -1
- package/src/chant-install.test.ts +2 -3
- package/src/chant-install.ts +1 -2
- package/src/ci-base.test.ts +41 -0
- package/src/ci-base.ts +43 -0
- package/src/ci-comment-commands.test.ts +376 -0
- package/src/ci-comment-commands.ts +389 -0
- package/src/ci-comment-replies.ts +78 -0
- package/src/ci-commit.test.ts +2 -3
- package/src/ci-evidence-from-job.test.ts +18 -0
- package/src/ci-evidence-from-job.ts +58 -2
- package/src/ci-evidence-jobs.ts +50 -5
- package/src/ci-image.test.ts +130 -9
- package/src/ci-image.ts +85 -12
- package/src/ci-note-commands.ts +104 -41
- package/src/ci-product-words.ts +59 -0
- package/src/ci-product.ts +40 -4
- package/src/cli/commands/build.test.ts +41 -0
- package/src/cli/commands/build.ts +27 -2
- package/src/cli/handlers/approve.ts +2 -1
- package/src/cli/handlers/ci-check.ts +19 -7
- package/src/cli/handlers/ci-evidence.ts +29 -8
- package/src/cli/handlers/components.ts +3 -1
- package/src/cli/handlers/generated-check.ts +31 -1
- package/src/cli/handlers/lock-reach.test.ts +103 -0
- package/src/cli/handlers/lock.ts +100 -4
- package/src/cli/handlers/pr-comment.ts +104 -0
- package/src/cli/handlers/pr-env.ts +6 -3
- package/src/cli/handlers/pr-record.test.ts +1 -1
- package/src/cli/handlers/pr.ts +50 -10
- package/src/cli/handlers/promote.ts +2 -1
- package/src/cli/handlers/release.e2e.test.ts +35 -0
- package/src/cli/handlers/release.ts +14 -2
- package/src/cli/handlers/run-wave.ts +28 -2
- package/src/cli/handlers/run.ts +2 -1
- package/src/cli/main.ts +24 -2
- package/src/cli/parse-args.ts +12 -0
- package/src/cli/registry.ts +11 -0
- package/src/components/auto-release.ts +2 -1
- package/src/components/pr-checks.ts +112 -17
- package/src/components/pr-pipeline.ts +17 -15
- package/src/components/product-pipeline.ts +93 -11
- package/src/components/product-plan.test.ts +40 -2
- package/src/components/product-plan.ts +331 -45
- package/src/drift-record.test.ts +20 -0
- package/src/drift-record.ts +16 -0
- package/src/floor-table.data.ts +54 -31
- package/src/forge-check/contract.ts +12 -1
- package/src/forge-check/forge-check.test.ts +17 -0
- package/src/forge-check/index.ts +2 -0
- package/src/gate-resume-run.ts +27 -3
- package/src/generated-check.e2e.test.ts +21 -1
- package/src/generated-check.test.ts +66 -0
- package/src/generated-check.ts +51 -10
- package/src/image-pins.ts +31 -0
- package/src/lexicon.ts +11 -0
- package/src/lifecycle/git.test.ts +48 -0
- package/src/lifecycle/git.ts +27 -4
- package/src/lifecycle/publish-npm.ts +31 -1
- package/src/lifecycle/reach-locks.test.ts +87 -0
- package/src/lifecycle/reach-locks.ts +169 -0
- package/src/lifecycle/release-cut.ts +17 -1
- package/src/lifecycle/release-images.test.ts +56 -0
- package/src/lifecycle/release-images.ts +1 -2
- package/src/notify-product.ts +19 -8
- package/src/op/activities/source-release.ts +2 -1
- package/src/op/activities/source-rollback.ts +2 -1
- package/src/op/gate-resume.test.ts +27 -0
- package/src/op/index.ts +10 -0
- package/src/op/op-waves-evidence-jobs.ts +10 -4
- package/src/op/op-waves-notify-words.test.ts +18 -0
- package/src/op/op-waves-render-spec.test.ts +160 -0
- package/src/op/op-waves-render-spec.ts +171 -0
- package/src/op/op-waves-run.ts +2 -1
- package/src/op/op-waves.ts +5 -2
- package/src/op/schedule-overdue.test.ts +43 -0
- package/src/op/schedule-overdue.ts +57 -3
- package/src/op/wave-stop.test.ts +72 -0
- package/src/op/wave-stop.ts +137 -0
- package/src/planned-files.test.ts +80 -0
- package/src/planned-files.ts +134 -0
- package/src/pr-forge-job.test.ts +53 -0
- package/src/pr-forge-job.ts +46 -0
- package/src/pr-loop-narrowed.test.ts +2 -1
- package/src/pr-loop-words.test.ts +2 -1
- package/src/pr-loop.test.ts +1 -2
- package/src/pr-loop.ts +4 -80
- package/src/pr-plan-note.ts +155 -3
- package/src/pr-post-replan.test.ts +144 -0
- package/src/pr-post-subject.test.ts +230 -0
- package/src/pr-post.test.ts +2 -1
- package/src/pr-post.ts +150 -15
- package/src/pr-status.ts +91 -0
- package/src/ref-gate-init.ts +30 -11
- package/src/release-floors.ts +78 -25
- package/src/render-module.ts +73 -0
- package/src/state-migration-record.test.ts +2 -3
- package/src/state-migration.ts +1 -2
- package/src/workspace/ci-green-cli.ts +3 -2
- package/src/workspace/ci-green-workflow.test.ts +32 -1
- package/src/workspace/release-train.ts +2 -1
- package/src/workspace/release-workflow.test.ts +36 -5
- package/src/workspace/release-workflow.ts +10 -7
- package/src/workspace/trust/check-evidence-report.ts +15 -8
- package/src/workspace/trust/check-evidence.test.ts +5 -0
- package/src/workspace/trust/ref-gate-cli.ts +30 -8
- package/src/workspace/trust/ref-gate-pieces.test.ts +46 -1
- package/src/workspace/trust/ref-gate.test.ts +10 -0
- package/src/workspace/workspace-run.ts +2 -1
|
@@ -23,6 +23,7 @@ import { join, resolve } from "node:path";
|
|
|
23
23
|
import type { ReleaseAdmission } from "../../lifecycle/release-ledger";
|
|
24
24
|
import { sortedJsonReplacer } from "../../utils";
|
|
25
25
|
import { archiveSourceTree, sha256Digest, type SourceArchive } from "../source-archive";
|
|
26
|
+
import { actorFromEnv } from "../../actor";
|
|
26
27
|
|
|
27
28
|
// ── sourceArchive ─────────────────────────────────────────────────────────────
|
|
28
29
|
|
|
@@ -149,7 +150,7 @@ export async function releaseRecord(args: ReleaseRecordArgs): Promise<ReleaseRec
|
|
|
149
150
|
return { recorded: false, digest: plan.digest, env, component, approver };
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
const actor = args.actor || process.env
|
|
153
|
+
const actor = args.actor || actorFromEnv(process.env, "");
|
|
153
154
|
if (!actor) throw new Error("releaseRecord: no actor: pass one, or set GITHUB_ACTOR, GITLAB_USER_LOGIN or USER");
|
|
154
155
|
const { runId, runOrigin } = resolveRunId(args.runId);
|
|
155
156
|
await persistReleasePlan(plan, opts);
|
|
@@ -26,6 +26,7 @@ import { realpathSync } from "node:fs";
|
|
|
26
26
|
import { join, resolve } from "node:path";
|
|
27
27
|
import type { ReleaseAdmission, ReleaseRecord, ReleaseRef } from "../../lifecycle/release-ledger";
|
|
28
28
|
import { archiveSourceTree } from "../source-archive";
|
|
29
|
+
import { actorFromEnv } from "../../actor";
|
|
29
30
|
import { readReleasePlan, releasePlan, releasePlanDigest } from "./source-release";
|
|
30
31
|
|
|
31
32
|
// ── releaseRollbackPlan ───────────────────────────────────────────────────────
|
|
@@ -219,7 +220,7 @@ export async function releaseRollbackRecord(args: ReleaseRollbackRecordArgs): Pr
|
|
|
219
220
|
return { recorded: false, digest: rollback.to, env, component, approver };
|
|
220
221
|
}
|
|
221
222
|
|
|
222
|
-
const actor = args.actor || process.env
|
|
223
|
+
const actor = args.actor || actorFromEnv(process.env, "");
|
|
223
224
|
if (!actor) throw new Error("releaseRollbackRecord: no actor: pass one, or set GITHUB_ACTOR, GITLAB_USER_LOGIN or USER");
|
|
224
225
|
const { runId, runOrigin } = resolveRunId(args.runId);
|
|
225
226
|
await appendReleaseRecord(
|
|
@@ -119,6 +119,33 @@ describe("resumeGateRun", () => {
|
|
|
119
119
|
expect(await resumeGateRun(gitlab, { token: "t", fetch: retried.fetch })).toMatchObject({ status: "skipped", reason: expect.stringContaining("job 556") });
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
+
test("GitLab (#4978): a wave job's evidence job that already ran is retried with it, and one GitLab skipped is left to GitLab", async () => {
|
|
123
|
+
const gitlab: GateRunLocator = { forge: "gitlab", api: "https://gl/api/v4", repo: "7", run: "100", job: "555", jobName: "wave-2-staging" };
|
|
124
|
+
const ran = fakeForge({
|
|
125
|
+
"GET /api/v4/projects/7/jobs/555": { status: "failed", name: "wave-2-staging" },
|
|
126
|
+
"GET /api/v4/projects/7/pipelines/100/jobs": [{ id: 555, name: "wave-2-staging", status: "failed" }, { id: 560, name: "wave-2-staging-evidence", status: "success" }],
|
|
127
|
+
"POST /api/v4/projects/7/jobs/555/retry": { id: 556 },
|
|
128
|
+
"POST /api/v4/projects/7/jobs/560/retry": { id: 561 },
|
|
129
|
+
});
|
|
130
|
+
expect(await resumeGateRun(gitlab, { token: "t", fetch: ran.fetch })).toMatchObject({ status: "resumed", how: "retried job 555 as job 556, and its evidence job 560 as job 561" });
|
|
131
|
+
// The wave job first, so the evidence job's need is the new try.
|
|
132
|
+
expect(ran.calls.filter((c) => c.method === "POST").map((c) => c.url)).toEqual(["https://gl/api/v4/projects/7/jobs/555/retry", "https://gl/api/v4/projects/7/jobs/560/retry"]);
|
|
133
|
+
|
|
134
|
+
const skipped = fakeForge({
|
|
135
|
+
"GET /api/v4/projects/7/jobs/555": { status: "failed", name: "wave-2-staging" },
|
|
136
|
+
"GET /api/v4/projects/7/pipelines/100/jobs": [{ id: 555, name: "wave-2-staging", status: "failed" }, { id: 560, name: "wave-2-staging-evidence", status: "skipped" }],
|
|
137
|
+
"POST /api/v4/projects/7/jobs/555/retry": { id: 556 },
|
|
138
|
+
});
|
|
139
|
+
expect(await resumeGateRun(gitlab, { token: "t", fetch: skipped.fetch })).toMatchObject({ status: "resumed", how: "retried job 555 as job 556" });
|
|
140
|
+
expect(skipped.calls.filter((c) => c.method === "POST")).toHaveLength(1);
|
|
141
|
+
|
|
142
|
+
const dry = fakeForge({
|
|
143
|
+
"GET /api/v4/projects/7/jobs/555": { status: "failed", name: "wave-2-staging" },
|
|
144
|
+
"GET /api/v4/projects/7/pipelines/100/jobs": [{ id: 555, name: "wave-2-staging", status: "failed" }, { id: 560, name: "wave-2-staging-evidence", status: "failed" }],
|
|
145
|
+
});
|
|
146
|
+
expect(await resumeGateRun(gitlab, { token: "t", fetch: dry.fetch, dryRun: true })).toMatchObject({ status: "would-resume", how: "would retry job 555 and its evidence job 560" });
|
|
147
|
+
});
|
|
148
|
+
|
|
122
149
|
test("Forgejo: dispatches the workflow on its branch, unless a run of it started after the approval", async () => {
|
|
123
150
|
const forgejo: GateRunLocator = { forge: "forgejo", api: "https://fj/api/v1", repo: "acme/db", run: "9", workflow: "migrations.yml", ref: "main" };
|
|
124
151
|
const forge = fakeForge({
|
package/src/op/index.ts
CHANGED
|
@@ -137,6 +137,16 @@ export {
|
|
|
137
137
|
} from "./op-waves-capability";
|
|
138
138
|
export type { OpWaveCostFormat, OpWaveCostHold, OpWaveCostVerdict, OpWaveHolds, OpWaveRunCost, OpWaveStep, OpWaveStepApply, OpWaveStepGroup, OpWaveStepPlan } from "./op-waves-capability";
|
|
139
139
|
export { notifyOpWave, opWaveNotifyFields } from "./op-waves-notify";
|
|
140
|
+
export {
|
|
141
|
+
OP_WAVES_RENDER_SPEC_FLAG,
|
|
142
|
+
OP_WAVES_SPEC_AT_ENV,
|
|
143
|
+
OP_WAVES_SPEC_COMMAND_ENV,
|
|
144
|
+
OP_WAVES_SPEC_FILE_ENV,
|
|
145
|
+
RUNTIME_WAVES_SPEC_FLOOR,
|
|
146
|
+
opWavesRenderSpecEnv,
|
|
147
|
+
opWavesRenderSpecProblems,
|
|
148
|
+
} from "./op-waves-render-spec";
|
|
149
|
+
export type { OpWavesRenderSpec } from "./op-waves-render-spec";
|
|
140
150
|
export { OP_WAVE_STAND_DOWN_FLOOR, gitOpWaveNewerCommit, newerCommitOnBranch, opWaveRunBranch, opWaveStandDownReason, tipAppliesTargets } from "./op-waves-stand-down";
|
|
141
151
|
export type { OpWaveNewerCommit, OpWaveNewerCommitPort } from "./op-waves-stand-down";
|
|
142
152
|
export { OP_WAVE_RELEASE_RECORD_FLOOR, opWaveReleaseNames, opWaveReleaseProblems, releaseOfCommit } from "./op-waves-release";
|
|
@@ -15,7 +15,11 @@
|
|
|
15
15
|
* policy, and `plan:<wave>` too when the wave trades cloud credentials and
|
|
16
16
|
* signs keyless, since after the trade no step of the wave job may request
|
|
17
17
|
* the signing token (#4869).
|
|
18
|
-
* - signs `plan:<wave>` in its command step otherwise, as before (#4870)
|
|
18
|
+
* - signs `plan:<wave>` in its command step otherwise, as before (#4870),
|
|
19
|
+
* except on GitLab with a runner key (#4964): a wave job names its own
|
|
20
|
+
* deploy environment, so it cannot name the `chant-evidence` one the
|
|
21
|
+
* key's variable is scoped to, and the evidence job, which does, signs
|
|
22
|
+
* `plan:<wave>` from the wave job's status and claim file.
|
|
19
23
|
*
|
|
20
24
|
* A wave with no policy and no keyless cloud trade renders as before.
|
|
21
25
|
* A later wave whose `evidence.requires` names a check an earlier wave's
|
|
@@ -51,15 +55,17 @@ export interface OpWaveEvidencePlan {
|
|
|
51
55
|
* pipeline). `keylessCloud` is whether the job signs keyless and trades
|
|
52
56
|
* cloud credentials.
|
|
53
57
|
*/
|
|
54
|
-
export function opWaveEvidencePlan(spec: Pick<OpWavesSpec, "holds" | "waves">, job: Pick<OpWaveJob, "kind" | "jobName" | "wave">, opts: { signs: boolean; keylessCloud: boolean }): OpWaveEvidencePlan | undefined {
|
|
58
|
+
export function opWaveEvidencePlan(spec: Pick<OpWavesSpec, "holds" | "waves">, job: Pick<OpWaveJob, "kind" | "jobName" | "wave">, opts: { signs: boolean; keylessCloud: boolean; keyOutOfWave?: boolean }): OpWaveEvidencePlan | undefined {
|
|
55
59
|
if (!opts.signs || (job.kind !== "wave" && job.kind !== "decide")) return undefined;
|
|
56
60
|
const name = spec.waves[job.wave - 1]!.name;
|
|
57
61
|
const plan = `plan:${name}`;
|
|
58
62
|
const policy = `policy:${name}`;
|
|
59
63
|
const policyStep = spec.holds?.policy === true;
|
|
60
|
-
|
|
64
|
+
// #4964: with `keyOutOfWave` (GitLab with a runner key) the wave job holds no key, so its evidence job signs the plan too.
|
|
65
|
+
const inJob = opts.keylessCloud || opts.keyOutOfWave === true;
|
|
66
|
+
const checks = [...(inJob ? [plan] : []), ...(policyStep ? [policy] : [])];
|
|
61
67
|
if (checks.length === 0) return { plan, policy, policyStep, commandSigns: true };
|
|
62
|
-
return { plan, policy, policyStep, commandMode:
|
|
68
|
+
return { plan, policy, policyStep, commandMode: inJob ? "job" : "plan", commandSigns: !inJob, evidenceJob: { name: `${job.jobName}-evidence`, checks } };
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
/** The GitLab job a wave's policy runs in (#4926). */
|
|
@@ -7,6 +7,7 @@ import { afterEach, describe, expect, test } from "vitest";
|
|
|
7
7
|
import { assertProductWords, CHANT_WORDS, notifyWaveLabel, productWordsProblems, resolveProductWords, setActiveProductWords } from "../ci-product-words";
|
|
8
8
|
import { makeNotifyEvent, slackMessage, teamsMessage, verifyWebhook, type NotifyFetch, type NotifyFields } from "../notify";
|
|
9
9
|
import { driftNotifyFields, productSendOptions } from "../notify-product";
|
|
10
|
+
import { driftRunFingerprint, type DriftIssueRecord } from "../drift-issue";
|
|
10
11
|
import type { OpWavesSpec } from "./op-waves";
|
|
11
12
|
import { notifyOpWave, opWaveNotifyFields, type OpWaveOutcome } from "./op-waves-notify";
|
|
12
13
|
|
|
@@ -97,6 +98,23 @@ describe("notify words (#4610)", () => {
|
|
|
97
98
|
expect(driftNotifyFields(CHANT_WORDS, { changed: ["net"], failed: ["db"] }).summary).toBe("1 member drifted: net; 1 member could not be refreshed: db");
|
|
98
99
|
});
|
|
99
100
|
|
|
101
|
+
test("a drift notice given the stacks' records names the drifted ones and computes the run's fingerprint (#4944)", () => {
|
|
102
|
+
const record = (member: string, status: "drifted" | "in-sync"): DriftIssueRecord => ({ member, address: "bucket", status, ...(status === "drifted" ? { attributes: [{ path: "acl", before: "private", after: "public-read" }] } : {}) });
|
|
103
|
+
const stacks = [
|
|
104
|
+
{ stack: "shop-prod", records: [record("shop-prod", "drifted")] },
|
|
105
|
+
{ stack: "shop-dev", records: [record("shop-dev", "in-sync")] },
|
|
106
|
+
{ stack: "shop-eu", records: [record("shop-eu", "drifted")] },
|
|
107
|
+
];
|
|
108
|
+
const fields = driftNotifyFields(PLYWOOD, { stacks, failed: ["shop-us"] });
|
|
109
|
+
expect(fields).toMatchObject({
|
|
110
|
+
summary: "2 stacks drifted: shop-prod, shop-eu; 1 stack could not be refreshed: shop-us",
|
|
111
|
+
targets: ["shop-prod", "shop-eu"],
|
|
112
|
+
drift: { changed: ["shop-prod", "shop-eu"], failed: ["shop-us"], fingerprint: driftRunFingerprint(stacks) },
|
|
113
|
+
});
|
|
114
|
+
expect(driftNotifyFields(PLYWOOD, { stacks, fingerprint: "fp" }).drift?.fingerprint).toBe("fp");
|
|
115
|
+
expect(driftNotifyFields(PLYWOOD, { stacks, changed: ["shop-prod"] }).drift?.changed).toEqual(["shop-prod"]);
|
|
116
|
+
});
|
|
117
|
+
|
|
100
118
|
test("sql-yodeler's words keep source sql-yodeler while its product word is yodel", () => {
|
|
101
119
|
expect(YODEL.notify).toEqual({ source: "sql-yodeler", wave: "wave {k} ({name}) of {spec}", headers: "x-yodel" });
|
|
102
120
|
expect(opWaveNotifyFields(spec, 2, outcomes.failed!, {}, YODEL)).toMatchObject({ source: "sql-yodeler" });
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4982: a waves spec the job renders at run time. The product's command
|
|
3
|
+
* prints the spec at the commit chant hands it, the job runs on the spec it
|
|
4
|
+
* printed at base, and the gate policy is read from that same render, so a
|
|
5
|
+
* change that loosens the product's config at its head does not loosen its
|
|
6
|
+
* own gate.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
10
|
+
import { execFileSync } from "node:child_process";
|
|
11
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { tmpdir } from "node:os";
|
|
14
|
+
import { gitShowAtBase, parseOpWavesSpec, readOpWavePolicy, runOpWave, type OpWaveExec } from "./op-waves-run";
|
|
15
|
+
import { memoryGateLedgerPort } from "./gate";
|
|
16
|
+
import {
|
|
17
|
+
commandSpecRender,
|
|
18
|
+
OP_WAVES_SPEC_COMMAND_ENV,
|
|
19
|
+
opWavesRenderSpecEnv,
|
|
20
|
+
opWavesSpecCommandFromEnv,
|
|
21
|
+
renderedJobMissing,
|
|
22
|
+
renderedSpecShow,
|
|
23
|
+
renderOpWavesSpecFile,
|
|
24
|
+
RUNTIME_WAVES_SPEC_FLOOR,
|
|
25
|
+
} from "./op-waves-render-spec";
|
|
26
|
+
import { NEXT_RELEASE } from "../release-floors";
|
|
27
|
+
import type { OpWavesSpec } from "./op-waves";
|
|
28
|
+
import { parseArgs } from "../cli/parse-args";
|
|
29
|
+
import { runOpWaveCommand } from "../cli/handlers/run-wave";
|
|
30
|
+
import type { CommandContext } from "../cli/registry";
|
|
31
|
+
|
|
32
|
+
const SPEC_FILE = ".chant/op-waves/tf-apply.spec.json";
|
|
33
|
+
|
|
34
|
+
/** A product's command: the spec, with wave dev's gate and shares read from `config.json` at the commit chant names. */
|
|
35
|
+
const RENDER_JS = `
|
|
36
|
+
const { execFileSync } = require("node:child_process");
|
|
37
|
+
const at = process.env.CHANT_WAVES_SPEC_AT;
|
|
38
|
+
if (process.env.RENDER_FAIL) process.exit(2);
|
|
39
|
+
let config;
|
|
40
|
+
try { config = JSON.parse(execFileSync("git", ["show", at + ":config.json"], { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] })); } catch { process.exit(0); }
|
|
41
|
+
process.stdout.write(JSON.stringify({
|
|
42
|
+
name: "tf-apply", op: "tf-apply",
|
|
43
|
+
plan: ["tool", "plan", "{target}", "--out", "{plan}"], apply: ["tool", "apply", "{target}", "--plan", "{plan}"],
|
|
44
|
+
waves: [{ name: "dev", gate: config.gate, shares: config.shares, runs: [{ target: "a" }, { target: "b" }] }],
|
|
45
|
+
}));
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
let repo: string;
|
|
49
|
+
let tools: string;
|
|
50
|
+
let command: string[];
|
|
51
|
+
const git = (...args: string[]) => execFileSync("git", args, { cwd: repo, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
52
|
+
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
repo = mkdtempSync(join(tmpdir(), "op-waves-render-"));
|
|
55
|
+
tools = mkdtempSync(join(tmpdir(), "op-waves-render-tool-"));
|
|
56
|
+
writeFileSync(join(tools, "render.cjs"), RENDER_JS);
|
|
57
|
+
command = [process.execPath, join(tools, "render.cjs")];
|
|
58
|
+
git("init", "-q", "-b", "main");
|
|
59
|
+
git("config", "user.email", "t@example.com");
|
|
60
|
+
git("config", "user.name", "t");
|
|
61
|
+
writeFileSync(join(repo, "config.json"), JSON.stringify({ gate: "always", shares: 2 }));
|
|
62
|
+
git("add", ".");
|
|
63
|
+
git("commit", "-q", "-m", "base");
|
|
64
|
+
// The change loosens the gate in the product's config.
|
|
65
|
+
writeFileSync(join(repo, "config.json"), JSON.stringify({ gate: "never", shares: 2 }));
|
|
66
|
+
git("commit", "-q", "-am", "loosen");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
afterEach(() => {
|
|
70
|
+
delete process.env.RENDER_FAIL;
|
|
71
|
+
rmSync(repo, { recursive: true, force: true });
|
|
72
|
+
rmSync(tools, { recursive: true, force: true });
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("a waves spec the job renders at run time (#4982)", () => {
|
|
76
|
+
test("the gate policy comes from the spec the command prints at base, not from the change's config", () => {
|
|
77
|
+
const show = renderedSpecShow(SPEC_FILE, commandSpecRender(command, SPEC_FILE, repo), gitShowAtBase);
|
|
78
|
+
const rules = readOpWavePolicy(SPEC_FILE, "dev", "HEAD^1", repo, show);
|
|
79
|
+
expect(rules).toMatchObject({ policy: "always", source: "base", base: git("rev-parse", "HEAD^1") });
|
|
80
|
+
// Without the render there is no spec at base at all.
|
|
81
|
+
expect(readOpWavePolicy(SPEC_FILE, "dev", "HEAD^1", repo).source).toBe("absent-at-base");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("the job's spec is rendered once per commit and written over the spec file", () => {
|
|
85
|
+
let calls = 0;
|
|
86
|
+
const render = commandSpecRender(command, SPEC_FILE, repo);
|
|
87
|
+
const show = renderedSpecShow(SPEC_FILE, (sha) => (calls++, render(sha)), gitShowAtBase);
|
|
88
|
+
const { spec, sha } = renderOpWavesSpecFile({ specFile: SPEC_FILE, base: "HEAD^1", cwd: repo, show, parse: parseOpWavesSpec });
|
|
89
|
+
expect(sha).toBe(git("rev-parse", "HEAD^1"));
|
|
90
|
+
expect(spec.waves[0]).toMatchObject({ name: "dev", gate: "always" });
|
|
91
|
+
expect(parseOpWavesSpec(readFileSync(join(repo, SPEC_FILE), "utf-8"), "file").waves[0]!.gate).toBe("always");
|
|
92
|
+
readOpWavePolicy(SPEC_FILE, "dev", "HEAD^1", repo, show);
|
|
93
|
+
expect(calls).toBe(1);
|
|
94
|
+
// Any other file is read through git.
|
|
95
|
+
expect(show("HEAD", "config.json", repo).text).toContain('"never"');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("a wave on the rendered spec waits under the gate at base, whatever the change's config says", async () => {
|
|
99
|
+
const show = renderedSpecShow(SPEC_FILE, commandSpecRender(command, SPEC_FILE, repo), gitShowAtBase);
|
|
100
|
+
const { spec } = renderOpWavesSpecFile({ specFile: SPEC_FILE, base: "HEAD^1", cwd: repo, show, parse: parseOpWavesSpec });
|
|
101
|
+
const applied: string[] = [];
|
|
102
|
+
const exec: OpWaveExec = (argv, dir) => {
|
|
103
|
+
if (argv[1] === "plan") writeFileSync(join(dir, argv[4]!), JSON.stringify({ planDigest: `sha256:${"1".repeat(64)}`, changes: { create: 1 } }));
|
|
104
|
+
if (argv[1] === "apply") applied.push(argv[2]!);
|
|
105
|
+
return 0;
|
|
106
|
+
};
|
|
107
|
+
const result = await runOpWave({ spec: { ...spec, waves: [{ ...spec.waves[0]!, shares: undefined }] }, specFile: SPEC_FILE, wave: 1, cwd: repo, exec, show, gates: memoryGateLedgerPort(), head: git("rev-parse", "HEAD") });
|
|
108
|
+
expect(result.exitCode).toBe(3);
|
|
109
|
+
expect(result.decision).toMatchObject({ status: "waiting", policy: "always" });
|
|
110
|
+
expect(applied).toEqual([]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("a command that fails fails the job; one that prints nothing reads as no spec at that commit", () => {
|
|
114
|
+
process.env.RENDER_FAIL = "1";
|
|
115
|
+
const failing = renderedSpecShow(SPEC_FILE, commandSpecRender(command, SPEC_FILE, repo), gitShowAtBase);
|
|
116
|
+
expect(() => readOpWavePolicy(SPEC_FILE, "dev", "HEAD^1", repo, failing)).toThrow(/the spec command \(.*render\.cjs\) exited 2 at [0-9a-f]{12}/);
|
|
117
|
+
delete process.env.RENDER_FAIL;
|
|
118
|
+
git("rm", "-q", "config.json");
|
|
119
|
+
git("commit", "-q", "-m", "drop the config");
|
|
120
|
+
const empty = renderedSpecShow(SPEC_FILE, commandSpecRender(command, SPEC_FILE, repo), gitShowAtBase);
|
|
121
|
+
expect(readOpWavePolicy(SPEC_FILE, "dev", "HEAD", repo, empty)).toMatchObject({ policy: "always", source: "absent-at-base" });
|
|
122
|
+
expect(() => renderOpWavesSpecFile({ specFile: SPEC_FILE, base: "HEAD", cwd: repo, show: empty, parse: parseOpWavesSpec })).toThrow(/printed no spec at HEAD/);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("a share or job group the shape has and the rendered spec does not has nothing to apply", () => {
|
|
126
|
+
const spec: OpWavesSpec = { name: "s", op: "o", plan: ["p"], apply: ["a"], waves: [{ name: "w", runs: [{ target: "a" }, { target: "b" }], shares: 2 }, { name: "g", runs: [{ target: "a" }], jobs: [{ name: "eu", runs: ["a"], shares: 2 }] }] };
|
|
127
|
+
expect(renderedJobMissing(spec, 1, { share: 2 })).toBeUndefined();
|
|
128
|
+
expect(renderedJobMissing(spec, 1, { share: 3 })).toBe("wave 1 (w) has 2 shares in the spec rendered at base");
|
|
129
|
+
expect(renderedJobMissing(spec, 2, { group: "us" })).toBe('wave 2 (g) has no job group "us" in the spec rendered at base');
|
|
130
|
+
expect(renderedJobMissing(spec, 2, { group: "eu", share: 3 })).toBe('job group "eu" of wave 2 (g) has 2 shares in the spec rendered at base');
|
|
131
|
+
expect(renderedJobMissing(spec, 2, { group: "eu", share: 1 })).toBeUndefined();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("the command comes from CHANT_WAVES_SPEC_COMMAND as a JSON list of words", () => {
|
|
135
|
+
expect(opWavesSpecCommandFromEnv({ [OP_WAVES_SPEC_COMMAND_ENV]: '["terragucci","waves-spec"]' })).toEqual(["terragucci", "waves-spec"]);
|
|
136
|
+
expect(() => opWavesSpecCommandFromEnv({})).toThrow(/CHANT_WAVES_SPEC_COMMAND names, and it is unset/);
|
|
137
|
+
expect(() => opWavesSpecCommandFromEnv({ [OP_WAVES_SPEC_COMMAND_ENV]: "terragucci waves-spec" })).toThrow(/must be a JSON list of words/);
|
|
138
|
+
expect(opWavesRenderSpecEnv({ command: ["terragucci", "waves-spec"] })).toEqual({ CHANT_WAVES_SPEC_COMMAND: '["terragucci","waves-spec"]' });
|
|
139
|
+
expect(opWavesRenderSpecEnv(undefined)).toEqual({});
|
|
140
|
+
expect(() => opWavesRenderSpecEnv({ command: [] })).toThrow(/renderSpec.command must be/);
|
|
141
|
+
expect(RUNTIME_WAVES_SPEC_FLOOR).toBe(NEXT_RELEASE);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("chant run wave --render-spec writes the rendered spec, and a share it does not have exits 0", async () => {
|
|
145
|
+
const was = process.cwd();
|
|
146
|
+
const env = process.env[OP_WAVES_SPEC_COMMAND_ENV];
|
|
147
|
+
process.env[OP_WAVES_SPEC_COMMAND_ENV] = JSON.stringify(command);
|
|
148
|
+
process.chdir(repo);
|
|
149
|
+
try {
|
|
150
|
+
const ctx = { args: parseArgs(["run", "wave", "--spec", SPEC_FILE, "--wave", "1", "--share", "3", "--render-spec"]), plugins: [], serializers: [] } as unknown as CommandContext;
|
|
151
|
+
expect(ctx.args.renderSpec).toBe(true);
|
|
152
|
+
expect(await runOpWaveCommand(ctx)).toBe(0);
|
|
153
|
+
expect(parseOpWavesSpec(readFileSync(join(repo, SPEC_FILE), "utf-8"), "file").waves[0]).toMatchObject({ gate: "always", shares: 2 });
|
|
154
|
+
} finally {
|
|
155
|
+
process.chdir(was);
|
|
156
|
+
if (env === undefined) delete process.env[OP_WAVES_SPEC_COMMAND_ENV];
|
|
157
|
+
else process.env[OP_WAVES_SPEC_COMMAND_ENV] = env;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A waves spec the job renders at run time (#4982).
|
|
3
|
+
*
|
|
4
|
+
* A generated waves pipeline reads its spec from the file at `specFile`,
|
|
5
|
+
* and each wave job reads the gate policy from that file at the base
|
|
6
|
+
* commit. A product whose spec is built from its own config (terragucci
|
|
7
|
+
* builds `tf-apply` from `terragucci.yml` at base: the gate per
|
|
8
|
+
* environment, the approval mode, the policy and cost holds) cannot commit
|
|
9
|
+
* the spec once, so it used to render its own apply-wave jobs.
|
|
10
|
+
*
|
|
11
|
+
* With `renderSpec` on the generator's options, every wave, deciding and
|
|
12
|
+
* share job, and the policy step, runs `chant run wave --render-spec`, and
|
|
13
|
+
* `CHANT_WAVES_SPEC_COMMAND` on the job holds the product command that
|
|
14
|
+
* prints the spec, as a JSON argv. chant runs that command with
|
|
15
|
+
* `CHANT_WAVES_SPEC_AT` set to a commit and reads the spec from its
|
|
16
|
+
* standard output:
|
|
17
|
+
*
|
|
18
|
+
* - at the base, for the spec the job runs, which chant writes over the
|
|
19
|
+
* file at `specFile` so the hooks, the decision record and the share
|
|
20
|
+
* jobs read the same one;
|
|
21
|
+
* - at the base again, for the gate policy, the holds, the hooks and the
|
|
22
|
+
* evidence rules (`readOpWavePolicy`), in place of `git show
|
|
23
|
+
* <base>:<specFile>`;
|
|
24
|
+
* - at a newer commit on the branch, for the stand-down (#4581).
|
|
25
|
+
*
|
|
26
|
+
* The command's output is the gate policy, so it must read the product's
|
|
27
|
+
* config at the commit it is handed (`git show "$CHANT_WAVES_SPEC_AT:<file>"`),
|
|
28
|
+
* never from the working tree, which holds the change. It exits 0 and
|
|
29
|
+
* prints nothing when that commit has no config, which reads as a spec
|
|
30
|
+
* missing at base: every wave's gate is `always`. Any other exit fails the
|
|
31
|
+
* job.
|
|
32
|
+
*
|
|
33
|
+
* The spec the generator is handed is the pipeline's shape: its waves'
|
|
34
|
+
* names, shares and job groups, runners, environments, `cloud` and
|
|
35
|
+
* `holds.policy` decide the jobs and their steps. The rendered spec decides
|
|
36
|
+
* the rules. A share or job group the shape has and the rendered spec does
|
|
37
|
+
* not applies nothing and exits 0, since the job exists before the runs
|
|
38
|
+
* are known.
|
|
39
|
+
*
|
|
40
|
+
* Nothing here imports the wave runner, so the generators' bundles take
|
|
41
|
+
* the variables without it; `chant run wave` hands in its git reader.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
import { execFileSync } from "node:child_process";
|
|
45
|
+
import { writeFileSync, mkdirSync } from "node:fs";
|
|
46
|
+
import { dirname, isAbsolute, join, posix } from "node:path";
|
|
47
|
+
import type { OpWaveShowAtBase } from "./op-waves-run";
|
|
48
|
+
import type { OpWavesSpec } from "./op-waves";
|
|
49
|
+
|
|
50
|
+
export { RUNTIME_WAVES_SPEC_FLOOR } from "../release-floors";
|
|
51
|
+
|
|
52
|
+
/** The job variable that holds the product command printing the spec, as a JSON argv. */
|
|
53
|
+
export const OP_WAVES_SPEC_COMMAND_ENV = "CHANT_WAVES_SPEC_COMMAND";
|
|
54
|
+
/** The variable chant hands that command: the full commit to render the spec at. */
|
|
55
|
+
export const OP_WAVES_SPEC_AT_ENV = "CHANT_WAVES_SPEC_AT";
|
|
56
|
+
/** The variable chant hands that command: the spec file's path, as the job names it. */
|
|
57
|
+
export const OP_WAVES_SPEC_FILE_ENV = "CHANT_WAVES_SPEC_FILE";
|
|
58
|
+
/** The `chant run wave` flag that renders the spec before the job runs. */
|
|
59
|
+
export const OP_WAVES_RENDER_SPEC_FLAG = "--render-spec";
|
|
60
|
+
|
|
61
|
+
/** `OpWavesPipelineOptions.renderSpec` (#4982). */
|
|
62
|
+
export interface OpWavesRenderSpec {
|
|
63
|
+
/** The product command that prints the spec at `CHANT_WAVES_SPEC_AT`, such as `["terragucci", "waves-spec"]`. */
|
|
64
|
+
command: string[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** What is wrong with a `renderSpec`, or nothing. */
|
|
68
|
+
export function opWavesRenderSpecProblems(value: unknown): string[] {
|
|
69
|
+
const command = (value as { command?: unknown } | null)?.command;
|
|
70
|
+
if (!Array.isArray(command) || command.length === 0 || command.some((w) => typeof w !== "string" || w.length === 0)) {
|
|
71
|
+
return ['renderSpec.command must be the product command that prints the spec, as a list of words: ["terragucci", "waves-spec"]'];
|
|
72
|
+
}
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The variables a wave job carries for `renderSpec`, or none without it. Throws on a `renderSpec` that is wrong. */
|
|
77
|
+
export function opWavesRenderSpecEnv(renderSpec: OpWavesRenderSpec | undefined): Record<string, string> {
|
|
78
|
+
if (renderSpec === undefined) return {};
|
|
79
|
+
const problems = opWavesRenderSpecProblems(renderSpec);
|
|
80
|
+
if (problems.length > 0) throw new Error(problems.join("; "));
|
|
81
|
+
return { [OP_WAVES_SPEC_COMMAND_ENV]: JSON.stringify(renderSpec.command) };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The product command `CHANT_WAVES_SPEC_COMMAND` names. Throws when it is unset or not a JSON list of words. */
|
|
85
|
+
export function opWavesSpecCommandFromEnv(env: NodeJS.ProcessEnv = process.env): string[] {
|
|
86
|
+
const raw = env[OP_WAVES_SPEC_COMMAND_ENV];
|
|
87
|
+
if (!raw) throw new Error(`${OP_WAVES_RENDER_SPEC_FLAG} runs the command ${OP_WAVES_SPEC_COMMAND_ENV} names, and it is unset`);
|
|
88
|
+
let command: unknown;
|
|
89
|
+
try {
|
|
90
|
+
command = JSON.parse(raw);
|
|
91
|
+
} catch {
|
|
92
|
+
command = undefined;
|
|
93
|
+
}
|
|
94
|
+
if (opWavesRenderSpecProblems({ command }).length > 0) throw new Error(`${OP_WAVES_SPEC_COMMAND_ENV} must be a JSON list of words, such as ["terragucci","waves-spec"]: got ${raw}`);
|
|
95
|
+
return command as string[];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Prints the spec at a full commit, or null when that commit has none. Injected for tests. */
|
|
99
|
+
export type OpWavesSpecRender = (sha: string) => string | null;
|
|
100
|
+
|
|
101
|
+
/** {@link OpWavesSpecRender} through the product's command, run in `cwd`. Its standard error goes to the job's log. */
|
|
102
|
+
export function commandSpecRender(command: readonly string[], specFile: string, cwd: string): OpWavesSpecRender {
|
|
103
|
+
return (sha) => {
|
|
104
|
+
let out: string;
|
|
105
|
+
try {
|
|
106
|
+
out = execFileSync(command[0]!, command.slice(1), {
|
|
107
|
+
cwd,
|
|
108
|
+
encoding: "utf-8",
|
|
109
|
+
stdio: ["ignore", "pipe", "inherit"],
|
|
110
|
+
env: { ...process.env, [OP_WAVES_SPEC_AT_ENV]: sha, [OP_WAVES_SPEC_FILE_ENV]: specFile },
|
|
111
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
112
|
+
});
|
|
113
|
+
} catch (err) {
|
|
114
|
+
const status = (err as { status?: number | null }).status;
|
|
115
|
+
throw new Error(`the spec command (${command.join(" ")}) ${typeof status === "number" ? `exited ${status}` : `did not run: ${err instanceof Error ? err.message : String(err)}`} at ${sha.slice(0, 12)}, so the wave's spec cannot be read`);
|
|
116
|
+
}
|
|
117
|
+
return out.trim() === "" ? null : out;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const posixPath = (p: string): string => p.replace(/^\.\//, "").split("\\").join(posix.sep);
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* An {@link OpWaveShowAtBase} that reads `specFile` at any commit from
|
|
125
|
+
* `render`, once per commit, and every other file through `fallback`
|
|
126
|
+
* (git, `gitShowAtBase`), which also resolves the commit.
|
|
127
|
+
*/
|
|
128
|
+
export function renderedSpecShow(specFile: string, render: OpWavesSpecRender, fallback: OpWaveShowAtBase): OpWaveShowAtBase {
|
|
129
|
+
const target = posixPath(specFile);
|
|
130
|
+
const seen = new Map<string, string | null>();
|
|
131
|
+
return (base, path, cwd) => {
|
|
132
|
+
if (posixPath(path) !== target) return fallback(base, path, cwd);
|
|
133
|
+
const { sha } = fallback(base, path, cwd);
|
|
134
|
+
if (!seen.has(sha)) seen.set(sha, render(sha));
|
|
135
|
+
return { sha, text: seen.get(sha)! };
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Render the job's spec at `base` (#4982): read it through `show`, parse it
|
|
141
|
+
* with `parse` (`parseOpWavesSpec`), write it over `specFile` in `cwd`, and
|
|
142
|
+
* return it. Throws when the command printed no spec, or one chant cannot
|
|
143
|
+
* read.
|
|
144
|
+
*/
|
|
145
|
+
export function renderOpWavesSpecFile(options: { specFile: string; base: string; cwd: string; show: OpWaveShowAtBase; parse: (text: string, where: string) => OpWavesSpec }): { spec: OpWavesSpec; sha: string } {
|
|
146
|
+
const { sha, text } = options.show(options.base, options.specFile, options.cwd);
|
|
147
|
+
if (text === null) throw new Error(`the spec command printed no spec at ${options.base} (${sha.slice(0, 12)}), so the wave has nothing to run`);
|
|
148
|
+
const spec = options.parse(text, `the spec rendered at ${sha.slice(0, 12)}`);
|
|
149
|
+
const path = isAbsolute(options.specFile) ? options.specFile : join(options.cwd, options.specFile);
|
|
150
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
151
|
+
writeFileSync(path, text.endsWith("\n") ? text : `${text}\n`);
|
|
152
|
+
return { spec, sha };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Whether job `job` of wave `k` has anything in the rendered spec: a share
|
|
157
|
+
* past the wave's (or the group's) shares, or a group the wave does not
|
|
158
|
+
* have, has nothing. Undefined when it has; otherwise why not.
|
|
159
|
+
*/
|
|
160
|
+
export function renderedJobMissing(spec: OpWavesSpec, k: number, job: { share?: number; group?: string }): string | undefined {
|
|
161
|
+
const wave = spec.waves[k - 1];
|
|
162
|
+
if (!wave) return undefined;
|
|
163
|
+
if (job.group !== undefined) {
|
|
164
|
+
const group = wave.jobs?.find((g) => g.name === job.group);
|
|
165
|
+
if (!group) return `wave ${k} (${wave.name}) has no job group "${job.group}" in the spec rendered at base`;
|
|
166
|
+
if (job.share !== undefined && job.share > (group.shares ?? 1)) return `job group "${job.group}" of wave ${k} (${wave.name}) has ${group.shares ?? 1} share${(group.shares ?? 1) === 1 ? "" : "s"} in the spec rendered at base`;
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
if (job.share !== undefined && wave.jobs === undefined && job.share > (wave.shares ?? 1)) return `wave ${k} (${wave.name}) has ${wave.shares ?? 1} share${(wave.shares ?? 1) === 1 ? "" : "s"} in the spec rendered at base`;
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
package/src/op/op-waves-run.ts
CHANGED
|
@@ -578,7 +578,8 @@ export interface OpWaveApplyHooksRun {
|
|
|
578
578
|
/** Reads one file at one commit, or null when the commit has no such file. Injected for tests. */
|
|
579
579
|
export type OpWaveShowAtBase = (base: string, path: string, cwd: string) => { sha: string; text: string | null };
|
|
580
580
|
|
|
581
|
-
|
|
581
|
+
/** {@link OpWaveShowAtBase} through git: `git show <base>:<path>`. A run-time spec (#4982, `./op-waves-render-spec.ts`) reads every other file through it. */
|
|
582
|
+
export const gitShowAtBase: OpWaveShowAtBase = (base, path, cwd) => {
|
|
582
583
|
let sha: string;
|
|
583
584
|
try {
|
|
584
585
|
sha = execFileSync("git", ["rev-parse", "--verify", `${base}^{commit}`], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
package/src/op/op-waves.ts
CHANGED
|
@@ -1462,14 +1462,17 @@ export function opWaveShare<T extends { target: string }>(runs: readonly T[], sh
|
|
|
1462
1462
|
* The jobs of an Op waves pipeline, in order. `specFile` is the spec's path
|
|
1463
1463
|
* from the job's working directory, which every command names. `bin` is the
|
|
1464
1464
|
* product's command in place of `chant` (#4607, {@link opWaveBinArgv}).
|
|
1465
|
+
* With `renderSpec` (#4982) every command passes `--render-spec`: the job
|
|
1466
|
+
* renders the spec at base through the product's command
|
|
1467
|
+
* (`./op-waves-render-spec.ts`), and `spec` is the pipeline's shape.
|
|
1465
1468
|
*/
|
|
1466
|
-
export function opWaveJobs(spec: OpWavesSpec, specFile: string, options: { bin?: string } = {}): OpWaveJob[] {
|
|
1469
|
+
export function opWaveJobs(spec: OpWavesSpec, specFile: string, options: { bin?: string; renderSpec?: boolean } = {}): OpWaveJob[] {
|
|
1467
1470
|
assertOpWavesSpec(spec);
|
|
1468
1471
|
const jobs: OpWaveJob[] = [];
|
|
1469
1472
|
let previous: string[] = [];
|
|
1470
1473
|
spec.waves.forEach((wave, index) => {
|
|
1471
1474
|
const k = index + 1;
|
|
1472
|
-
const command = [...opWaveBinArgv(options.bin), "run", "wave", "--spec", specFile, "--wave", String(k), ...(spec.base ? ["--base", spec.base] : [])];
|
|
1475
|
+
const command = [...opWaveBinArgv(options.bin), "run", "wave", "--spec", specFile, "--wave", String(k), ...(spec.base ? ["--base", spec.base] : []), ...(options.renderSpec ? ["--render-spec"] : [])];
|
|
1473
1476
|
const prefix = `wave-${k}-${wave.name}`;
|
|
1474
1477
|
const shares = wave.shares ?? 1;
|
|
1475
1478
|
if (shares === 1 && wave.jobs === undefined) {
|
|
@@ -309,6 +309,49 @@ describe("checkOverdueOps", () => {
|
|
|
309
309
|
expect(asked).toEqual([schedule]);
|
|
310
310
|
expect(found[0]?.message).toContain("No active pipeline schedule is picked by the Op's rule, one whose TERRAGUCCI_SCHEDULE is none of comments, resume.");
|
|
311
311
|
});
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* #4952: a shallow checkout's oldest commit lists every file as added, so
|
|
315
|
+
* the job that never ran counts from that commit and the check
|
|
316
|
+
* under-reports. The check deepens the history and reads the real commit.
|
|
317
|
+
*/
|
|
318
|
+
describe("a shallow checkout", () => {
|
|
319
|
+
function shallowClone(): string {
|
|
320
|
+
const origin = repo({ ".github/workflows/drift.yml": "on: schedule" }, "2026-09-01T00:00:00Z");
|
|
321
|
+
const later = "2026-10-20T00:00:00Z";
|
|
322
|
+
writeFileSync(join(origin, "README.md"), "later\n");
|
|
323
|
+
execFileSync("git", ["-C", origin, "add", "."], { stdio: "pipe" });
|
|
324
|
+
execFileSync("git", ["-C", origin, "-c", "user.name=t", "-c", "user.email=t@example.com", "commit", "-q", "-m", "later"], { env: { ...process.env, GIT_COMMITTER_DATE: later, GIT_AUTHOR_DATE: later }, stdio: "pipe" });
|
|
325
|
+
const clone = join(origin, ".clone");
|
|
326
|
+
execFileSync("git", ["clone", "-q", "--depth", "1", `file://${origin}`, clone], { stdio: "pipe" });
|
|
327
|
+
return clone;
|
|
328
|
+
}
|
|
329
|
+
const run = (root: string, lines: string[]) =>
|
|
330
|
+
checkOverdueOps({
|
|
331
|
+
watches: [{ op: "drift", cron: "0 6 * * *" }],
|
|
332
|
+
forge: forgeWith("github", async () => ({})),
|
|
333
|
+
repoRoot: root,
|
|
334
|
+
now: new Date("2026-10-22T00:00:00Z"),
|
|
335
|
+
log: (l) => lines.push(l),
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test("deepens the history and counts from the commit that added the file", async () => {
|
|
339
|
+
const clone = shallowClone();
|
|
340
|
+
const lines: string[] = [];
|
|
341
|
+
const found = await run(clone, lines);
|
|
342
|
+
expect(found.map((o) => o.since.slice(0, 10))).toEqual(["2026-09-01"]);
|
|
343
|
+
expect(execFileSync("git", ["-C", clone, "rev-parse", "--is-shallow-repository"], { encoding: "utf-8" }).trim()).toBe("false");
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test("a fetch that fails counts from the oldest commit there is, and says so", async () => {
|
|
347
|
+
const clone = shallowClone();
|
|
348
|
+
execFileSync("git", ["-C", clone, "remote", "remove", "origin"], { stdio: "pipe" });
|
|
349
|
+
const lines: string[] = [];
|
|
350
|
+
const found = await run(clone, lines);
|
|
351
|
+
expect(found.map((o) => o.since.slice(0, 10))).toEqual(["2026-10-20"]);
|
|
352
|
+
expect(lines.some((l) => l.includes("the checkout is shallow and its history could not be fetched"))).toBe(true);
|
|
353
|
+
});
|
|
354
|
+
});
|
|
312
355
|
});
|
|
313
356
|
|
|
314
357
|
describe("the plan note", () => {
|