@intentius/chant 0.124.76 → 0.124.77
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/__fixtures__/agent-guard/plywood.d.ts +8 -0
- package/dist/__fixtures__/agent-guard/plywood.d.ts.map +1 -0
- package/dist/__fixtures__/agent-guard/plywood.js +19 -0
- package/dist/__fixtures__/agent-guard/terragucci.d.ts +8 -0
- package/dist/__fixtures__/agent-guard/terragucci.d.ts.map +1 -0
- package/dist/__fixtures__/agent-guard/terragucci.js +30 -0
- package/dist/__fixtures__/gated-ledger.d.ts +10 -0
- package/dist/__fixtures__/gated-ledger.d.ts.map +1 -0
- package/dist/__fixtures__/gated-ledger.js +51 -0
- package/dist/agent-guard.d.ts +143 -0
- package/dist/agent-guard.d.ts.map +1 -0
- package/dist/agent-guard.js +456 -0
- package/dist/ci-commit.d.ts +54 -3
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +69 -7
- package/dist/ci-own-jobs.d.ts +81 -0
- package/dist/ci-own-jobs.d.ts.map +1 -0
- package/dist/ci-own-jobs.js +234 -0
- package/dist/ci-product.d.ts +39 -0
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +40 -0
- package/dist/cli/handlers/approve.d.ts +5 -1
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +17 -11
- package/dist/cli/handlers/build.d.ts +1 -1
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +88 -2
- package/dist/cli/handlers/commit.d.ts.map +1 -1
- package/dist/cli/handlers/commit.js +3 -1
- package/dist/cli/handlers/notify-relay.d.ts +18 -1
- package/dist/cli/handlers/notify-relay.d.ts.map +1 -1
- package/dist/cli/handlers/notify-relay.js +90 -14
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +3 -1
- package/dist/cli/handlers/release.d.ts +5 -1
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +17 -5
- package/dist/cli/handlers/run-generate.d.ts.map +1 -1
- package/dist/cli/handlers/run-generate.js +2 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +21 -1
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +60 -4
- package/dist/cli/registry.d.ts +16 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/pr-env-components.d.ts +65 -0
- package/dist/components/pr-env-components.d.ts.map +1 -0
- package/dist/components/pr-env-components.js +163 -0
- package/dist/components/pr-policy.d.ts +15 -0
- package/dist/components/pr-policy.d.ts.map +1 -1
- package/dist/components/pr-policy.js +24 -1
- package/dist/components/release-compile.d.ts +15 -3
- package/dist/components/release-compile.d.ts.map +1 -1
- package/dist/components/release-compile.js +66 -15
- package/dist/gate-policy.d.ts +14 -1
- package/dist/gate-policy.d.ts.map +1 -1
- package/dist/gate-policy.js +16 -6
- package/dist/lexicon.d.ts +17 -1
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lexicon.js +1 -0
- package/dist/lifecycle/gated-op.d.ts +95 -0
- package/dist/lifecycle/gated-op.d.ts.map +1 -0
- package/dist/lifecycle/gated-op.js +96 -0
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +83 -2
- package/dist/notify-relay-repo.d.ts +131 -0
- package/dist/notify-relay-repo.d.ts.map +1 -0
- package/dist/notify-relay-repo.js +202 -0
- package/dist/notify-relay.d.ts +25 -1
- package/dist/notify-relay.d.ts.map +1 -1
- package/dist/notify-relay.js +28 -2
- package/dist/op/op-waves-capability.js +2 -2
- package/dist/policy-engine.d.ts +95 -0
- package/dist/policy-engine.d.ts.map +1 -0
- package/dist/policy-engine.js +158 -0
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/state-export.d.ts +126 -0
- package/dist/state-export.d.ts.map +1 -0
- package/dist/state-export.js +157 -0
- package/dist/state-migration.d.ts +148 -0
- package/dist/state-migration.d.ts.map +1 -0
- package/dist/state-migration.js +147 -0
- package/dist/state-unlock.d.ts +167 -0
- package/dist/state-unlock.d.ts.map +1 -0
- package/dist/state-unlock.js +197 -0
- package/dist/wave-runtime.mjs +329 -329
- package/dist/workspace/declaration.schema.json +1 -1
- package/dist/workspace/release-workflow.d.ts +10 -0
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +8 -3
- package/package.json +1 -1
- package/src/__fixtures__/agent-guard/plywood.ts +27 -0
- package/src/__fixtures__/agent-guard/terragucci.ts +39 -0
- package/src/__fixtures__/gated-ledger.ts +58 -0
- package/src/agent-guard.test.ts +320 -0
- package/src/agent-guard.ts +548 -0
- package/src/ci-commit.test.ts +50 -2
- package/src/ci-commit.ts +93 -9
- package/src/ci-own-jobs.test.ts +109 -0
- package/src/ci-own-jobs.ts +253 -0
- package/src/ci-product.ts +81 -0
- package/src/cli/handlers/approve-cwd.test.ts +112 -0
- package/src/cli/handlers/approve.ts +22 -11
- package/src/cli/handlers/build-own-jobs.test.ts +80 -0
- package/src/cli/handlers/build-pr-loop-control.test.ts +88 -0
- package/src/cli/handlers/build-run-group.test.ts +60 -0
- package/src/cli/handlers/build.ts +83 -3
- package/src/cli/handlers/commit.ts +3 -0
- package/src/cli/handlers/notify-relay.ts +99 -17
- package/src/cli/handlers/pr.ts +3 -1
- package/src/cli/handlers/release.ts +15 -5
- package/src/cli/handlers/run-generate.ts +2 -1
- package/src/cli/main.ts +21 -1
- package/src/cli/parse-args.ts +45 -3
- package/src/cli/registry.ts +16 -0
- package/src/components/pr-env-components.test.ts +138 -0
- package/src/components/pr-env-components.ts +214 -0
- package/src/components/pr-policy.test.ts +41 -1
- package/src/components/pr-policy.ts +25 -1
- package/src/components/release-compile.test.ts +47 -0
- package/src/components/release-compile.ts +70 -13
- package/src/gate-policy-bundle.test.ts +14 -0
- package/src/gate-policy.test.ts +7 -0
- package/src/gate-policy.ts +22 -7
- package/src/lexicon.ts +18 -1
- package/src/lifecycle/gated-op.ts +158 -0
- package/src/lifecycle/git.test.ts +92 -0
- package/src/lifecycle/git.ts +71 -2
- package/src/notify-relay-repo.test.ts +284 -0
- package/src/notify-relay-repo.ts +234 -0
- package/src/notify-relay.test.ts +12 -0
- package/src/notify-relay.ts +30 -3
- package/src/op/op-waves-capability.ts +2 -2
- package/src/policy-engine.test.ts +163 -0
- package/src/policy-engine.ts +201 -0
- package/src/release-floors.ts +1 -1
- package/src/state-export.test.ts +125 -0
- package/src/state-export.ts +228 -0
- package/src/state-migration.test.ts +134 -0
- package/src/state-migration.ts +237 -0
- package/src/state-unlock.test.ts +166 -0
- package/src/state-unlock.ts +294 -0
- package/src/workspace/declaration.schema.json +1 -1
- package/src/workspace/release-workflow.test.ts +34 -0
- package/src/workspace/release-workflow.ts +17 -3
package/dist/ci-commit.js
CHANGED
|
@@ -28,6 +28,8 @@ import { spawn } from "node:child_process";
|
|
|
28
28
|
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
29
29
|
import { join } from "node:path";
|
|
30
30
|
import { CHANT_EXIT } from "./exit-codes.js";
|
|
31
|
+
import { FORGE_TOKEN_VARS } from "./ci-handover.js";
|
|
32
|
+
import { NEXT_RELEASE } from "./release-floors.js";
|
|
31
33
|
import { agentForbiddenPaths, AgentError, branchOk, errText, LOGIN, readSmall, SHA } from "./ci-agent.js";
|
|
32
34
|
import { parseProductComment } from "./ci-product-words.js";
|
|
33
35
|
/** The first chant with the commit job and the scheduled Op spec's `commit` (#4722). Products feature-detect on it. */
|
|
@@ -36,6 +38,12 @@ export const CI_COMMIT_FLOOR = "0.124.71";
|
|
|
36
38
|
export const CI_COMMIT_PUSH_FLOOR = "0.124.72";
|
|
37
39
|
/** The first chant whose commit job takes `allowedFiles` (#4758). */
|
|
38
40
|
export const CI_COMMIT_FILES_FLOOR = "0.124.73";
|
|
41
|
+
/**
|
|
42
|
+
* The first chant whose commit job takes `commandEnv`, gives the command
|
|
43
|
+
* `CHANT_COMMIT_PR`, keeps the tail of its standard error and replies with a
|
|
44
|
+
* product's refusal text ({@link setCommitRefusalReply}) (#4724).
|
|
45
|
+
*/
|
|
46
|
+
export const CI_COMMIT_REPLY_FLOOR = NEXT_RELEASE;
|
|
39
47
|
export const COMMIT_TRIGGERS = ["comment", "check"];
|
|
40
48
|
export const COMMIT_MAX_RUNS = 3;
|
|
41
49
|
export const COMMIT_TIMEOUT_MINUTES = 10;
|
|
@@ -57,7 +65,10 @@ export const COMMIT_ENV = {
|
|
|
57
65
|
timeout: "CHANT_COMMIT_TIMEOUT",
|
|
58
66
|
env: "CHANT_COMMIT_ENV",
|
|
59
67
|
mergeBase: "CHANT_COMMIT_MERGE_BASE",
|
|
68
|
+
commandEnv: "CHANT_COMMIT_COMMAND_ENV",
|
|
60
69
|
};
|
|
70
|
+
/** The variable the command reads the pull request's number from (#4724), such as for a default name. */
|
|
71
|
+
export const COMMIT_PR_ENV = "CHANT_COMMIT_PR";
|
|
61
72
|
/** GitLab starts no pipeline on a note: a pipeline of the default branch started with these runs a comment commit job. */
|
|
62
73
|
export const GITLAB_COMMIT_PR_VAR = "CHANT_COMMIT_PR";
|
|
63
74
|
export const GITLAB_COMMIT_WORD_VAR = "CHANT_COMMIT";
|
|
@@ -70,6 +81,10 @@ export const COMMIT_BASE_REF = "refs/chant/commit-base";
|
|
|
70
81
|
export const COMMIT_DECISION_FILE = "decision.json";
|
|
71
82
|
export const COMMIT_PATCH_FILE = "change.patch";
|
|
72
83
|
export const COMMIT_RC_FILE = "rc";
|
|
84
|
+
/** The tail of the command's standard error (#4724), which a product's refusal reply reads. */
|
|
85
|
+
export const COMMIT_OUTPUT_FILE = "output";
|
|
86
|
+
/** How much of the command's standard error {@link COMMIT_OUTPUT_FILE} keeps, from the end. */
|
|
87
|
+
export const COMMIT_OUTPUT_LIMIT = 8192;
|
|
73
88
|
/** What `chant commit land` leaves when it pushed (#4749): the pushed commit, which the push job's `after` lines read. */
|
|
74
89
|
export const COMMIT_PUSHED_FILE = "pushed";
|
|
75
90
|
/**
|
|
@@ -144,6 +159,12 @@ export function resolveCommitSpec(name, spec, product = "chant") {
|
|
|
144
159
|
const after = spec.after ?? [];
|
|
145
160
|
if (!Array.isArray(after) || !after.every((l) => typeof l === "string" && l.trim() !== "" && !l.includes("\n")))
|
|
146
161
|
throw new AgentError(`${where}: after is a list of shell lines, one command each`);
|
|
162
|
+
const commandEnv = spec.commandEnv ?? [];
|
|
163
|
+
if (!Array.isArray(commandEnv) || !commandEnv.every((v) => typeof v === "string" && VAR.test(v)))
|
|
164
|
+
throw new AgentError(`${where}: commandEnv is a list of variable names`);
|
|
165
|
+
const tokens = commandEnv.filter((v) => FORGE_TOKEN_VARS.includes(v) || v === spec.tokenEnv || v.startsWith("CHANT_COMMIT_"));
|
|
166
|
+
if (tokens.length > 0)
|
|
167
|
+
throw new AgentError(`${where}: commandEnv may not pass ${tokens.join(", ")}: the command never sees a forge token or the job's own settings`);
|
|
147
168
|
return {
|
|
148
169
|
name,
|
|
149
170
|
on: spec.on,
|
|
@@ -159,6 +180,7 @@ export function resolveCommitSpec(name, spec, product = "chant") {
|
|
|
159
180
|
mergeBase: spec.mergeBase === true,
|
|
160
181
|
jobToken: spec.jobToken === true,
|
|
161
182
|
after: [...after],
|
|
183
|
+
commandEnv: [...new Set(commandEnv)],
|
|
162
184
|
};
|
|
163
185
|
}
|
|
164
186
|
/** The settings as the generated jobs' variables. */
|
|
@@ -176,6 +198,7 @@ export function commitSettingsEnv(s) {
|
|
|
176
198
|
[COMMIT_ENV.timeout]: String(s.timeout),
|
|
177
199
|
[COMMIT_ENV.env]: s.env,
|
|
178
200
|
...(s.mergeBase ? { [COMMIT_ENV.mergeBase]: "1" } : {}),
|
|
201
|
+
...(s.commandEnv.length > 0 ? { [COMMIT_ENV.commandEnv]: JSON.stringify(s.commandEnv) } : {}),
|
|
179
202
|
};
|
|
180
203
|
}
|
|
181
204
|
/** The settings back from the job's variables, checked as {@link resolveCommitSpec} checks a spec. */
|
|
@@ -223,6 +246,7 @@ export function commitSettingsFromEnv(env, product = "chant") {
|
|
|
223
246
|
...(guarded ? { guarded } : {}),
|
|
224
247
|
...(env[COMMIT_ENV.env] ? { env: env[COMMIT_ENV.env] } : {}),
|
|
225
248
|
...(env[COMMIT_ENV.mergeBase] === "1" ? { mergeBase: true } : {}),
|
|
249
|
+
...(list(COMMIT_ENV.commandEnv) ? { commandEnv: list(COMMIT_ENV.commandEnv) } : {}),
|
|
226
250
|
};
|
|
227
251
|
return resolveCommitSpec(name, spec, product);
|
|
228
252
|
}
|
|
@@ -499,7 +523,16 @@ export async function prepareCommitRun(i) {
|
|
|
499
523
|
}
|
|
500
524
|
export const runCommitArgv = (argv, o) => new Promise((done) => {
|
|
501
525
|
let timedOut = false;
|
|
502
|
-
|
|
526
|
+
let tail = Buffer.alloc(0);
|
|
527
|
+
const child = spawn(argv[0], argv.slice(1), { cwd: o.cwd, env: o.env, stdio: ["ignore", "inherit", "pipe"] });
|
|
528
|
+
// The job's log still gets all of it; the tail is kept for the reply.
|
|
529
|
+
child.stderr?.on("data", (chunk) => {
|
|
530
|
+
process.stderr.write(chunk);
|
|
531
|
+
tail = Buffer.concat([tail, chunk]);
|
|
532
|
+
if (tail.length > COMMIT_OUTPUT_LIMIT)
|
|
533
|
+
tail = tail.subarray(tail.length - COMMIT_OUTPUT_LIMIT);
|
|
534
|
+
});
|
|
535
|
+
const output = () => tail.toString("utf8");
|
|
503
536
|
const timer = setTimeout(() => {
|
|
504
537
|
timedOut = true;
|
|
505
538
|
child.kill("SIGTERM");
|
|
@@ -507,25 +540,29 @@ export const runCommitArgv = (argv, o) => new Promise((done) => {
|
|
|
507
540
|
}, o.timeoutMs);
|
|
508
541
|
child.on("error", () => {
|
|
509
542
|
clearTimeout(timer);
|
|
510
|
-
done({ exitCode: null, timedOut });
|
|
543
|
+
done({ exitCode: null, timedOut, output: output() });
|
|
511
544
|
});
|
|
512
545
|
child.on("close", (code) => {
|
|
513
546
|
clearTimeout(timer);
|
|
514
|
-
done({ exitCode: code, timedOut });
|
|
547
|
+
done({ exitCode: code, timedOut, output: output() });
|
|
515
548
|
});
|
|
516
549
|
});
|
|
517
550
|
/**
|
|
518
551
|
* The variables the command sees: process basics, with the checkout's
|
|
519
552
|
* `node_modules/.bin` first on `PATH` so a product's bin installed on the
|
|
520
|
-
* target branch runs on the head's files. Never a forge or cloud token.
|
|
553
|
+
* target branch runs on the head's files. Never a forge or cloud token. Also
|
|
554
|
+
* the variables the spec's `commandEnv` names, and {@link COMMIT_PR_ENV}, the
|
|
555
|
+
* pull request's number (#4724).
|
|
521
556
|
*/
|
|
522
|
-
export function commitCommandEnv(env, checkout) {
|
|
557
|
+
export function commitCommandEnv(env, checkout, o = {}) {
|
|
523
558
|
const out = {};
|
|
524
|
-
for (const name of ["PATH", "HOME", "TMPDIR", "LANG", "LC_ALL", "TERM", "SystemRoot", "npm_config_cache"]) {
|
|
559
|
+
for (const name of ["PATH", "HOME", "TMPDIR", "LANG", "LC_ALL", "TERM", "SystemRoot", "npm_config_cache", ...(o.names ?? [])]) {
|
|
525
560
|
const v = env[name];
|
|
526
561
|
if (v !== undefined)
|
|
527
562
|
out[name] = v;
|
|
528
563
|
}
|
|
564
|
+
if (o.pr !== undefined)
|
|
565
|
+
out[COMMIT_PR_ENV] = String(o.pr);
|
|
529
566
|
const bin = join(checkout, "node_modules", ".bin");
|
|
530
567
|
if (existsSync(bin))
|
|
531
568
|
out.PATH = out.PATH ? `${bin}:${out.PATH}` : bin;
|
|
@@ -554,14 +591,28 @@ export async function runCommit(i) {
|
|
|
554
591
|
return { rc: "conflict", changed: false };
|
|
555
592
|
}
|
|
556
593
|
}
|
|
557
|
-
const
|
|
594
|
+
const env = commitCommandEnv(i.env, i.checkout, { names: i.settings.commandEnv, ...(decision.pr !== undefined ? { pr: decision.pr } : {}) });
|
|
595
|
+
const out = await i.runCommand(i.settings.command, { cwd: i.workDir, env, timeoutMs: i.settings.timeout * 60000 });
|
|
558
596
|
const rc = out.timedOut ? "timeout" : out.exitCode === null ? "no-exit" : String(out.exitCode);
|
|
559
597
|
writeFileSync(rcFile, `${rc}\n`);
|
|
598
|
+
if (out.output)
|
|
599
|
+
writeFileSync(join(i.dir, COMMIT_OUTPUT_FILE), out.output.slice(-COMMIT_OUTPUT_LIMIT));
|
|
560
600
|
i.git(["add", "-A"], { cwd: i.workDir });
|
|
561
601
|
const patch = i.git(["diff", "--cached", "--binary", "--no-renames", "HEAD"], { cwd: i.workDir });
|
|
562
602
|
writeFileSync(join(i.dir, COMMIT_PATCH_FILE), patch);
|
|
563
603
|
return { rc, changed: patch.length > 0 };
|
|
564
604
|
}
|
|
605
|
+
let activeRefusalReply;
|
|
606
|
+
/** Set the refusal reply for this process (a product's bin, once, as it sets its words). Returns the one it replaced. */
|
|
607
|
+
export function setCommitRefusalReply(reply) {
|
|
608
|
+
const was = activeRefusalReply;
|
|
609
|
+
activeRefusalReply = reply;
|
|
610
|
+
return was;
|
|
611
|
+
}
|
|
612
|
+
/** The refusal reply {@link setCommitRefusalReply} set, if any. */
|
|
613
|
+
export function activeCommitRefusalReply() {
|
|
614
|
+
return activeRefusalReply;
|
|
615
|
+
}
|
|
565
616
|
const code = (s) => "`" + s.replaceAll("`", "'") + "`";
|
|
566
617
|
/**
|
|
567
618
|
* `chant commit land`: from the commit job's patch to a pushed commit, or a
|
|
@@ -633,6 +684,17 @@ export async function landCommitChange(i) {
|
|
|
633
684
|
}
|
|
634
685
|
if (rc === "timeout")
|
|
635
686
|
return finish({ result: "stopped", reason: `the command passed its ${s.timeout} minute limit` }, `${code(s.command.join(" "))} was stopped at its ${s.timeout} minute limit, so nothing was pushed.`);
|
|
687
|
+
if (rc !== "0" && /^[0-9]+$/.test(rc) && i.refusalReply) {
|
|
688
|
+
let said;
|
|
689
|
+
try {
|
|
690
|
+
said = i.refusalReply({ settings: s, rc, output: readSmall(join(i.dir, COMMIT_OUTPUT_FILE), COMMIT_OUTPUT_LIMIT * 2) ?? "" });
|
|
691
|
+
}
|
|
692
|
+
catch {
|
|
693
|
+
said = undefined;
|
|
694
|
+
}
|
|
695
|
+
if (said)
|
|
696
|
+
return finish({ result: "refused", reason: `the command refused, exiting ${rc}` }, `${said.trim()} Nothing was pushed.`);
|
|
697
|
+
}
|
|
636
698
|
if (rc !== "0")
|
|
637
699
|
return finish({ result: "failed", reason: `the command exited ${rc || "with no code"}` }, `${code(s.command.join(" "))} stopped with ${rc ? `exit code ${rc}` : "no exit code"}, so nothing was pushed. The commit job's log has its output.`);
|
|
638
700
|
const head = await i.forge.pullRequestHead?.(pr).catch(() => undefined);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A repository's own jobs in a pipeline file chant generates (#4769).
|
|
3
|
+
*
|
|
4
|
+
* chant's generators write the whole file, so a job a repository adds by
|
|
5
|
+
* hand is gone at the next `chant build`. Two ways keep it:
|
|
6
|
+
*
|
|
7
|
+
* - a jobs file, or a map of jobs, merged after chant's jobs
|
|
8
|
+
* ({@link mergeOwnJobs}, `chant build --own-jobs <file>`). The file is in
|
|
9
|
+
* the forge's own syntax: a map of job name to job. A name chant's file
|
|
10
|
+
* already gives a job is refused, and on GitLab a top-level keyword too.
|
|
11
|
+
* terragucci's `own_jobs` works this way.
|
|
12
|
+
* - the jobs of the old file that the new one lacks, put back as they were
|
|
13
|
+
* written, comments and all ({@link keepOwnJobs}, `chant build
|
|
14
|
+
* --keep-own-jobs`). A job that runs `chant` or the product's bin counts as
|
|
15
|
+
* generated and is not kept. plywood's `init` and `ci` work this way.
|
|
16
|
+
*
|
|
17
|
+
* Either way the jobs go after chant's, under one comment line: inside
|
|
18
|
+
* `jobs:` at two spaces on GitHub and Forgejo, and at the top level on
|
|
19
|
+
* GitLab. The blocks are read as text by their indentation, so a kept job
|
|
20
|
+
* keeps its formatting. A file with no own jobs is returned unchanged.
|
|
21
|
+
*/
|
|
22
|
+
/** The first chant with `mergeOwnJobs`, `keepOwnJobs` and `chant build --own-jobs` / `--keep-own-jobs` (#4769). Products feature-detect on it. */
|
|
23
|
+
export declare const OWN_JOBS_FLOOR = "0.124.77";
|
|
24
|
+
/** The forges whose pipeline files take own jobs. */
|
|
25
|
+
export type OwnJobsForge = "github" | "gitlab" | "forgejo";
|
|
26
|
+
export declare const OWN_JOBS_FORGES: readonly OwnJobsForge[];
|
|
27
|
+
/** The default line above the own jobs. A product passes its own as `line`. */
|
|
28
|
+
export declare const OWN_JOBS_LINE = "# Your own jobs, kept as they are when chant writes this file again.";
|
|
29
|
+
/** GitLab's top-level keys that are not jobs: never read as a job, never kept. */
|
|
30
|
+
export declare const GITLAB_TOP_KEYWORDS: readonly string[];
|
|
31
|
+
/** The names an own job may not take on GitLab: the keywords, and `pages`, which GitLab reads as its Pages job. */
|
|
32
|
+
export declare const GITLAB_RESERVED_JOB_NAMES: readonly string[];
|
|
33
|
+
/** A job name every forge's YAML reads as a plain key. */
|
|
34
|
+
export declare const OWN_JOB_NAME: RegExp;
|
|
35
|
+
/** An own job refused: a collision, a reserved name, or a file that is not a map of jobs. */
|
|
36
|
+
export declare class OwnJobsError extends Error {
|
|
37
|
+
constructor(message: string);
|
|
38
|
+
}
|
|
39
|
+
/** Each job's block of lines in `text`, by name, in file order. */
|
|
40
|
+
export declare function jobBlocks(text: string, forge: OwnJobsForge): Map<string, string>;
|
|
41
|
+
/** The job names of a pipeline file. */
|
|
42
|
+
export declare function jobNames(text: string, forge: OwnJobsForge): string[];
|
|
43
|
+
/** The problems with `own` as a map of job name to job; `where` names it in each. */
|
|
44
|
+
export declare function ownJobsProblems(own: unknown, where: string): string[];
|
|
45
|
+
/** The map of jobs a YAML file holds. Throws {@link OwnJobsError} when it is missing, not YAML, or not a map of jobs. */
|
|
46
|
+
export declare function readOwnJobsFile(path: string, where?: string): Record<string, Record<string, unknown>>;
|
|
47
|
+
export interface MergeOwnJobsOptions {
|
|
48
|
+
/** The line above the jobs. Default {@link OWN_JOBS_LINE}. */
|
|
49
|
+
line?: string;
|
|
50
|
+
/** What the jobs are called in a refusal, such as `own_jobs` or the file's path. Default `own jobs`. */
|
|
51
|
+
where?: string;
|
|
52
|
+
/** Names the generated file's jobs take, when the caller knows them; default: read from `generated`. */
|
|
53
|
+
generatedJobs?: readonly string[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The YAML of `own`, as it goes after chant's jobs: {@link OWN_JOBS_LINE} (or
|
|
57
|
+
* `line`), then each job as it is. Empty for no jobs. Throws
|
|
58
|
+
* {@link OwnJobsError} on a name in `ours` or, on GitLab, a reserved one.
|
|
59
|
+
*/
|
|
60
|
+
export declare function ownJobsYAML(own: Record<string, unknown> | undefined, ours: readonly string[], forge: OwnJobsForge, options?: Omit<MergeOwnJobsOptions, "generatedJobs">): string;
|
|
61
|
+
/** `generated` with `own` after chant's jobs (terragucci's `own_jobs` model). Unchanged for no jobs. */
|
|
62
|
+
export declare function mergeOwnJobs(generated: string, forge: OwnJobsForge, own: Record<string, unknown> | undefined, options?: MergeOwnJobsOptions): string;
|
|
63
|
+
/** Whether a job's block runs `chant` or one of `bins`: a job chant's generator wrote. */
|
|
64
|
+
export declare function isGeneratedJob(block: string, bins?: readonly string[]): boolean;
|
|
65
|
+
export interface KeepOwnJobsOptions {
|
|
66
|
+
/** The product's bin, such as `npx --no-install plywood`: a job that runs it is generated. `chant` always counts. */
|
|
67
|
+
bins?: readonly string[];
|
|
68
|
+
/** The line above the kept jobs. Default {@link OWN_JOBS_LINE}. */
|
|
69
|
+
line?: string;
|
|
70
|
+
}
|
|
71
|
+
/** The jobs of `previous` that `generated` lacks and that run neither `chant` nor a bin of `bins`. */
|
|
72
|
+
export declare function ownJobsOf(previous: string, generated: string, forge: OwnJobsForge, bins?: readonly string[]): Map<string, string>;
|
|
73
|
+
/**
|
|
74
|
+
* The old file's own jobs carried into the new one (plywood's model):
|
|
75
|
+
* `previous` undefined means there was no file. `kept` names them.
|
|
76
|
+
*/
|
|
77
|
+
export declare function keepOwnJobs(previous: string | undefined, generated: string, forge: OwnJobsForge, options?: KeepOwnJobsOptions): {
|
|
78
|
+
text: string;
|
|
79
|
+
kept: string[];
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=ci-own-jobs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ci-own-jobs.d.ts","sourceRoot":"","sources":["../src/ci-own-jobs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,kJAAkJ;AAClJ,eAAO,MAAM,cAAc,aAAe,CAAC;AAE3C,qDAAqD;AACrD,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAC3D,eAAO,MAAM,eAAe,EAAE,SAAS,YAAY,EAAoC,CAAC;AAExF,+EAA+E;AAC/E,eAAO,MAAM,aAAa,yEAAyE,CAAC;AAEpG,kFAAkF;AAClF,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAAqI,CAAC;AAEvL,mHAAmH;AACnH,eAAO,MAAM,yBAAyB,EAAE,SAAS,MAAM,EAAsC,CAAC;AAE9F,0DAA0D;AAC1D,eAAO,MAAM,YAAY,QAA8B,CAAC;AAExD,6FAA6F;AAC7F,qBAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAkBD,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CA4ChF;AAED,wCAAwC;AACxC,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,MAAM,EAAE,CAEpE;AAsBD,qFAAqF;AACrF,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAQrE;AAED,yHAAyH;AACzH,wBAAgB,eAAe,CAAC,I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AQ,EAAE,MAAM,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,GAAE,kBAAuB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAIpK"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A repository's own jobs in a pipeline file chant generates (#4769).
|
|
3
|
+
*
|
|
4
|
+
* chant's generators write the whole file, so a job a repository adds by
|
|
5
|
+
* hand is gone at the next `chant build`. Two ways keep it:
|
|
6
|
+
*
|
|
7
|
+
* - a jobs file, or a map of jobs, merged after chant's jobs
|
|
8
|
+
* ({@link mergeOwnJobs}, `chant build --own-jobs <file>`). The file is in
|
|
9
|
+
* the forge's own syntax: a map of job name to job. A name chant's file
|
|
10
|
+
* already gives a job is refused, and on GitLab a top-level keyword too.
|
|
11
|
+
* terragucci's `own_jobs` works this way.
|
|
12
|
+
* - the jobs of the old file that the new one lacks, put back as they were
|
|
13
|
+
* written, comments and all ({@link keepOwnJobs}, `chant build
|
|
14
|
+
* --keep-own-jobs`). A job that runs `chant` or the product's bin counts as
|
|
15
|
+
* generated and is not kept. plywood's `init` and `ci` work this way.
|
|
16
|
+
*
|
|
17
|
+
* Either way the jobs go after chant's, under one comment line: inside
|
|
18
|
+
* `jobs:` at two spaces on GitHub and Forgejo, and at the top level on
|
|
19
|
+
* GitLab. The blocks are read as text by their indentation, so a kept job
|
|
20
|
+
* keeps its formatting. A file with no own jobs is returned unchanged.
|
|
21
|
+
*/
|
|
22
|
+
import { readFileSync } from "node:fs";
|
|
23
|
+
import { emitYAMLEntry, parseYAMLDocument } from "./yaml.js";
|
|
24
|
+
import { NEXT_RELEASE } from "./release-floors.js";
|
|
25
|
+
/** The first chant with `mergeOwnJobs`, `keepOwnJobs` and `chant build --own-jobs` / `--keep-own-jobs` (#4769). Products feature-detect on it. */
|
|
26
|
+
export const OWN_JOBS_FLOOR = NEXT_RELEASE;
|
|
27
|
+
export const OWN_JOBS_FORGES = ["github", "gitlab", "forgejo"];
|
|
28
|
+
/** The default line above the own jobs. A product passes its own as `line`. */
|
|
29
|
+
export const OWN_JOBS_LINE = "# Your own jobs, kept as they are when chant writes this file again.";
|
|
30
|
+
/** GitLab's top-level keys that are not jobs: never read as a job, never kept. */
|
|
31
|
+
export const GITLAB_TOP_KEYWORDS = ["default", "include", "stages", "variables", "workflow", "image", "services", "cache", "before_script", "after_script", "spec"];
|
|
32
|
+
/** The names an own job may not take on GitLab: the keywords, and `pages`, which GitLab reads as its Pages job. */
|
|
33
|
+
export const GITLAB_RESERVED_JOB_NAMES = [...GITLAB_TOP_KEYWORDS, "pages"];
|
|
34
|
+
/** A job name every forge's YAML reads as a plain key. */
|
|
35
|
+
export const OWN_JOB_NAME = /^[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
36
|
+
/** An own job refused: a collision, a reserved name, or a file that is not a map of jobs. */
|
|
37
|
+
export class OwnJobsError extends Error {
|
|
38
|
+
constructor(message) {
|
|
39
|
+
super(message);
|
|
40
|
+
this.name = "OwnJobsError";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const KEY = /^([A-Za-z0-9_.-]+|"[^"]+"|'[^']+'):(\s|$)/;
|
|
44
|
+
const JOBS_LINE = /^jobs:\s*(#.*)?$/;
|
|
45
|
+
function indentOf(line) {
|
|
46
|
+
return line.length - line.trimStart().length;
|
|
47
|
+
}
|
|
48
|
+
function isContent(line) {
|
|
49
|
+
const t = line.trim();
|
|
50
|
+
return t !== "" && !t.startsWith("#");
|
|
51
|
+
}
|
|
52
|
+
function escapeRegExp(s) {
|
|
53
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
54
|
+
}
|
|
55
|
+
/** Each job's block of lines in `text`, by name, in file order. */
|
|
56
|
+
export function jobBlocks(text, forge) {
|
|
57
|
+
const lines = text.split("\n");
|
|
58
|
+
const out = new Map();
|
|
59
|
+
let start = 0;
|
|
60
|
+
let end = lines.length;
|
|
61
|
+
let depth = 0;
|
|
62
|
+
if (forge !== "gitlab") {
|
|
63
|
+
const at = lines.findIndex((l) => JOBS_LINE.test(l));
|
|
64
|
+
if (at < 0)
|
|
65
|
+
return out;
|
|
66
|
+
start = at + 1;
|
|
67
|
+
const next = lines.findIndex((l, i) => i > at && indentOf(l) === 0 && isContent(l));
|
|
68
|
+
end = next < 0 ? lines.length : next;
|
|
69
|
+
depth = 2;
|
|
70
|
+
}
|
|
71
|
+
let name;
|
|
72
|
+
let body = [];
|
|
73
|
+
const flush = () => {
|
|
74
|
+
if (name !== undefined) {
|
|
75
|
+
while (body.length > 0 && body[body.length - 1].trim() === "")
|
|
76
|
+
body.pop();
|
|
77
|
+
out.set(name, body.join("\n"));
|
|
78
|
+
}
|
|
79
|
+
name = undefined;
|
|
80
|
+
body = [];
|
|
81
|
+
};
|
|
82
|
+
for (let i = start; i < end; i++) {
|
|
83
|
+
const line = lines[i];
|
|
84
|
+
if (isContent(line) && indentOf(line) === depth) {
|
|
85
|
+
const m = KEY.exec(line.slice(depth));
|
|
86
|
+
flush();
|
|
87
|
+
if (m) {
|
|
88
|
+
name = m[1].replace(/^["']|["']$/g, "");
|
|
89
|
+
body = [line];
|
|
90
|
+
}
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (isContent(line) && indentOf(line) < depth) {
|
|
94
|
+
flush();
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (name !== undefined)
|
|
98
|
+
body.push(line);
|
|
99
|
+
}
|
|
100
|
+
flush();
|
|
101
|
+
if (forge === "gitlab")
|
|
102
|
+
for (const k of [...out.keys()])
|
|
103
|
+
if (GITLAB_TOP_KEYWORDS.includes(k))
|
|
104
|
+
out.delete(k);
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
/** The job names of a pipeline file. */
|
|
108
|
+
export function jobNames(text, forge) {
|
|
109
|
+
return [...jobBlocks(text, forge).keys()];
|
|
110
|
+
}
|
|
111
|
+
/** `generated` with `blocks` after chant's jobs, under `line`. */
|
|
112
|
+
function withBlocks(generated, blocks, forge, line) {
|
|
113
|
+
if (blocks.length === 0)
|
|
114
|
+
return generated;
|
|
115
|
+
const indent = forge === "gitlab" ? "" : " ";
|
|
116
|
+
const block = [`${indent}${line}`, ...blocks].join("\n");
|
|
117
|
+
const lines = generated.replace(/\n+$/, "").split("\n");
|
|
118
|
+
if (forge !== "gitlab") {
|
|
119
|
+
const at = lines.findIndex((l) => JOBS_LINE.test(l));
|
|
120
|
+
if (at >= 0) {
|
|
121
|
+
const next = lines.findIndex((l, i) => i > at && indentOf(l) === 0 && isContent(l));
|
|
122
|
+
if (next >= 0) {
|
|
123
|
+
let cut = next;
|
|
124
|
+
while (cut > at + 1 && lines[cut - 1].trim() === "")
|
|
125
|
+
cut--;
|
|
126
|
+
return [...lines.slice(0, cut), block, ...lines.slice(cut)].join("\n") + "\n";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return [...lines, block].join("\n") + "\n";
|
|
131
|
+
}
|
|
132
|
+
/** The problems with `own` as a map of job name to job; `where` names it in each. */
|
|
133
|
+
export function ownJobsProblems(own, where) {
|
|
134
|
+
if (own === null || typeof own !== "object" || Array.isArray(own))
|
|
135
|
+
return [`${where} must be a map of job name to job`];
|
|
136
|
+
const problems = [];
|
|
137
|
+
for (const [name, job] of Object.entries(own)) {
|
|
138
|
+
if (!OWN_JOB_NAME.test(name))
|
|
139
|
+
problems.push(`${where}: ${JSON.stringify(name)} is not a job name; use letters, digits, "_" and "-"`);
|
|
140
|
+
else if (job === null || typeof job !== "object" || Array.isArray(job) || Object.keys(job).length === 0)
|
|
141
|
+
problems.push(`${where}.${name} must be a job: a map of its keys, in the forge's own syntax`);
|
|
142
|
+
}
|
|
143
|
+
return problems;
|
|
144
|
+
}
|
|
145
|
+
/** The map of jobs a YAML file holds. Throws {@link OwnJobsError} when it is missing, not YAML, or not a map of jobs. */
|
|
146
|
+
export function readOwnJobsFile(path, where = path) {
|
|
147
|
+
let text;
|
|
148
|
+
try {
|
|
149
|
+
text = readFileSync(path, "utf-8");
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
throw new OwnJobsError(`${where}: no such file`);
|
|
153
|
+
}
|
|
154
|
+
let doc;
|
|
155
|
+
try {
|
|
156
|
+
doc = parseYAMLDocument(text);
|
|
157
|
+
}
|
|
158
|
+
catch (e) {
|
|
159
|
+
throw new OwnJobsError(`${where} is not YAML (${e.message})`);
|
|
160
|
+
}
|
|
161
|
+
const problems = ownJobsProblems(doc, where);
|
|
162
|
+
if (problems.length > 0)
|
|
163
|
+
throw new OwnJobsError(problems.join("; "));
|
|
164
|
+
return doc;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The YAML of `own`, as it goes after chant's jobs: {@link OWN_JOBS_LINE} (or
|
|
168
|
+
* `line`), then each job as it is. Empty for no jobs. Throws
|
|
169
|
+
* {@link OwnJobsError} on a name in `ours` or, on GitLab, a reserved one.
|
|
170
|
+
*/
|
|
171
|
+
export function ownJobsYAML(own, ours, forge, options = {}) {
|
|
172
|
+
if (!own || Object.keys(own).length === 0)
|
|
173
|
+
return "";
|
|
174
|
+
const where = options.where ?? "own jobs";
|
|
175
|
+
const problems = ownJobsProblems(own, where);
|
|
176
|
+
if (problems.length > 0)
|
|
177
|
+
throw new OwnJobsError(problems.join("; "));
|
|
178
|
+
for (const name of Object.keys(own)) {
|
|
179
|
+
if (ours.includes(name))
|
|
180
|
+
throw new OwnJobsError(`${where}.${name}: chant's file has a job of that name; give yours another`);
|
|
181
|
+
if (forge === "gitlab" && GITLAB_RESERVED_JOB_NAMES.includes(name))
|
|
182
|
+
throw new OwnJobsError(`${where}.${name}: GitLab reads ${name} as a keyword, not a job; give yours another name`);
|
|
183
|
+
}
|
|
184
|
+
const indent = forge === "gitlab" ? 0 : 1;
|
|
185
|
+
return [`${forge === "gitlab" ? "" : " "}${options.line ?? OWN_JOBS_LINE}`, ...Object.entries(own).map(([name, job]) => emitYAMLEntry(name, job, indent))].join("\n") + "\n";
|
|
186
|
+
}
|
|
187
|
+
/** `generated` with `own` after chant's jobs (terragucci's `own_jobs` model). Unchanged for no jobs. */
|
|
188
|
+
export function mergeOwnJobs(generated, forge, own, options = {}) {
|
|
189
|
+
if (!own || Object.keys(own).length === 0)
|
|
190
|
+
return generated;
|
|
191
|
+
const ours = options.generatedJobs ?? jobNames(generated, forge);
|
|
192
|
+
const rendered = ownJobsYAML(own, ours, forge, options).replace(/\n$/, "");
|
|
193
|
+
const [line, ...rest] = rendered.split("\n");
|
|
194
|
+
// The rendered text starts with the indented line; withBlocks adds the indent itself.
|
|
195
|
+
return withBlocks(generated, [rest.join("\n")], forge, line.trimStart());
|
|
196
|
+
}
|
|
197
|
+
/** The bins whose lines mark a job as generated: `chant`, and each of `bins` with its last word (`npx --no-install plywood` and `plywood`). */
|
|
198
|
+
function generatedLine(bins) {
|
|
199
|
+
const names = new Set(["chant"]);
|
|
200
|
+
for (const bin of bins) {
|
|
201
|
+
const b = bin.trim();
|
|
202
|
+
if (b === "")
|
|
203
|
+
continue;
|
|
204
|
+
names.add(b);
|
|
205
|
+
names.add(b.split(/\s+/).pop().split("/").pop());
|
|
206
|
+
}
|
|
207
|
+
const alt = [...names].sort((a, b) => b.length - a.length).map(escapeRegExp).join("|");
|
|
208
|
+
return new RegExp(`(^|[\\s"'(]|\\$\\()(?:${alt}) (?=[a-z])`, "m");
|
|
209
|
+
}
|
|
210
|
+
/** Whether a job's block runs `chant` or one of `bins`: a job chant's generator wrote. */
|
|
211
|
+
export function isGeneratedJob(block, bins = []) {
|
|
212
|
+
return generatedLine(bins).test(block);
|
|
213
|
+
}
|
|
214
|
+
/** The jobs of `previous` that `generated` lacks and that run neither `chant` nor a bin of `bins`. */
|
|
215
|
+
export function ownJobsOf(previous, generated, forge, bins = []) {
|
|
216
|
+
const ours = jobBlocks(generated, forge);
|
|
217
|
+
const out = new Map();
|
|
218
|
+
for (const [name, block] of jobBlocks(previous, forge)) {
|
|
219
|
+
if (ours.has(name) || isGeneratedJob(block, bins))
|
|
220
|
+
continue;
|
|
221
|
+
out.set(name, block);
|
|
222
|
+
}
|
|
223
|
+
return out;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* The old file's own jobs carried into the new one (plywood's model):
|
|
227
|
+
* `previous` undefined means there was no file. `kept` names them.
|
|
228
|
+
*/
|
|
229
|
+
export function keepOwnJobs(previous, generated, forge, options = {}) {
|
|
230
|
+
if (previous === undefined)
|
|
231
|
+
return { text: generated, kept: [] };
|
|
232
|
+
const own = ownJobsOf(previous, generated, forge, options.bins ?? []);
|
|
233
|
+
return { text: withBlocks(generated, [...own.values()], forge, options.line ?? OWN_JOBS_LINE), kept: [...own.keys()] };
|
|
234
|
+
}
|
package/dist/ci-product.d.ts
CHANGED
|
@@ -79,6 +79,36 @@ export declare const CI_RESPOND_FLOOR = "0.124.56";
|
|
|
79
79
|
* its pull request jobs with the build feature-detects on this floor.
|
|
80
80
|
*/
|
|
81
81
|
export declare const PR_LOOP_BUILD_FLAGS_FLOOR = "0.124.56";
|
|
82
|
+
/**
|
|
83
|
+
* A repository's own jobs in the generated pipeline file (#4769):
|
|
84
|
+
* `mergeOwnJobs` adds a map of jobs (or `readOwnJobsFile`'s) after chant's
|
|
85
|
+
* and refuses a name chant's file has or a GitLab keyword; `keepOwnJobs`
|
|
86
|
+
* carries over the old file's jobs that run neither `chant` nor the
|
|
87
|
+
* product's bin. `chant build --components --generate <forge> --own-jobs
|
|
88
|
+
* <file>` and `--keep-own-jobs` do the same on the build line. A product
|
|
89
|
+
* feature-detects on `OWN_JOBS_FLOOR`.
|
|
90
|
+
*/
|
|
91
|
+
export { GITLAB_RESERVED_JOB_NAMES, GITLAB_TOP_KEYWORDS, isGeneratedJob, jobBlocks, jobNames, keepOwnJobs, mergeOwnJobs, OWN_JOB_NAME, OWN_JOBS_FLOOR, OWN_JOBS_FORGES, OWN_JOBS_LINE, OwnJobsError, ownJobsOf, ownJobsProblems, ownJobsYAML, readOwnJobsFile, type KeepOwnJobsOptions, type MergeOwnJobsOptions, type OwnJobsForge, } from "./ci-own-jobs.js";
|
|
92
|
+
/**
|
|
93
|
+
* The Forgejo generators write a workflow-level run group a product asks for
|
|
94
|
+
* (#4771): `runGroup: "pull-request"` on the components pipeline (`chant
|
|
95
|
+
* build --components --generate forgejo --run-group pull-request`) and
|
|
96
|
+
* `runGroup: "commit"` on an op waves spec (its `options`, or `chant run
|
|
97
|
+
* --generate forgejo --spec <file> --run-group commit`). A workflow with a
|
|
98
|
+
* group of its own keeps it, and GitHub and GitLab files are unchanged. A
|
|
99
|
+
* product feature-detects on this floor.
|
|
100
|
+
*/
|
|
101
|
+
export declare const FORGEJO_RUN_GROUP_FLOOR = "0.124.77";
|
|
102
|
+
export { RUN_GROUP_KEYS, type RunGroupKey } from "./lexicon.js";
|
|
103
|
+
/**
|
|
104
|
+
* `chant build --pr-loop` takes the control repo (#4772): `--control <repo>`
|
|
105
|
+
* and `--control-setting <key>=<value>` (op, member, readTokenSecret, and
|
|
106
|
+
* the rest of the control settings) are the pull request loop's `control`,
|
|
107
|
+
* so the note job the build writes reads the control repo's records itself,
|
|
108
|
+
* the step `productPipelineJobs(...).post.control` returns. A product that
|
|
109
|
+
* writes its pipeline with the build feature-detects on this floor.
|
|
110
|
+
*/
|
|
111
|
+
export declare const PR_LOOP_CONTROL_FLOOR = "0.124.77";
|
|
82
112
|
export { CI_RESPOND_DEFAULTS, CI_RESPOND_ENV, CI_RESPONSES, parseRespondList, renderRefusedDiff, renderTriage, respondList, resolveResponses, type CiRespondEvent, type CiResponses, type DescriptionFinding, type FailedApply, type RefusedDiff, } from "./ci-respond.js";
|
|
83
113
|
export { respondDescription, respondOpWave, respondPrApply, triageOfOpWave, triageOfPrReport, refusedOfOpWave, refusedOfPrReport } from "./ci-respond-run.js";
|
|
84
114
|
/**
|
|
@@ -98,6 +128,15 @@ export declare function runChantInProcess(argv: string[], words: CiProductWordsI
|
|
|
98
128
|
* `CI_AGENT_FLOOR`.
|
|
99
129
|
*/
|
|
100
130
|
export { CI_AGENT_FLOOR, agentForbiddenPaths, type AgentSettings, type OpAgentSpec } from "./ci-agent.js";
|
|
131
|
+
/**
|
|
132
|
+
* The agent guard (#4770): a Claude Code PreToolUse hook on Bash and a
|
|
133
|
+
* wrapper per engine binary that refuse an agent's apply, approve or
|
|
134
|
+
* override. A product passes its words (its name, the refusal) and rules
|
|
135
|
+
* (engines, their refused subcommands and flags, its own refused commands)
|
|
136
|
+
* to `installAgentGuard`, and `agentGuard` checks a command line in process
|
|
137
|
+
* with the same rule. Feature-detect on `AGENT_GUARD_FLOOR`.
|
|
138
|
+
*/
|
|
139
|
+
export { AGENT_GUARD_FLOOR, agentGuard, agentGuardScript, agentGuardWrapper, CLAUDE_SETTINGS_LOCAL, CLAUDE_SETTINGS_SHARED, installAgentGuard, withAgentGuardHook, type AgentGuard, type AgentGuardEngine, type AgentGuardInstall, type AgentGuardInstallOptions, type AgentGuardRules, type AgentGuardSpec, type AgentGuardVerdict, type AgentGuardWords, } from "./agent-guard.js";
|
|
101
140
|
/**
|
|
102
141
|
* After-plan hooks in a wave job's process (#4614): `runChantInProcess(["run",
|
|
103
142
|
* "wave", ...], words, { wave: { afterPlan, capabilities } })`, or
|
package/dist/ci-product.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ci-product.d.ts","sourceRoot":"","sources":["../src/ci-product.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"ci-product.d.ts","sourceRoot":"","sources":["../src/ci-product.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mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EACL,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,YAAY,GAClB,MAAM,QAAQ,CAAC"}
|
package/dist/ci-product.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* and `assertProductWords` present means the rest is too.
|
|
10
10
|
*/
|
|
11
11
|
import { OTLP_EXPORTER_FLOOR } from "./otlp.js";
|
|
12
|
+
import { NEXT_RELEASE } from "./release-floors.js";
|
|
12
13
|
/**
|
|
13
14
|
* The first chant with the product pipeline (#4550): the words, the
|
|
14
15
|
* `pull-request` op-wave approval source, `runCommandInProcess(argv, {
|
|
@@ -77,6 +78,36 @@ export const CI_RESPOND_FLOOR = "0.124.56";
|
|
|
77
78
|
* its pull request jobs with the build feature-detects on this floor.
|
|
78
79
|
*/
|
|
79
80
|
export const PR_LOOP_BUILD_FLAGS_FLOOR = "0.124.56";
|
|
81
|
+
/**
|
|
82
|
+
* A repository's own jobs in the generated pipeline file (#4769):
|
|
83
|
+
* `mergeOwnJobs` adds a map of jobs (or `readOwnJobsFile`'s) after chant's
|
|
84
|
+
* and refuses a name chant's file has or a GitLab keyword; `keepOwnJobs`
|
|
85
|
+
* carries over the old file's jobs that run neither `chant` nor the
|
|
86
|
+
* product's bin. `chant build --components --generate <forge> --own-jobs
|
|
87
|
+
* <file>` and `--keep-own-jobs` do the same on the build line. A product
|
|
88
|
+
* feature-detects on `OWN_JOBS_FLOOR`.
|
|
89
|
+
*/
|
|
90
|
+
export { GITLAB_RESERVED_JOB_NAMES, GITLAB_TOP_KEYWORDS, isGeneratedJob, jobBlocks, jobNames, keepOwnJobs, mergeOwnJobs, OWN_JOB_NAME, OWN_JOBS_FLOOR, OWN_JOBS_FORGES, OWN_JOBS_LINE, OwnJobsError, ownJobsOf, ownJobsProblems, ownJobsYAML, readOwnJobsFile, } from "./ci-own-jobs.js";
|
|
91
|
+
/**
|
|
92
|
+
* The Forgejo generators write a workflow-level run group a product asks for
|
|
93
|
+
* (#4771): `runGroup: "pull-request"` on the components pipeline (`chant
|
|
94
|
+
* build --components --generate forgejo --run-group pull-request`) and
|
|
95
|
+
* `runGroup: "commit"` on an op waves spec (its `options`, or `chant run
|
|
96
|
+
* --generate forgejo --spec <file> --run-group commit`). A workflow with a
|
|
97
|
+
* group of its own keeps it, and GitHub and GitLab files are unchanged. A
|
|
98
|
+
* product feature-detects on this floor.
|
|
99
|
+
*/
|
|
100
|
+
export const FORGEJO_RUN_GROUP_FLOOR = NEXT_RELEASE;
|
|
101
|
+
export { RUN_GROUP_KEYS } from "./lexicon.js";
|
|
102
|
+
/**
|
|
103
|
+
* `chant build --pr-loop` takes the control repo (#4772): `--control <repo>`
|
|
104
|
+
* and `--control-setting <key>=<value>` (op, member, readTokenSecret, and
|
|
105
|
+
* the rest of the control settings) are the pull request loop's `control`,
|
|
106
|
+
* so the note job the build writes reads the control repo's records itself,
|
|
107
|
+
* the step `productPipelineJobs(...).post.control` returns. A product that
|
|
108
|
+
* writes its pipeline with the build feature-detects on this floor.
|
|
109
|
+
*/
|
|
110
|
+
export const PR_LOOP_CONTROL_FLOOR = NEXT_RELEASE;
|
|
80
111
|
export { CI_RESPOND_DEFAULTS, CI_RESPOND_ENV, CI_RESPONSES, parseRespondList, renderRefusedDiff, renderTriage, respondList, resolveResponses, } from "./ci-respond.js";
|
|
81
112
|
export { respondDescription, respondOpWave, respondPrApply, triageOfOpWave, triageOfPrReport, refusedOfOpWave, refusedOfPrReport } from "./ci-respond-run.js";
|
|
82
113
|
/**
|
|
@@ -96,6 +127,15 @@ export async function runChantInProcess(argv, words, options = {}) {
|
|
|
96
127
|
* `CI_AGENT_FLOOR`.
|
|
97
128
|
*/
|
|
98
129
|
export { CI_AGENT_FLOOR, agentForbiddenPaths } from "./ci-agent.js";
|
|
130
|
+
/**
|
|
131
|
+
* The agent guard (#4770): a Claude Code PreToolUse hook on Bash and a
|
|
132
|
+
* wrapper per engine binary that refuse an agent's apply, approve or
|
|
133
|
+
* override. A product passes its words (its name, the refusal) and rules
|
|
134
|
+
* (engines, their refused subcommands and flags, its own refused commands)
|
|
135
|
+
* to `installAgentGuard`, and `agentGuard` checks a command line in process
|
|
136
|
+
* with the same rule. Feature-detect on `AGENT_GUARD_FLOOR`.
|
|
137
|
+
*/
|
|
138
|
+
export { AGENT_GUARD_FLOOR, agentGuard, agentGuardScript, agentGuardWrapper, CLAUDE_SETTINGS_LOCAL, CLAUDE_SETTINGS_SHARED, installAgentGuard, withAgentGuardHook, } from "./agent-guard.js";
|
|
99
139
|
/**
|
|
100
140
|
* After-plan hooks in a wave job's process (#4614): `runChantInProcess(["run",
|
|
101
141
|
* "wave", ...], words, { wave: { afterPlan, capabilities } })`, or
|
|
@@ -79,7 +79,11 @@ export interface GateApprovalOptions {
|
|
|
79
79
|
* `--statement` and `--signature`.
|
|
80
80
|
*/
|
|
81
81
|
binding?: string;
|
|
82
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* The repository the approval is for: its ops, its workspace and key file,
|
|
84
|
+
* and its `chant/lifecycle`, which is read, appended to and pushed (#4760).
|
|
85
|
+
* Defaults to the process's directory.
|
|
86
|
+
*/
|
|
83
87
|
cwd?: string;
|
|
84
88
|
/** Replaces the lexicon evaluator a gate policy is loaded from. For tests. */
|
|
85
89
|
evaluator?: GatePolicyEvaluator;
|