@intentius/chant 0.124.108 → 0.124.110
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__/wave-loop/fan-out-applied.json +12 -6
- package/dist/__golden__/wave-loop/fan-out-apply-fails.json +8 -4
- package/dist/__golden__/wave-loop/fan-out-gated.json +4 -2
- package/dist/__golden__/wave-loop/fan-out-no-members.json +16 -8
- package/dist/__golden__/wave-loop/fan-out-plan-fails.json +8 -4
- package/dist/__golden__/wave-loop/fan-out-same-root.json +4 -2
- package/dist/agent-facts.d.ts +130 -0
- package/dist/agent-facts.js +196 -0
- package/dist/change-risk.d.ts +216 -0
- package/dist/change-risk.js +304 -0
- package/dist/change-set.d.ts +8 -0
- package/dist/ci-agent-alert.d.ts +139 -0
- package/dist/ci-agent-alert.js +342 -0
- package/dist/ci-agent-triggers.d.ts +152 -0
- package/dist/ci-agent-triggers.js +232 -0
- package/dist/ci-agent-verify-failed.d.ts +149 -0
- package/dist/ci-agent-verify-failed.js +191 -0
- package/dist/ci-agent.d.ts +136 -8
- package/dist/ci-agent.js +353 -26
- package/dist/ci-comment-commands.d.ts +8 -0
- package/dist/ci-comment-commands.js +17 -1
- package/dist/ci-comment-reject.d.ts +70 -0
- package/dist/ci-comment-reject.js +135 -0
- package/dist/ci-comment-replies.d.ts +3 -1
- package/dist/ci-comment-replies.js +6 -0
- package/dist/ci-estate/delivery.d.ts +25 -3
- package/dist/ci-estate/delivery.js +28 -9
- package/dist/ci-estate/page.d.ts +7 -3
- package/dist/ci-estate/page.js +19 -4
- package/dist/ci-estate/rows.d.ts +14 -2
- package/dist/ci-estate/rows.js +9 -1
- package/dist/ci-estate.d.ts +5 -2
- package/dist/ci-estate.js +3 -2
- package/dist/ci-handover.d.ts +2 -7
- package/dist/ci-handover.js +3 -20
- package/dist/ci-jobs.d.ts +6 -0
- package/dist/ci-jobs.js +17 -0
- package/dist/ci-note-commands.d.ts +2 -0
- package/dist/ci-note-commands.js +12 -1
- package/dist/ci-product-words.d.ts +151 -1
- package/dist/ci-product-words.js +1390 -3
- package/dist/ci-product.d.ts +100 -4
- package/dist/ci-product.js +99 -3
- package/dist/ci-respond-run.d.ts +9 -0
- package/dist/ci-respond-run.js +35 -4
- package/dist/ci-respond-summary-env.d.ts +56 -0
- package/dist/ci-respond-summary-env.js +81 -0
- package/dist/ci-respond-summary.d.ts +103 -0
- package/dist/ci-respond-summary.js +243 -0
- package/dist/ci-respond.d.ts +4 -2
- package/dist/ci-respond.js +4 -2
- package/dist/cli/command-group.js +1 -1
- package/dist/cli/commands/lint.js +21 -3
- package/dist/cli/handlers/agent.js +49 -4
- package/dist/cli/handlers/approve.js +3 -1
- package/dist/cli/handlers/build.d.ts +97 -1
- package/dist/cli/handlers/build.js +251 -3
- package/dist/cli/handlers/fan-out.js +55 -0
- package/dist/cli/handlers/graph.d.ts +14 -0
- package/dist/cli/handlers/graph.js +58 -3
- package/dist/cli/handlers/lifecycle-health.d.ts +7 -0
- package/dist/cli/handlers/lifecycle-health.js +47 -9
- package/dist/cli/handlers/lifecycle.js +4 -1
- package/dist/cli/handlers/notify-relay.d.ts +2 -2
- package/dist/cli/handlers/notify-relay.js +67 -7
- package/dist/cli/handlers/pipeline-agent.d.ts +30 -0
- package/dist/cli/handlers/pipeline-agent.js +255 -0
- package/dist/cli/handlers/pipeline-artifacts.d.ts +39 -0
- package/dist/cli/handlers/pipeline-artifacts.js +203 -0
- package/dist/cli/handlers/pipeline.d.ts +16 -0
- package/dist/cli/handlers/pipeline.js +112 -0
- package/dist/cli/handlers/pr-comment.js +4 -0
- package/dist/cli/handlers/pr-notes.js +4 -1
- package/dist/cli/handlers/pr.d.ts +20 -0
- package/dist/cli/handlers/pr.js +114 -11
- package/dist/cli/handlers/promote.js +792 -47
- package/dist/cli/handlers/reject.d.ts +84 -0
- package/dist/cli/handlers/reject.js +216 -0
- package/dist/cli/handlers/release.js +4 -2
- package/dist/cli/handlers/replan.d.ts +54 -0
- package/dist/cli/handlers/replan.js +177 -0
- package/dist/cli/handlers/run-generate.d.ts +5 -0
- package/dist/cli/handlers/run-generate.js +31 -4
- package/dist/cli/handlers/run-wave.js +15 -2
- package/dist/cli/handlers/run.js +4 -2
- package/dist/cli/handlers/stage.d.ts +35 -0
- package/dist/cli/handlers/stage.js +90 -0
- package/dist/cli/lsp/server.js +4 -0
- package/dist/cli/main.js +88 -8
- package/dist/cli/parse-args.js +35 -2
- package/dist/cli/registry.d.ts +12 -0
- package/dist/components/auto-release.d.ts +2 -0
- package/dist/components/auto-release.js +1 -0
- package/dist/components/capability.d.ts +40 -0
- package/dist/components/cli-support.d.ts +21 -1
- package/dist/components/cli-support.js +28 -6
- package/dist/components/component.d.ts +23 -4
- package/dist/components/component.schema.json +28 -0
- package/dist/components/declared-reads.d.ts +44 -4
- package/dist/components/declared-reads.js +80 -3
- package/dist/components/discover.d.ts +8 -0
- package/dist/components/discover.js +1 -1
- package/dist/components/driver.d.ts +13 -0
- package/dist/components/driver.js +23 -2
- package/dist/components/environment-sets.d.ts +229 -0
- package/dist/components/environment-sets.js +338 -0
- package/dist/components/fan-out-canary.d.ts +47 -0
- package/dist/components/fan-out-canary.js +58 -0
- package/dist/components/fan-out-run.d.ts +17 -0
- package/dist/components/fan-out-run.js +14 -1
- package/dist/components/fan-out-support.d.ts +7 -0
- package/dist/components/fan-out-support.js +1 -1
- package/dist/components/groups.d.ts +8 -1
- package/dist/components/groups.js +19 -1
- package/dist/components/index.d.ts +5 -2
- package/dist/components/index.js +4 -1
- package/dist/components/pr-cost.d.ts +28 -0
- package/dist/components/pr-cost.js +53 -0
- package/dist/components/pr-pipeline.d.ts +33 -0
- package/dist/components/pr-pipeline.js +32 -5
- package/dist/components/pr-policy.d.ts +33 -2
- package/dist/components/pr-policy.js +5 -2
- package/dist/components/pr-risk.d.ts +42 -0
- package/dist/components/pr-risk.js +74 -0
- package/dist/components/product-pipeline.d.ts +43 -0
- package/dist/components/product-pipeline.js +67 -1
- package/dist/components/promote.d.ts +6 -0
- package/dist/components/promote.js +13 -0
- package/dist/components/release-compile.js +3 -1
- package/dist/components/release-gate.d.ts +6 -1
- package/dist/components/release-gate.js +10 -2
- package/dist/components/step-environments.d.ts +236 -0
- package/dist/components/step-environments.js +392 -0
- package/dist/components/upstream-replan.d.ts +201 -0
- package/dist/components/upstream-replan.js +249 -0
- package/dist/components/verify-step.d.ts +30 -0
- package/dist/components/verify-step.js +27 -0
- package/dist/components/wave-plan.js +6 -2
- package/dist/config-environments.d.ts +4 -2
- package/dist/control/dispatch.d.ts +15 -0
- package/dist/control/dispatch.js +28 -4
- package/dist/cost-estimate.d.ts +188 -0
- package/dist/cost-estimate.js +363 -0
- package/dist/drift-record.d.ts +36 -0
- package/dist/drift-record.js +44 -0
- package/dist/engine-facts.d.ts +105 -0
- package/dist/engine-facts.js +111 -0
- package/dist/exit-codes.d.ts +4 -3
- package/dist/exit-codes.js +4 -3
- package/dist/flag-params.d.ts +2 -2
- package/dist/flag-params.js +9 -4
- package/dist/floor-table.data.js +53 -0
- package/dist/forge-token-vars.d.ts +12 -0
- package/dist/forge-token-vars.js +25 -0
- package/dist/gate-decision.d.ts +3 -1
- package/dist/gate-decision.js +3 -1
- package/dist/gated-waves.d.ts +2 -0
- package/dist/gated-waves.js +1 -0
- package/dist/graph-ir.d.ts +30 -0
- package/dist/graph-ir.js +33 -1
- package/dist/graph-refs.d.ts +26 -0
- package/dist/graph-refs.js +34 -3
- package/dist/graph-schema/graph.schema.json +136 -0
- package/dist/health.d.ts +65 -0
- package/dist/health.js +62 -0
- package/dist/lexicon.d.ts +188 -1
- package/dist/lifecycle/disruption.d.ts +14 -1
- package/dist/lifecycle/disruption.js +5 -1
- package/dist/lifecycle/gate-change-set.d.ts +8 -0
- package/dist/lifecycle/gate-change-set.js +2 -1
- package/dist/lifecycle/gate-ledger.d.ts +26 -0
- package/dist/lifecycle/gate-rejection.d.ts +82 -0
- package/dist/lifecycle/gate-rejection.js +93 -0
- package/dist/lifecycle/gate-seal.d.ts +3 -3
- package/dist/lifecycle/gate-seal.js +5 -5
- package/dist/lifecycle/observe.d.ts +17 -0
- package/dist/lifecycle/observe.js +10 -1
- package/dist/lifecycle/release-cut.js +4 -0
- package/dist/lifecycle/release-ledger.d.ts +8 -0
- package/dist/lifecycle/release-risk.d.ts +137 -0
- package/dist/lifecycle/release-risk.js +214 -0
- package/dist/lifecycle/release-store.d.ts +9 -0
- package/dist/lifecycle/release-store.js +4 -0
- package/dist/lifecycle/stage-log.d.ts +85 -0
- package/dist/lifecycle/stage-log.js +141 -0
- package/dist/lint/canary-checks.d.ts +31 -0
- package/dist/lint/canary-checks.js +45 -0
- package/dist/lint/rule.d.ts +1 -0
- package/dist/lint/rules/evl012-pipeline-fold.d.ts +14 -0
- package/dist/lint/rules/evl012-pipeline-fold.js +30 -0
- package/dist/lint/rules/index.d.ts +1 -0
- package/dist/lint/rules/index.js +3 -0
- package/dist/notify-relay-repo.d.ts +54 -0
- package/dist/notify-relay-repo.js +84 -0
- package/dist/notify-relay.d.ts +53 -3
- package/dist/notify-relay.js +96 -3
- package/dist/notify.d.ts +57 -1
- package/dist/notify.js +7 -1
- package/dist/notify.schema.json +61 -3
- package/dist/observation.d.ts +34 -0
- package/dist/observation.js +14 -1
- package/dist/op/activities/review-agent.d.ts +39 -2
- package/dist/op/activities/review-agent.js +88 -5
- package/dist/op/agent-permit.d.ts +88 -0
- package/dist/op/agent-permit.js +97 -0
- package/dist/op/gate-approval-base.d.ts +8 -0
- package/dist/op/gate-approval-base.js +9 -0
- package/dist/op/gate-approval.d.ts +30 -1
- package/dist/op/gate-approval.js +23 -2
- package/dist/op/gate-quorum.d.ts +114 -8
- package/dist/op/gate-quorum.js +198 -21
- package/dist/op/gate-reject.d.ts +79 -0
- package/dist/op/gate-reject.js +96 -0
- package/dist/op/gate-summary.js +1 -1
- package/dist/op/gate.d.ts +28 -3
- package/dist/op/gate.js +55 -13
- package/dist/op/generate-pipeline.d.ts +15 -1
- package/dist/op/generate-pipeline.js +32 -5
- package/dist/op/index.d.ts +11 -6
- package/dist/op/index.js +10 -5
- package/dist/op/local-executor.d.ts +2 -0
- package/dist/op/local-executor.js +23 -4
- package/dist/op/op-waves-after-plan.d.ts +23 -0
- package/dist/op/op-waves-after-plan.js +12 -1
- package/dist/op/op-waves-capability-spec.d.ts +14 -0
- package/dist/op/op-waves-capability-spec.js +46 -6
- package/dist/op/op-waves-capability.d.ts +21 -13
- package/dist/op/op-waves-capability.js +22 -59
- package/dist/op/op-waves-environment-sets.d.ts +41 -0
- package/dist/op/op-waves-environment-sets.js +82 -0
- package/dist/op/op-waves-quorum-warnings.d.ts +53 -0
- package/dist/op/op-waves-quorum-warnings.js +90 -0
- package/dist/op/op-waves-release-port.d.ts +7 -0
- package/dist/op/op-waves-release-port.js +15 -3
- package/dist/op/op-waves-release.d.ts +15 -0
- package/dist/op/op-waves-release.js +15 -0
- package/dist/op/op-waves-run.d.ts +37 -3
- package/dist/op/op-waves-run.js +141 -18
- package/dist/op/op-waves-soak.d.ts +57 -0
- package/dist/op/op-waves-soak.js +111 -0
- package/dist/op/op-waves-split.d.ts +4 -0
- package/dist/op/op-waves-split.js +4 -0
- package/dist/op/op-waves.d.ts +67 -4
- package/dist/op/op-waves.js +71 -3
- package/dist/pipeline/agent-ajv.d.ts +4 -0
- package/dist/pipeline/agent-ajv.js +14 -0
- package/dist/pipeline/agent-steps.d.ts +329 -0
- package/dist/pipeline/agent-steps.js +602 -0
- package/dist/pipeline/artifacts.d.ts +264 -0
- package/dist/pipeline/artifacts.js +425 -0
- package/dist/pipeline/diff.d.ts +45 -0
- package/dist/pipeline/diff.js +177 -0
- package/dist/pipeline/fold.d.ts +43 -0
- package/dist/pipeline/fold.js +140 -0
- package/dist/pipeline/generate.d.ts +52 -0
- package/dist/pipeline/generate.js +120 -0
- package/dist/pipeline/product.d.ts +225 -0
- package/dist/pipeline/product.js +257 -0
- package/dist/pipeline/promote.d.ts +404 -0
- package/dist/pipeline/promote.js +694 -0
- package/dist/pipeline/read.d.ts +37 -0
- package/dist/pipeline/read.js +58 -0
- package/dist/pipeline/rendered.d.ts +25 -0
- package/dist/pipeline/rendered.js +53 -0
- package/dist/pipeline/soak-checks.d.ts +80 -0
- package/dist/pipeline/soak-checks.js +254 -0
- package/dist/pipeline/soak-gate.d.ts +97 -0
- package/dist/pipeline/soak-gate.js +176 -0
- package/dist/pipeline/soak-sources.d.ts +17 -0
- package/dist/pipeline/soak-sources.js +42 -0
- package/dist/pipeline/soak.d.ts +260 -0
- package/dist/pipeline/soak.js +378 -0
- package/dist/pipeline/spec.d.ts +724 -0
- package/dist/pipeline/spec.js +567 -0
- package/dist/pipeline/stage-ledger.d.ts +187 -0
- package/dist/pipeline/stage-ledger.js +185 -0
- package/dist/pipeline/stage-waves.d.ts +114 -0
- package/dist/pipeline/stage-waves.js +161 -0
- package/dist/pipeline/stages.d.ts +64 -0
- package/dist/pipeline/stages.js +174 -0
- package/dist/pipeline/verify-rollback.d.ts +277 -0
- package/dist/pipeline/verify-rollback.js +393 -0
- package/dist/pipeline.d.ts +142 -0
- package/dist/pipeline.js +143 -0
- package/dist/pr-loop.d.ts +22 -0
- package/dist/pr-loop.js +8 -0
- package/dist/pr-plan-note.d.ts +15 -1
- package/dist/pr-plan-note.js +8 -0
- package/dist/pr-post.d.ts +31 -0
- package/dist/pr-post.js +89 -0
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/report-store/audit.schema.json +50 -0
- package/dist/report-store/dora.schema.json +331 -0
- package/dist/report-store/estate.schema.json +96 -0
- package/dist/report-store/run.schema.json +14 -0
- package/dist/report-store.d.ts +151 -0
- package/dist/report-store.js +344 -0
- package/dist/run-event.d.ts +7 -2
- package/dist/wave-runtime.mjs +458 -404
- package/dist/workspace/catalog-edges.js +3 -3
- package/dist/workspace/change-set.schema.json +4 -0
- package/dist/workspace/ci-cloud-identity.d.ts +4 -0
- package/dist/workspace/ci-cloud-identity.js +30 -0
- package/dist/workspace/ci-run.js +17 -2
- package/dist/workspace/ci-secrets.d.ts +3 -1
- package/dist/workspace/ci-secrets.js +7 -1
- package/dist/workspace/compose-graph.d.ts +1 -1
- package/dist/workspace/compose-graph.js +3 -1
- package/dist/workspace/declaration.d.ts +27 -0
- package/dist/workspace/declaration.js +35 -0
- package/dist/workspace/declaration.schema.json +56 -0
- package/dist/workspace/graph-cli.js +26 -0
- package/dist/workspace/graph.schema.json +5 -1
- package/dist/workspace/identity-gate-rule.d.ts +4 -0
- package/dist/workspace/identity-gate-rule.js +2 -2
- package/dist/workspace/identity-reject-rule.d.ts +14 -0
- package/dist/workspace/identity-reject-rule.js +24 -0
- package/dist/workspace/identity.d.ts +3 -0
- package/dist/workspace/identity.js +2 -1
- package/dist/workspace/nested-graph.js +2 -0
- package/dist/workspace/pr-report.schema.json +65 -0
- package/dist/workspace/promotion-order.d.ts +19 -4
- package/dist/workspace/promotion-order.js +26 -4
- package/dist/workspace/release-train.d.ts +14 -0
- package/dist/workspace/release-train.js +32 -0
- package/dist/workspace/run-event.schema.json +2 -2
- package/dist/workspace/stack-read-edges.d.ts +19 -0
- package/dist/workspace/stack-read-edges.js +54 -0
- package/dist/workspace/status-gates.d.ts +51 -1
- package/dist/workspace/status-gates.js +60 -0
- package/dist/workspace/status-stages.d.ts +223 -0
- package/dist/workspace/status-stages.js +279 -0
- package/dist/workspace/status.d.ts +45 -1
- package/dist/workspace/status.js +109 -5
- package/dist/workspace/status.schema.json +283 -2
- package/dist/workspace/train-cut.js +5 -2
- package/dist/workspace/train-shell.d.ts +18 -0
- package/dist/workspace/train-shell.js +43 -0
- package/dist/workspace/trust/seal.d.ts +7 -0
- package/dist/workspace/trust/seal.js +9 -0
- package/package.json +5 -1
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant pipeline agent` (#5358): a stage's agent steps. See
|
|
3
|
+
* ../../pipeline/agent-steps.ts.
|
|
4
|
+
*
|
|
5
|
+
* pipeline agent run --stage <stage> --release <label|digest> [--output <dir>]
|
|
6
|
+
* run the stage's agent steps for the release, in order, and write each
|
|
7
|
+
* step's record to <dir>/<step>.json (default .chant/agent-steps/<stage>).
|
|
8
|
+
* Reads the ledger and writes nothing to it: the job it runs in holds a
|
|
9
|
+
* read token only. Exits 1 when a step failed, naming why.
|
|
10
|
+
* pipeline agent record --stage <stage> --release <label|digest> [--from <dir>]
|
|
11
|
+
* check each record against the pipeline at base, record it on
|
|
12
|
+
* <stage>/agent-answers.jsonl with a run record per model run, and push.
|
|
13
|
+
* Exits 1 when a step failed or a record is refused.
|
|
14
|
+
* pipeline agent answer --stage <stage> --release <label|digest> [--name <step>] [--json]
|
|
15
|
+
* print the stage's answers for the release, or one step's answer.
|
|
16
|
+
*/
|
|
17
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { tmpdir } from "node:os";
|
|
19
|
+
import { join, resolve } from "node:path";
|
|
20
|
+
import { formatError, formatInfo, formatWarning } from "../format.js";
|
|
21
|
+
const USAGE = "chant pipeline agent run --stage <stage> --release <label|digest> [--output <dir>] | chant pipeline agent record --stage <stage> --release <label|digest> [--from <dir>] | chant pipeline agent answer --stage <stage> --release <label|digest> [--name <step>] [--json]";
|
|
22
|
+
/** Where `run` writes a stage's records and `record` reads them, unless named. */
|
|
23
|
+
export const AGENT_STEPS_DIR = ".chant/agent-steps";
|
|
24
|
+
/** The pipeline on the default branch, or why there is none to read. */
|
|
25
|
+
async function pipelineAtBase(cwd) {
|
|
26
|
+
const { promoteBase, readPipelineAt, readMemberPipeline } = await import("../../pipeline/read.js");
|
|
27
|
+
const base = promoteBase(cwd);
|
|
28
|
+
const read = base ? readPipelineAt(base, cwd) : readMemberPipeline(cwd);
|
|
29
|
+
if (read.status === "absent")
|
|
30
|
+
return "this member has no pipeline";
|
|
31
|
+
if (read.status === "refused")
|
|
32
|
+
return `the pipeline does not fold: ${read.line}`;
|
|
33
|
+
return read.spec;
|
|
34
|
+
}
|
|
35
|
+
/** The release named, by label or digest. */
|
|
36
|
+
async function releaseNamed(ref, cwd) {
|
|
37
|
+
const { resolveRelease } = await import("../../lifecycle/release-store.js");
|
|
38
|
+
const found = await resolveRelease(ref, { cwd });
|
|
39
|
+
return found ? { digest: found.release.releaseDigest, label: found.label, commit: found.release.commit } : undefined;
|
|
40
|
+
}
|
|
41
|
+
/** The stage, the pipeline at base and the release every verb starts from, or the exit code. */
|
|
42
|
+
async function start(ctx) {
|
|
43
|
+
const { args } = ctx;
|
|
44
|
+
const stage = args.lockStage;
|
|
45
|
+
if (!stage || !args.release) {
|
|
46
|
+
console.error(formatError({ message: "--stage <stage> and --release <label|digest> are required: an agent step answers for the release its stage takes", hint: USAGE }));
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
49
|
+
const cwd = resolve(".");
|
|
50
|
+
const { fetchLifecycle } = await import("../../lifecycle/git.js");
|
|
51
|
+
await fetchLifecycle({ cwd }).catch(() => false);
|
|
52
|
+
const spec = await pipelineAtBase(cwd);
|
|
53
|
+
if (typeof spec === "string") {
|
|
54
|
+
console.error(formatError({ message: spec, hint: USAGE }));
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
if (!spec.stages.some((s) => s.name === stage)) {
|
|
58
|
+
console.error(formatError({ message: `the pipeline "${spec.name}" has no stage "${stage}"` }));
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
const release = await releaseNamed(args.release, cwd);
|
|
62
|
+
if (!release) {
|
|
63
|
+
console.error(formatError({ message: `no release is labelled or digested ${args.release}` }));
|
|
64
|
+
return 1;
|
|
65
|
+
}
|
|
66
|
+
return { cwd, stage, spec, release };
|
|
67
|
+
}
|
|
68
|
+
export async function runPipelineAgent(ctx) {
|
|
69
|
+
const verb = ctx.args.extraPositional;
|
|
70
|
+
if (verb === "run")
|
|
71
|
+
return runSteps(ctx);
|
|
72
|
+
if (verb === "record")
|
|
73
|
+
return recordSteps(ctx);
|
|
74
|
+
if (verb === "answer")
|
|
75
|
+
return printAnswers(ctx);
|
|
76
|
+
console.error(formatError({ message: "chant pipeline agent takes run, record or answer", hint: USAGE }));
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
async function runSteps(ctx) {
|
|
80
|
+
const at = await start(ctx);
|
|
81
|
+
if (typeof at === "number")
|
|
82
|
+
return at;
|
|
83
|
+
const { cwd, stage, spec, release } = at;
|
|
84
|
+
const { runStageAgentSteps, stageAgentSteps } = await import("../../pipeline/agent-steps.js");
|
|
85
|
+
if (stageAgentSteps(spec, stage).length === 0) {
|
|
86
|
+
console.error(formatInfo(`stage "${stage}" has no agent steps`));
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
const { gitStageArtifactPort } = await import("../../pipeline/artifacts.js");
|
|
90
|
+
const { AGENT_OUTPUT_FILE, AGENT_USAGE_FILE, digestOf, overLimit, readAgentUsage } = await import("../../ci-agent.js");
|
|
91
|
+
const { WAVE_SUMMARY_COMMAND } = await import("../../ci-respond-summary.js");
|
|
92
|
+
const { quoted, reviewCommandEnv, runReviewCommand } = await import("../../op/activities/review-agent.js");
|
|
93
|
+
const env = process.env;
|
|
94
|
+
const records = await runStageAgentSteps({
|
|
95
|
+
spec,
|
|
96
|
+
stage,
|
|
97
|
+
release: { digest: release.digest, label: release.label, gitSha: release.commit },
|
|
98
|
+
defaultCommand: WAVE_SUMMARY_COMMAND,
|
|
99
|
+
artifacts: gitStageArtifactPort({ cwd }),
|
|
100
|
+
readRuns: async (s) => {
|
|
101
|
+
const { readRunLedger } = await import("../../lifecycle/run-ledger.js");
|
|
102
|
+
return (await readRunLedger(s.env, s.name, { cwd })).records;
|
|
103
|
+
},
|
|
104
|
+
hasKey: (k) => Boolean(env[k]),
|
|
105
|
+
quote: quoted,
|
|
106
|
+
overLimit: (s, r, now) => overLimit(s, r, now),
|
|
107
|
+
digestOf,
|
|
108
|
+
// The model's environment is built from scratch: its key and the process basics, never a forge token.
|
|
109
|
+
model: async ({ settings, prompt }) => {
|
|
110
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-agent-step-"));
|
|
111
|
+
const commandEnv = { ...reviewCommandEnv(env, settings.keyEnv), CHANT_AGENT_USAGE: join(dir, AGENT_USAGE_FILE) };
|
|
112
|
+
let got;
|
|
113
|
+
try {
|
|
114
|
+
got = await runReviewCommand(settings.command, prompt, commandEnv, settings.timeout * 60000);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
got = { stdout: "", exitCode: null };
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
writeFileSync(join(dir, AGENT_OUTPUT_FILE), got.stdout.slice(0, 8 << 20));
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
/* the usage is read from the output when it can be */
|
|
124
|
+
}
|
|
125
|
+
return { ...got, usage: readAgentUsage(dir) };
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
const outDir = resolve(ctx.args.output ?? join(AGENT_STEPS_DIR, stage));
|
|
129
|
+
mkdirSync(outDir, { recursive: true });
|
|
130
|
+
let failed = 0;
|
|
131
|
+
for (const r of records) {
|
|
132
|
+
writeFileSync(join(outDir, `${r.step}.json`), JSON.stringify(r, null, 2) + "\n");
|
|
133
|
+
if (r.status === "answered")
|
|
134
|
+
console.error(formatInfo(`agent step ${r.step}: answered${r.usage?.usd !== undefined ? ` (${r.usage.usd.toFixed(2)} USD)` : ""}`));
|
|
135
|
+
else {
|
|
136
|
+
failed++;
|
|
137
|
+
console.error(formatError({ message: `agent step ${r.step} failed: ${r.reason}` }));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
console.error(formatInfo(`wrote ${records.length} record${records.length === 1 ? "" : "s"} to ${outDir}; \`chant pipeline agent record\` records them`));
|
|
141
|
+
return failed > 0 ? 1 : 0;
|
|
142
|
+
}
|
|
143
|
+
async function recordSteps(ctx) {
|
|
144
|
+
const at = await start(ctx);
|
|
145
|
+
if (typeof at === "number")
|
|
146
|
+
return at;
|
|
147
|
+
const { cwd, stage, spec, release } = at;
|
|
148
|
+
const { checkedAgentAnswer, gitStageAgentAnswerPort, stageAgentSteps, agentStepSettings, AGENT_STEP_TRIGGER } = await import("../../pipeline/agent-steps.js");
|
|
149
|
+
const steps = stageAgentSteps(spec, stage);
|
|
150
|
+
if (steps.length === 0) {
|
|
151
|
+
console.error(formatInfo(`stage "${stage}" has no agent steps`));
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
const dir = resolve(ctx.args.migrateFrom ?? join(AGENT_STEPS_DIR, stage));
|
|
155
|
+
const port = gitStageAgentAnswerPort({ cwd });
|
|
156
|
+
const { agentRunRecordInput } = await import("../../ci-agent.js");
|
|
157
|
+
const { WAVE_SUMMARY_COMMAND } = await import("../../ci-respond-summary.js");
|
|
158
|
+
const { appendRunRecord } = await import("../../lifecycle/run-ledger.js");
|
|
159
|
+
const { resolveCiRun } = await import("../../lifecycle/release-ledger.js");
|
|
160
|
+
const ci = resolveCiRun(process.env);
|
|
161
|
+
let failed = 0;
|
|
162
|
+
for (const [name, declared] of steps) {
|
|
163
|
+
const file = join(dir, `${name}.json`);
|
|
164
|
+
let raw;
|
|
165
|
+
try {
|
|
166
|
+
raw = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : undefined;
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
raw = undefined;
|
|
170
|
+
}
|
|
171
|
+
if (raw === undefined) {
|
|
172
|
+
failed++;
|
|
173
|
+
console.error(formatError({ message: `agent step ${name} wrote no record to ${file}, so nothing is recorded for it and the stage holds` }));
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const checked = checkedAgentAnswer(spec, stage, release.digest, raw);
|
|
177
|
+
if ("refused" in checked) {
|
|
178
|
+
failed++;
|
|
179
|
+
console.error(formatError({ message: `agent step ${name}'s record is refused: ${checked.refused}` }));
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
await port.append(stage, checked);
|
|
183
|
+
// One run record per model run, which the step's limits count, as every agent's do.
|
|
184
|
+
if (checked.promptDigest && checked.started && checked.ended) {
|
|
185
|
+
const s = agentStepSettings(spec, stage, name, declared, WAVE_SUMMARY_COMMAND);
|
|
186
|
+
await appendRunRecord(agentRunRecordInput({
|
|
187
|
+
settings: { name: s.name, env: s.env, on: AGENT_STEP_TRIGGER },
|
|
188
|
+
started: checked.started,
|
|
189
|
+
ended: checked.ended,
|
|
190
|
+
result: checked.status === "answered" ? "answered" : "failed",
|
|
191
|
+
reason: checked.status === "answered" ? `answered for ${release.label ?? release.digest}` : (checked.reason ?? "failed"),
|
|
192
|
+
promptDigest: checked.promptDigest,
|
|
193
|
+
...(checked.usage ? { usage: checked.usage } : {}),
|
|
194
|
+
gitSha: release.commit,
|
|
195
|
+
...(ci ? { runOrigin: ci.runOrigin } : {}),
|
|
196
|
+
}), { cwd });
|
|
197
|
+
}
|
|
198
|
+
if (checked.status === "answered")
|
|
199
|
+
console.error(formatInfo(`agent step ${name}: recorded its answer for release ${release.label ?? release.digest}`));
|
|
200
|
+
else {
|
|
201
|
+
failed++;
|
|
202
|
+
console.error(formatError({ message: `agent step ${name} failed for release ${release.label ?? release.digest}: ${checked.reason}` }));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const { pushLifecycleRebasing } = await import("../../lifecycle/git.js");
|
|
206
|
+
const pushed = await pushLifecycleRebasing({ cwd }).catch((err) => ({ pushed: false, pushWarning: err instanceof Error ? err.message : String(err) }));
|
|
207
|
+
if (!pushed.pushed && pushed.pushWarning)
|
|
208
|
+
console.error(formatWarning({ message: pushed.pushWarning }));
|
|
209
|
+
return failed > 0 ? 1 : 0;
|
|
210
|
+
}
|
|
211
|
+
async function printAnswers(ctx) {
|
|
212
|
+
const at = await start(ctx);
|
|
213
|
+
if (typeof at === "number")
|
|
214
|
+
return at;
|
|
215
|
+
const { cwd, stage, release } = at;
|
|
216
|
+
const { gitStageAgentAnswerPort, readStageAgentAnswers } = await import("../../pipeline/agent-steps.js");
|
|
217
|
+
const answers = await readStageAgentAnswers(gitStageAgentAnswerPort({ cwd }), { stage, release: release.digest });
|
|
218
|
+
if (ctx.args.selectName) {
|
|
219
|
+
const r = answers[ctx.args.selectName];
|
|
220
|
+
if (!r || r.status !== "answered") {
|
|
221
|
+
console.error(formatError({ message: `agent step ${ctx.args.selectName} of stage "${stage}" has no answer for release ${release.label ?? release.digest}${r?.reason ? `: ${r.reason}` : ""}` }));
|
|
222
|
+
return 1;
|
|
223
|
+
}
|
|
224
|
+
console.log(ctx.args.json ? JSON.stringify(r, null, 2) : JSON.stringify(r.answer));
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
if (ctx.args.json)
|
|
228
|
+
console.log(JSON.stringify(answers, null, 2));
|
|
229
|
+
else
|
|
230
|
+
for (const r of Object.values(answers))
|
|
231
|
+
console.log(`${r.step}: ${r.status === "answered" ? JSON.stringify(r.answer) : `failed, ${r.reason}`}`);
|
|
232
|
+
return 0;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* The stage gate's policy over agent answers, for the promote (#5358): the
|
|
236
|
+
* workspace's `ci.policy` at base, with the answers as `input.agent` and no
|
|
237
|
+
* change set, since a promote is gated before it plans. Undefined when no
|
|
238
|
+
* policy is named at base.
|
|
239
|
+
*/
|
|
240
|
+
export async function stageAgentPolicy(cwd, spec, stage, agent) {
|
|
241
|
+
const { promoteBase } = await import("../../pipeline/read.js");
|
|
242
|
+
const { prLoopPolicyAt, preparePrPolicyEngine, runPrPolicy } = await import("../../components/pr-policy.js");
|
|
243
|
+
const { composeChangeSet } = await import("../../change-set.js");
|
|
244
|
+
const { getHeadCommit } = await import("../../lifecycle/git.js");
|
|
245
|
+
const base = promoteBase(cwd);
|
|
246
|
+
if (!base)
|
|
247
|
+
return { result: "error", reasons: ["the default branch cannot be read, so the stage's policy cannot be read at base"] };
|
|
248
|
+
const head = (await getHeadCommit({ cwd }).catch(() => "")) || base;
|
|
249
|
+
const read = await preparePrPolicyEngine(prLoopPolicyAt(cwd, base));
|
|
250
|
+
const verdict = runPrPolicy(read, { version: 1, stage: "apply", op: spec.name, gate: stage, env: stage, pr: null, base, head, changeSet: composeChangeSet([]), agent });
|
|
251
|
+
if (!verdict)
|
|
252
|
+
return undefined;
|
|
253
|
+
const reasons = verdict.result === "error" ? [verdict.error ?? "the policy did not run"] : [...verdict.denials, ...verdict.holds].map((f) => f.message).filter(Boolean);
|
|
254
|
+
return { result: verdict.result, reasons };
|
|
255
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant pipeline artifacts` and `chant pipeline release-of` (#5356): the
|
|
3
|
+
* release artifacts a stage publishes and later stages and other
|
|
4
|
+
* repositories read. See ../../pipeline/artifacts.ts.
|
|
5
|
+
*
|
|
6
|
+
* pipeline artifacts publish --stage <stage> [--release <label|digest>] [--dry-run] [--json]
|
|
7
|
+
* publish the artifacts the stage declares, for the release named, or
|
|
8
|
+
* the release cut from HEAD. The declarations are read from the
|
|
9
|
+
* pipeline on the default branch, as the stage's gates are. A wave job
|
|
10
|
+
* runs it after the first stage's release cut.
|
|
11
|
+
* pipeline artifacts read --stage <stage> [--release <label|digest>] [--name <artifact>] [--from <dir>] [--json]
|
|
12
|
+
* print the artifacts the stage published for the release named, else
|
|
13
|
+
* for the release in CHANT_CONTROL_RELEASE, else for the release it
|
|
14
|
+
* last published for. --from reads another repository's records: a
|
|
15
|
+
* checkout of it, or a directory holding its chant/lifecycle.
|
|
16
|
+
* pipeline release-of <commit>
|
|
17
|
+
* print the digest of the release cut from the commit; exit 1 when none
|
|
18
|
+
*/
|
|
19
|
+
import type { CommandContext } from "../registry.js";
|
|
20
|
+
import { type PublishStageArtifactsResult } from "../../pipeline/artifacts.js";
|
|
21
|
+
import type { PipelineSpec } from "../../pipeline/spec.js";
|
|
22
|
+
/** Publish `stage`'s artifacts for `release` from `cwd`, and push the ledger. Shared by the command and the promote. */
|
|
23
|
+
export declare function publishStageFrom(input: {
|
|
24
|
+
cwd: string;
|
|
25
|
+
spec: PipelineSpec;
|
|
26
|
+
stage: string;
|
|
27
|
+
release: {
|
|
28
|
+
digest: string;
|
|
29
|
+
label?: string | null;
|
|
30
|
+
gitSha?: string;
|
|
31
|
+
};
|
|
32
|
+
dryRun?: boolean;
|
|
33
|
+
}): Promise<PublishStageArtifactsResult>;
|
|
34
|
+
/** The lines a refused publish prints. They name artifacts, members and outputs, never a value. */
|
|
35
|
+
export declare function publishRefusedMessage(result: Extract<PublishStageArtifactsResult, {
|
|
36
|
+
status: "refused";
|
|
37
|
+
}>): string;
|
|
38
|
+
export declare function runPipelineArtifacts(ctx: CommandContext): Promise<number>;
|
|
39
|
+
export declare function runPipelineReleaseOf(ctx: CommandContext): Promise<number>;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant pipeline artifacts` and `chant pipeline release-of` (#5356): the
|
|
3
|
+
* release artifacts a stage publishes and later stages and other
|
|
4
|
+
* repositories read. See ../../pipeline/artifacts.ts.
|
|
5
|
+
*
|
|
6
|
+
* pipeline artifacts publish --stage <stage> [--release <label|digest>] [--dry-run] [--json]
|
|
7
|
+
* publish the artifacts the stage declares, for the release named, or
|
|
8
|
+
* the release cut from HEAD. The declarations are read from the
|
|
9
|
+
* pipeline on the default branch, as the stage's gates are. A wave job
|
|
10
|
+
* runs it after the first stage's release cut.
|
|
11
|
+
* pipeline artifacts read --stage <stage> [--release <label|digest>] [--name <artifact>] [--from <dir>] [--json]
|
|
12
|
+
* print the artifacts the stage published for the release named, else
|
|
13
|
+
* for the release in CHANT_CONTROL_RELEASE, else for the release it
|
|
14
|
+
* last published for. --from reads another repository's records: a
|
|
15
|
+
* checkout of it, or a directory holding its chant/lifecycle.
|
|
16
|
+
* pipeline release-of <commit>
|
|
17
|
+
* print the digest of the release cut from the commit; exit 1 when none
|
|
18
|
+
*/
|
|
19
|
+
import { resolve } from "node:path";
|
|
20
|
+
import { formatError, formatInfo, formatWarning } from "../format.js";
|
|
21
|
+
import { gitStageArtifactPort, publishStageArtifacts, readStageArtifacts, releaseCutFrom, stageArtifactsNote, stageArtifactText, STAGE_ARTIFACTS_RELEASE_ENV, } from "../../pipeline/artifacts.js";
|
|
22
|
+
const USAGE = "chant pipeline artifacts publish --stage <stage> [--release <label|digest>] [--dry-run] [--json] | chant pipeline artifacts read --stage <stage> [--release <label|digest>] [--name <artifact>] [--from <dir>] [--json] | chant pipeline release-of <commit>";
|
|
23
|
+
/** The pipeline on the default branch, or why there is none to read. */
|
|
24
|
+
async function pipelineAtBase(cwd) {
|
|
25
|
+
const { promoteBase, readPipelineAt, readMemberPipeline } = await import("../../pipeline/read.js");
|
|
26
|
+
const base = promoteBase(cwd);
|
|
27
|
+
const read = base ? readPipelineAt(base, cwd) : readMemberPipeline(cwd);
|
|
28
|
+
if (read.status === "absent")
|
|
29
|
+
return "this member has no pipeline";
|
|
30
|
+
if (read.status === "refused")
|
|
31
|
+
return `the pipeline does not fold: ${read.line}`;
|
|
32
|
+
return read.spec;
|
|
33
|
+
}
|
|
34
|
+
/** A release by label or digest, on the ledger at `cwd`. */
|
|
35
|
+
async function releaseNamed(ref, cwd) {
|
|
36
|
+
const { resolveRelease } = await import("../../lifecycle/release-store.js");
|
|
37
|
+
const found = await resolveRelease(ref, { cwd });
|
|
38
|
+
return found ? { digest: found.release.releaseDigest, label: found.label, commit: found.release.commit } : undefined;
|
|
39
|
+
}
|
|
40
|
+
/** Reads each member's outputs in `env` through its steps' capabilities, as the replan step does. */
|
|
41
|
+
async function outputsReader(cwd, env) {
|
|
42
|
+
const { loadChantConfig } = await import("../../config.js");
|
|
43
|
+
const { resolveComponentTargets } = await import("../../components/cli-support.js");
|
|
44
|
+
const { fanOutRegistry } = await import("../../components/fan-out-support.js");
|
|
45
|
+
const { readMarkedOutputs } = await import("../../components/upstream-replan.js");
|
|
46
|
+
const { config } = await loadChantConfig(cwd).catch(() => ({ config: {} }));
|
|
47
|
+
const targets = await resolveComponentTargets(cwd, "all");
|
|
48
|
+
if (!targets.success)
|
|
49
|
+
return targets.error ?? "Could not discover components";
|
|
50
|
+
const registry = await fanOutRegistry(cwd, config);
|
|
51
|
+
const byName = new Map(targets.targets.map((c) => [c.name, c]));
|
|
52
|
+
return async (member) => {
|
|
53
|
+
const component = byName.get(member);
|
|
54
|
+
if (!component)
|
|
55
|
+
return undefined;
|
|
56
|
+
return readMarkedOutputs(component, registry, { env, component: member });
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Publish `stage`'s artifacts for `release` from `cwd`, and push the ledger. Shared by the command and the promote. */
|
|
60
|
+
export async function publishStageFrom(input) {
|
|
61
|
+
const declared = input.spec.stages.find((s) => s.name === input.stage)?.publish;
|
|
62
|
+
if (!declared || Object.keys(declared).length === 0)
|
|
63
|
+
return { status: "none", stage: input.stage };
|
|
64
|
+
const { ENV_VAR } = await import("../../env.js");
|
|
65
|
+
const before = process.env[ENV_VAR];
|
|
66
|
+
process.env[ENV_VAR] = input.stage;
|
|
67
|
+
try {
|
|
68
|
+
const reader = await outputsReader(input.cwd, input.stage);
|
|
69
|
+
if (typeof reader === "string")
|
|
70
|
+
return { status: "refused", stage: input.stage, problems: [reader] };
|
|
71
|
+
const result = await publishStageArtifacts({ spec: input.spec, stage: input.stage, release: input.release, outputsOf: reader, port: gitStageArtifactPort({ cwd: input.cwd }), ...(input.dryRun ? { dryRun: true } : {}) });
|
|
72
|
+
if (result.status === "published" && !input.dryRun) {
|
|
73
|
+
const { pushLifecycleRebasing } = await import("../../lifecycle/git.js");
|
|
74
|
+
const pushed = await pushLifecycleRebasing({ cwd: input.cwd }).catch((err) => ({ pushed: false, pushWarning: err instanceof Error ? err.message : String(err) }));
|
|
75
|
+
if (!pushed.pushed && pushed.pushWarning)
|
|
76
|
+
console.error(formatWarning({ message: pushed.pushWarning }));
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
if (before === undefined)
|
|
82
|
+
delete process.env[ENV_VAR];
|
|
83
|
+
else
|
|
84
|
+
process.env[ENV_VAR] = before;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** The lines a refused publish prints. They name artifacts, members and outputs, never a value. */
|
|
88
|
+
export function publishRefusedMessage(result) {
|
|
89
|
+
return `stage "${result.stage}" published no artifacts: ${result.problems.join("; ")}`;
|
|
90
|
+
}
|
|
91
|
+
export async function runPipelineArtifacts(ctx) {
|
|
92
|
+
const verb = ctx.args.extraPositional;
|
|
93
|
+
if (verb === "publish")
|
|
94
|
+
return runPublish(ctx);
|
|
95
|
+
if (verb === "read")
|
|
96
|
+
return runRead(ctx);
|
|
97
|
+
console.error(formatError({ message: "chant pipeline artifacts takes publish or read", hint: USAGE }));
|
|
98
|
+
return 1;
|
|
99
|
+
}
|
|
100
|
+
async function runPublish(ctx) {
|
|
101
|
+
const { args } = ctx;
|
|
102
|
+
const stage = args.lockStage;
|
|
103
|
+
if (!stage) {
|
|
104
|
+
console.error(formatError({ message: "--stage <stage> is required", hint: USAGE }));
|
|
105
|
+
return 1;
|
|
106
|
+
}
|
|
107
|
+
const cwd = resolve(".");
|
|
108
|
+
const { fetchLifecycle, getHeadCommit } = await import("../../lifecycle/git.js");
|
|
109
|
+
await fetchLifecycle({ cwd }).catch(() => false);
|
|
110
|
+
const spec = await pipelineAtBase(cwd);
|
|
111
|
+
if (typeof spec === "string") {
|
|
112
|
+
console.error(formatError({ message: spec, hint: USAGE }));
|
|
113
|
+
return 1;
|
|
114
|
+
}
|
|
115
|
+
let release;
|
|
116
|
+
if (args.release) {
|
|
117
|
+
release = await releaseNamed(args.release, cwd);
|
|
118
|
+
if (!release) {
|
|
119
|
+
console.error(formatError({ message: `no release is labelled or digested ${args.release}` }));
|
|
120
|
+
return 1;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const head = await getHeadCommit({ cwd }).catch(() => "");
|
|
125
|
+
release = head ? await releaseCutFrom(head, { cwd }) : undefined;
|
|
126
|
+
if (!release) {
|
|
127
|
+
console.error(formatError({ message: `no release was cut from ${head ? head.slice(0, 12) : "HEAD"}, so stage "${stage}" has no release to publish artifacts for`, hint: "Name one with --release <label|digest>" }));
|
|
128
|
+
return 1;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const result = await publishStageFrom({ cwd, spec, stage, release: { digest: release.digest, label: release.label, gitSha: release.commit }, ...(args.dryRun ? { dryRun: true } : {}) });
|
|
132
|
+
if (result.status === "refused") {
|
|
133
|
+
console.error(formatError({ message: publishRefusedMessage(result) }));
|
|
134
|
+
return 1;
|
|
135
|
+
}
|
|
136
|
+
if (result.status === "none") {
|
|
137
|
+
console.error(formatInfo(`stage "${stage}" publishes no artifacts`));
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
if (args.json)
|
|
141
|
+
console.log(JSON.stringify(result.record, null, 2));
|
|
142
|
+
else
|
|
143
|
+
process.stdout.write(stageArtifactsNote(result.record));
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
async function runRead(ctx) {
|
|
147
|
+
const { args } = ctx;
|
|
148
|
+
const stage = args.lockStage;
|
|
149
|
+
if (!stage) {
|
|
150
|
+
console.error(formatError({ message: "--stage <stage> is required", hint: USAGE }));
|
|
151
|
+
return 1;
|
|
152
|
+
}
|
|
153
|
+
const from = args.migrateFrom ? resolve(args.migrateFrom) : resolve(".");
|
|
154
|
+
if (!args.migrateFrom) {
|
|
155
|
+
const { fetchLifecycle } = await import("../../lifecycle/git.js");
|
|
156
|
+
await fetchLifecycle({ cwd: from }).catch(() => false);
|
|
157
|
+
}
|
|
158
|
+
const ref = args.release ?? (process.env[STAGE_ARTIFACTS_RELEASE_ENV] || undefined);
|
|
159
|
+
let digest;
|
|
160
|
+
if (ref) {
|
|
161
|
+
digest = ref.includes(":") ? ref : (await releaseNamed(ref, from))?.digest;
|
|
162
|
+
if (!digest) {
|
|
163
|
+
console.error(formatError({ message: `no release is labelled ${ref}` }));
|
|
164
|
+
return 1;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const record = await readStageArtifacts(gitStageArtifactPort({ cwd: from }), { stage, ...(digest ? { release: digest } : {}) });
|
|
168
|
+
if (!record) {
|
|
169
|
+
console.error(formatError({ message: `stage "${stage}" published no artifacts${digest ? ` for release ${digest}` : ""}` }));
|
|
170
|
+
return 1;
|
|
171
|
+
}
|
|
172
|
+
if (args.selectName) {
|
|
173
|
+
const entry = record.artifacts[args.selectName];
|
|
174
|
+
if (!entry) {
|
|
175
|
+
console.error(formatError({ message: `stage "${stage}" published no artifact "${args.selectName}" for release ${record.label ?? record.release}; it published ${Object.keys(record.artifacts).sort().join(", ")}` }));
|
|
176
|
+
return 1;
|
|
177
|
+
}
|
|
178
|
+
console.log(args.json ? JSON.stringify(entry) : stageArtifactText(entry));
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
if (args.json)
|
|
182
|
+
console.log(JSON.stringify(record, null, 2));
|
|
183
|
+
else
|
|
184
|
+
process.stdout.write(stageArtifactsNote(record));
|
|
185
|
+
return 0;
|
|
186
|
+
}
|
|
187
|
+
export async function runPipelineReleaseOf(ctx) {
|
|
188
|
+
const commit = ctx.args.extraPositional;
|
|
189
|
+
if (!commit || !/^[0-9a-f]{7,64}$/.test(commit)) {
|
|
190
|
+
console.error(formatError({ message: "pipeline release-of takes a commit sha", hint: USAGE }));
|
|
191
|
+
return 1;
|
|
192
|
+
}
|
|
193
|
+
const cwd = resolve(".");
|
|
194
|
+
const { fetchLifecycle } = await import("../../lifecycle/git.js");
|
|
195
|
+
await fetchLifecycle({ cwd }).catch(() => false);
|
|
196
|
+
const found = await releaseCutFrom(commit, { cwd });
|
|
197
|
+
if (!found) {
|
|
198
|
+
console.error(formatError({ message: `no release was cut from ${commit.slice(0, 12)}` }));
|
|
199
|
+
return 1;
|
|
200
|
+
}
|
|
201
|
+
console.log(found.digest);
|
|
202
|
+
return 0;
|
|
203
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant pipeline` (#5324): the member's folded pipeline.
|
|
3
|
+
*
|
|
4
|
+
* pipeline spec [--stage <stage>] [--at <commit>]
|
|
5
|
+
* print the folded spec, or with --stage that stage's op-waves spec.
|
|
6
|
+
* With --at, or CHANT_WAVES_SPEC_AT set (a wave job's render), the file
|
|
7
|
+
* is folded as it stood at that commit, and a commit with no pipeline
|
|
8
|
+
* prints nothing and exits 0, which a wave job reads as a spec absent
|
|
9
|
+
* at base. A file outside the subset exits 1 with its finding.
|
|
10
|
+
* pipeline generate <github|gitlab|forgejo> [--output <dir>] [--format json]
|
|
11
|
+
* write the merge's waves workflow and the promote workflow
|
|
12
|
+
*/
|
|
13
|
+
import type { CommandContext } from "../registry.js";
|
|
14
|
+
export declare function runPipelineSpec(ctx: CommandContext): Promise<number>;
|
|
15
|
+
export declare function runPipelineGenerate(ctx: CommandContext): Promise<number>;
|
|
16
|
+
export declare function runPipelineUnknown(): Promise<number>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant pipeline` (#5324): the member's folded pipeline.
|
|
3
|
+
*
|
|
4
|
+
* pipeline spec [--stage <stage>] [--at <commit>]
|
|
5
|
+
* print the folded spec, or with --stage that stage's op-waves spec.
|
|
6
|
+
* With --at, or CHANT_WAVES_SPEC_AT set (a wave job's render), the file
|
|
7
|
+
* is folded as it stood at that commit, and a commit with no pipeline
|
|
8
|
+
* prints nothing and exits 0, which a wave job reads as a spec absent
|
|
9
|
+
* at base. A file outside the subset exits 1 with its finding.
|
|
10
|
+
* pipeline generate <github|gitlab|forgejo> [--output <dir>] [--format json]
|
|
11
|
+
* write the merge's waves workflow and the promote workflow
|
|
12
|
+
*/
|
|
13
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { dirname, join, resolve } from "node:path";
|
|
15
|
+
import { GENERATED_MARKER } from "../../discovery/files.js";
|
|
16
|
+
import { OP_WAVES_SPEC_AT_ENV } from "../../op/op-waves-render-spec.js";
|
|
17
|
+
import { readMemberPipeline, readPipelineAt } from "../../pipeline/read.js";
|
|
18
|
+
import { stageWavesSpec } from "../../pipeline/stages.js";
|
|
19
|
+
import { PIPELINE_FILE } from "../../pipeline/spec.js";
|
|
20
|
+
import { formatBold, formatError, formatSuccess } from "../format.js";
|
|
21
|
+
import { DEFAULT_OP_PIPELINE_DIRS } from "./run-generate.js";
|
|
22
|
+
const USAGE = "chant pipeline spec [--stage <stage>] [--at <commit>] | chant pipeline generate <github|gitlab|forgejo> [--output <dir>] [--format json]";
|
|
23
|
+
function refused(read) {
|
|
24
|
+
console.error(formatError({ message: `${read.line}`, hint: "A pipeline file stays inside the TypeScript-as-data subset: it is folded, never run." }));
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
export async function runPipelineSpec(ctx) {
|
|
28
|
+
const { args } = ctx;
|
|
29
|
+
const at = args.at ?? process.env[OP_WAVES_SPEC_AT_ENV] ?? undefined;
|
|
30
|
+
const read = at ? readPipelineAt(at, process.cwd()) : readMemberPipeline(process.cwd());
|
|
31
|
+
if (read.status === "absent") {
|
|
32
|
+
if (at)
|
|
33
|
+
return 0;
|
|
34
|
+
console.error(formatError({ message: `this member has no ${PIPELINE_FILE}`, hint: USAGE }));
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
if (read.status === "refused")
|
|
38
|
+
return refused(read);
|
|
39
|
+
try {
|
|
40
|
+
const out = args.lockStage ? stageWavesSpec(read.spec, args.lockStage) : read.spec;
|
|
41
|
+
console.log(JSON.stringify(out, null, 2));
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
console.error(formatError({ message: err instanceof Error ? err.message : String(err) }));
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export async function runPipelineGenerate(ctx) {
|
|
50
|
+
const { args } = ctx;
|
|
51
|
+
const provider = args.extraPositional;
|
|
52
|
+
if (!provider) {
|
|
53
|
+
console.error(formatError({ message: "pipeline generate needs a forge: github, gitlab or forgejo", hint: USAGE }));
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
const read = readMemberPipeline(process.cwd());
|
|
57
|
+
if (read.status === "absent") {
|
|
58
|
+
console.error(formatError({ message: `this member has no ${PIPELINE_FILE}`, hint: USAGE }));
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
if (read.status === "refused")
|
|
62
|
+
return refused(read);
|
|
63
|
+
const { generatePipeline } = await import("../../pipeline/generate.js");
|
|
64
|
+
// #5348: each stage's identity and its config and secret set, from the workspace declaration.
|
|
65
|
+
let declared = {};
|
|
66
|
+
try {
|
|
67
|
+
const { declaredCloudIdentityDeclaration, declaredEnvironmentSets } = await import("../../workspace/ci-cloud-identity.js");
|
|
68
|
+
const [identity, environmentSets] = await Promise.all([declaredCloudIdentityDeclaration(process.cwd()), declaredEnvironmentSets(process.cwd())]);
|
|
69
|
+
const member = await memberName(process.cwd());
|
|
70
|
+
declared = { ...(identity ? { identity } : {}), ...(environmentSets ? { environmentSets } : {}), ...(member ? { member } : {}) };
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
console.error(formatError({ message: err instanceof Error ? err.message : String(err) }));
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
76
|
+
const result = await generatePipeline(read.spec, provider, declared);
|
|
77
|
+
if (!result.success) {
|
|
78
|
+
console.error(formatError({ message: result.error ?? "Failed to generate the pipeline" }));
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
const header = `# ${GENERATED_MARKER}. Regenerate with: chant pipeline generate ${provider}\n`;
|
|
82
|
+
const outDir = args.output ?? DEFAULT_OP_PIPELINE_DIRS[provider] ?? ".";
|
|
83
|
+
const files = (result.files ?? []).map((f) => ({ name: f.name, path: join(outDir, f.name), content: header + f.yaml }));
|
|
84
|
+
if (args.format === "json") {
|
|
85
|
+
console.log(JSON.stringify({ files, jobs: result.jobs ?? [] }, null, 2));
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
for (const file of files) {
|
|
89
|
+
const target = resolve(file.path);
|
|
90
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
91
|
+
writeFileSync(target, file.content);
|
|
92
|
+
console.error(formatSuccess(`wrote ${formatBold(file.path)}`));
|
|
93
|
+
}
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
/** The workspace member whose directory holds `cwd`, or undefined. */
|
|
97
|
+
async function memberName(cwd) {
|
|
98
|
+
const { findWorkspaceRoot } = await import("../../project-root.js");
|
|
99
|
+
const found = findWorkspaceRoot(cwd);
|
|
100
|
+
if (!found)
|
|
101
|
+
return undefined;
|
|
102
|
+
const [{ readDeclaration }, { workingTree }, { memberHolding }, { relative, sep }] = await Promise.all([import("../../workspace/declaration.js"), import("../../workspace/tree.js"), import("../../workspace/record-assets.js"), import("node:path")]);
|
|
103
|
+
const rel = relative(found.dir, resolve(cwd));
|
|
104
|
+
if (rel.startsWith(".."))
|
|
105
|
+
return undefined;
|
|
106
|
+
const posix = sep === "/" ? rel : rel.split(sep).join("/");
|
|
107
|
+
return memberHolding(posix === "" ? "." : posix, readDeclaration(workingTree(found.dir)).members ?? []) ?? undefined;
|
|
108
|
+
}
|
|
109
|
+
export async function runPipelineUnknown() {
|
|
110
|
+
console.error(formatError({ message: "chant pipeline takes spec, generate, artifacts or release-of", hint: USAGE }));
|
|
111
|
+
return 1;
|
|
112
|
+
}
|
|
@@ -201,7 +201,11 @@ export async function runComponentsPrComment(ctx) {
|
|
|
201
201
|
return fail("pr-comment needs the default branch: --branch <name>, or repository.default_branch in the event");
|
|
202
202
|
// INTENTIUS/terragucci#1461: teams are read with the pipeline's team token when it has one.
|
|
203
203
|
const teamToken = env[COMMENT_ALLOW_TOKEN_ENV];
|
|
204
|
+
// #5354: a reject comment is recorded when the product's words map a command onto reject.
|
|
205
|
+
const { commentRejectFromEnv } = await import("../../ci-comment-reject.js");
|
|
206
|
+
const reject = await commentRejectFromEnv(activeProductWords(), env);
|
|
204
207
|
const outcome = await answerProductComment({
|
|
208
|
+
...(reject ? { reject } : {}),
|
|
205
209
|
forge: kind,
|
|
206
210
|
event,
|
|
207
211
|
repo: target.repo,
|
|
@@ -51,6 +51,9 @@ export async function runComponentsPrNotes(ctx) {
|
|
|
51
51
|
return fail(err instanceof Error ? err.message : String(err));
|
|
52
52
|
}
|
|
53
53
|
const beforeMerge = more.wavesBeforeMerge && more.waves ? await beforeMergeDeps(forge, more, env) : undefined;
|
|
54
|
+
// #5354: a reject note is recorded when the product's words map a command onto reject.
|
|
55
|
+
const { commentRejectFromEnv } = await import("../../ci-comment-reject.js");
|
|
56
|
+
const reject = await commentRejectFromEnv(words, env, cwd);
|
|
54
57
|
const polled = await pollNoteCommands({
|
|
55
58
|
reads: forgeReadsFor(target),
|
|
56
59
|
forge,
|
|
@@ -64,7 +67,7 @@ export async function runComponentsPrNotes(ctx) {
|
|
|
64
67
|
...(args.locks ? { locks: true } : {}),
|
|
65
68
|
...(more.waves ? { waves: more.waves } : {}),
|
|
66
69
|
...(more.wavesBeforeMerge ? { wavesBeforeMerge: more.wavesBeforeMerge } : {}),
|
|
67
|
-
}, beforeMerge ? { beforeMerge } : {}),
|
|
70
|
+
}, { ...(beforeMerge ? { beforeMerge } : {}), ...(reject ? { reject } : {}) }),
|
|
68
71
|
log: ledgerNoteLog({ cwd }),
|
|
69
72
|
env,
|
|
70
73
|
// #4984: a merged merge request's wave-<n> stops the retried waves after it.
|