@intentius/chant 0.124.71 → 0.124.73

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.
Files changed (58) hide show
  1. package/dist/ci-commit.d.ts +41 -1
  2. package/dist/ci-commit.d.ts.map +1 -1
  3. package/dist/ci-commit.js +54 -8
  4. package/dist/ci-estate/delivery.d.ts +75 -2
  5. package/dist/ci-estate/delivery.d.ts.map +1 -1
  6. package/dist/ci-estate/delivery.js +129 -0
  7. package/dist/ci-estate.d.ts +3 -1
  8. package/dist/ci-estate.d.ts.map +1 -1
  9. package/dist/ci-estate.js +3 -1
  10. package/dist/ci-product.d.ts +1 -1
  11. package/dist/ci-product.d.ts.map +1 -1
  12. package/dist/ci-product.js +1 -1
  13. package/dist/cli/handlers/commit.d.ts.map +1 -1
  14. package/dist/cli/handlers/commit.js +5 -2
  15. package/dist/cli/handlers/notify-relay.d.ts.map +1 -1
  16. package/dist/cli/handlers/notify-relay.js +22 -2
  17. package/dist/config.d.ts +14 -0
  18. package/dist/config.d.ts.map +1 -1
  19. package/dist/config.js +7 -0
  20. package/dist/lexicon.d.ts +17 -0
  21. package/dist/lexicon.d.ts.map +1 -1
  22. package/dist/lifecycle/publish-forge.d.ts.map +1 -1
  23. package/dist/lifecycle/publish-forge.js +1 -2
  24. package/dist/lifecycle/release-images.d.ts.map +1 -1
  25. package/dist/lifecycle/release-images.js +1 -2
  26. package/dist/notify-relay.d.ts +41 -1
  27. package/dist/notify-relay.d.ts.map +1 -1
  28. package/dist/notify-relay.js +39 -0
  29. package/dist/notify.d.ts +16 -3
  30. package/dist/notify.d.ts.map +1 -1
  31. package/dist/notify.js +16 -10
  32. package/dist/op/activities/activity-contracts.d.ts +4 -4
  33. package/dist/release-floors.d.ts +1 -1
  34. package/dist/release-floors.js +1 -1
  35. package/dist/wave-runtime.mjs +237 -237
  36. package/dist/workspace/release-workflow.d.ts +24 -0
  37. package/dist/workspace/release-workflow.d.ts.map +1 -1
  38. package/dist/workspace/release-workflow.js +61 -8
  39. package/package.json +1 -1
  40. package/src/ci-commit.test.ts +22 -1
  41. package/src/ci-commit.ts +79 -8
  42. package/src/ci-estate/__fixtures__/terragucci-dora.json +1305 -0
  43. package/src/ci-estate/delivery.ts +186 -2
  44. package/src/ci-estate/records-delivery.test.ts +55 -0
  45. package/src/ci-estate.ts +9 -0
  46. package/src/ci-product.ts +1 -0
  47. package/src/cli/handlers/commit.ts +4 -1
  48. package/src/cli/handlers/notify-relay.ts +21 -2
  49. package/src/config.ts +7 -0
  50. package/src/lexicon.ts +16 -0
  51. package/src/lifecycle/publish-forge.ts +1 -2
  52. package/src/lifecycle/release-images.ts +1 -2
  53. package/src/notify-relay.test.ts +55 -1
  54. package/src/notify-relay.ts +48 -1
  55. package/src/notify.ts +25 -12
  56. package/src/release-floors.ts +1 -1
  57. package/src/workspace/release-workflow.test.ts +49 -1
  58. package/src/workspace/release-workflow.ts +91 -7
@@ -1,4 +1,5 @@
1
1
  import type { SecurityGroup } from "./security.js";
2
+ import type { OpSetupStep } from "../lexicon.js";
2
3
  export declare const RELEASE_WORKFLOW_FORGES: readonly ["github", "forgejo", "gitlab"];
3
4
  export type ReleaseWorkflowForge = (typeof RELEASE_WORKFLOW_FORGES)[number];
4
5
  /** Where each forge's publish workflow is written, relative to the repository root. */
@@ -17,6 +18,29 @@ export interface ReleasePipelineConfig {
17
18
  chant?: string;
18
19
  /** Shell lines run after the publish, with `CHANT_RELEASE_LABEL` set: steps that need a published release. */
19
20
  after?: string[];
21
+ /**
22
+ * Scopes added to the workflow's `contents: write` and `id-token: write`
23
+ * (#4751), such as `{ packages: "write" }` for an `oci` target that pushes to
24
+ * GHCR with the run's token. A scope already granted is refused. GitHub and
25
+ * Forgejo only; GitLab has no `permissions:` and refuses it by name.
26
+ */
27
+ permissions?: Record<string, "read" | "write">;
28
+ /**
29
+ * Variables for the cut and publish jobs (#4751), such as an `oci` target's
30
+ * `OCI_USERNAME: "${{ github.actor }}"` and `OCI_PASSWORD: "${{ github.token }}"`.
31
+ * A value may be a forge expression: it goes in the job's `env:` (GitLab:
32
+ * `variables:`), never on a `run:` line.
33
+ */
34
+ env?: Record<string, string>;
35
+ /**
36
+ * Steps the cut and publish jobs run after the install (#4751): `{ run }`,
37
+ * or `{ uses, with }` on GitHub and Forgejo, such as QEMU's binfmt handlers
38
+ * for a two-platform image build, or a newer npm. GitLab takes `run` steps
39
+ * as script lines and refuses `uses` by name.
40
+ */
41
+ setup?: OpSetupStep[];
42
+ /** Where the workflow is written, from the repository root, such as `.github/workflows/publish.yml` for an npm trusted publisher that names that file. Default {@link RELEASE_WORKFLOW_FILES}. */
43
+ file?: string;
20
44
  }
21
45
  export interface ReleaseWorkflowInput {
22
46
  forge: ReleaseWorkflowForge;
@@ -1 +1 @@
1
- {"version":3,"file":"release-workflow.d.ts","sourceRoot":"","sources":["../../src/workspace/release-workflow.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,eAAO,MAAM,uBAAuB,YAAI,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAU,CAAC;AAChF,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5E,uFAAuF;AACvF,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,oBAAoB,EAAE,MAAM,CAKvE,CAAC;AAEF,yGAAyG;AACzG,MAAM,WAAW,qBAAqB;IACpC,8HAA8H;IAC9H,OAAO,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC;IAC7B,iLAAiL;IACjL,IAAI,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;IAC7B,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yJAAyJ;IACzJ,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8GAA8G;I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ACvB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IACjC,6FAA6F;IAC7F,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,+DAA+D;AAC/D,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,aAAa,CAAC,GAAG,MAAM,EAAE,CAEzE;AAED,6FAA6F;AAC7F,eAAO,MAAM,oBAAoB,gCAAgC,CAAC;AAOlE,iEAAiE;AACjE,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CA8FzE;AAkOD,wFAAwF;AACxF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,OAAO,iBAAiB,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CA6DvG"}
@@ -58,8 +58,9 @@ export function renderReleaseWorkflow(input) {
58
58
  const flags = publishFlags(input.groups).join(" ");
59
59
  const after = p.after ?? [];
60
60
  const images = input.images === true;
61
+ const extra = jobExtras(p, input.forge);
61
62
  if (p.trigger === "dispatch") {
62
- const o = { chant, install, build, root, verify, flags, after, images, gate: p.gate ?? "last-green", ...(input.lane ? { lane: input.lane } : {}) };
63
+ const o = { chant, install, build, root, verify, flags, after, images, extra, gate: p.gate ?? "last-green", ...(input.lane ? { lane: input.lane } : {}) };
63
64
  return input.forge === "gitlab" ? renderGitlabDispatch(o) : renderGithubDispatch(o);
64
65
  }
65
66
  // #4657: the images are built from the release, so chant/lifecycle is fetched before them and the build after.
@@ -74,9 +75,11 @@ export function renderReleaseWorkflow(input) {
74
75
  " id_tokens:",
75
76
  " SIGSTORE_ID_TOKEN:",
76
77
  " aud: sigstore",
78
+ ...(extra.gitlabVariables.length > 0 ? [" variables:", ...extra.gitlabVariables] : []),
77
79
  " script:",
78
80
  ...(root ? [` - cd ${root}`] : []),
79
81
  ` - ${install}`,
82
+ ...extra.gitlabScript.map((l) => ` - ${l}`),
80
83
  ...(images ? [...fetches, ...imageLines(label, `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`).map((l) => ` - ${l}`)] : []),
81
84
  ...(build ? [` - ${build}`] : []),
82
85
  ...(images ? [] : fetches),
@@ -98,13 +101,16 @@ export function renderReleaseWorkflow(input) {
98
101
  "permissions:",
99
102
  " contents: write",
100
103
  " id-token: write",
104
+ ...extra.permissions,
101
105
  "jobs:",
102
106
  " publish:",
103
107
  " runs-on: ubuntu-latest",
104
108
  ...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []),
109
+ ...extra.githubEnv([]),
105
110
  " steps:",
106
111
  ...githubSetup(),
107
112
  ` - run: ${install}`,
113
+ ...extra.githubSteps,
108
114
  ...(images ? [...fetches, ...imageLines(label, `echo "CHANT_RELEASE_DIGESTS=$PWD/${RELEASE_DIGESTS_FILE}" >> "$GITHUB_ENV"`).map((l) => ` - run: ${l}`)] : []),
109
115
  ...(build ? [` - run: ${build}`] : []),
110
116
  ...(images ? [] : fetches),
@@ -116,6 +122,48 @@ export function renderReleaseWorkflow(input) {
116
122
  }
117
123
  return tagComments(`${lines.join("\n")}\n`);
118
124
  }
125
+ /** `release.workflow`'s `permissions`, `env` and `setup` (#4751) as lines of the forge's file. Empty for a config without them, so its file is what it was. */
126
+ function jobExtras(p, forge) {
127
+ const permissions = Object.entries(p.permissions ?? {});
128
+ const env = Object.entries(p.env ?? {});
129
+ const setup = p.setup ?? [];
130
+ const where = "release.workflow";
131
+ for (const [k, v] of env)
132
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(k) || typeof v !== "string")
133
+ throw new Error(`${where}.env: ${JSON.stringify(k)} is not a variable name with a string value`);
134
+ if (forge === "gitlab") {
135
+ if (permissions.length > 0)
136
+ throw new Error(`${where}.permissions: GitLab has no permissions: block; a GitLab job's token scopes are the project's`);
137
+ const uses = setup.find((s) => "uses" in s);
138
+ if (uses)
139
+ throw new Error(`${where}.setup: "${uses.uses}" is an action, and a GitLab job runs script lines; give it as { run }`);
140
+ }
141
+ else {
142
+ for (const [k, v] of permissions) {
143
+ if (k === "contents" || k === "id-token")
144
+ throw new Error(`${where}.permissions: ${k} is already granted (contents: write, id-token: write)`);
145
+ if (!/^[a-z][a-z-]*$/.test(k) || (v !== "read" && v !== "write"))
146
+ throw new Error(`${where}.permissions: ${k}: ${String(v)} is not a scope and read or write`);
147
+ }
148
+ for (const s of setup)
149
+ if (!("uses" in s) && s.run.trim() === "")
150
+ throw new Error(`${where}.setup: a run step is empty`);
151
+ }
152
+ const q = (v) => JSON.stringify(v);
153
+ const map = (indent, entries) => entries.map(([k, v]) => `${indent}${k}: ${q(v)}`);
154
+ const githubSteps = setup.flatMap((s) => [
155
+ "uses" in s ? ` - uses: ${s.uses}` : ` - run: ${q(s.run)}`,
156
+ ...("uses" in s && s.with && Object.keys(s.with).length > 0 ? [" with:", ...map(" ", Object.entries(s.with))] : []),
157
+ ...(s.env && Object.keys(s.env).length > 0 ? [" env:", ...map(" ", Object.entries(s.env))] : []),
158
+ ]);
159
+ return {
160
+ permissions: permissions.map(([k, v]) => ` ${k}: ${v}`),
161
+ githubEnv: (base) => (base.length + env.length > 0 ? [" env:", ...base, ...map(" ", env)] : []),
162
+ githubSteps,
163
+ gitlabVariables: map(" ", env),
164
+ gitlabScript: setup.flatMap((s) => ("uses" in s ? [] : [...Object.entries(s.env ?? {}).map(([k, v]) => `export ${k}=${q(v)}`), s.run])),
165
+ };
166
+ }
119
167
  /** The checkout and node setup a GitHub or Forgejo job starts with; `ref` checks out that commit. */
120
168
  function githubSetup(ref) {
121
169
  return [
@@ -167,6 +215,7 @@ function renderGithubDispatch(o) {
167
215
  "permissions:",
168
216
  " contents: write",
169
217
  " id-token: write",
218
+ ...o.extra.permissions,
170
219
  "concurrency:",
171
220
  " group: chant-release",
172
221
  " cancel-in-progress: false",
@@ -189,20 +238,22 @@ function renderGithubDispatch(o) {
189
238
  " needs: gate",
190
239
  " runs-on: ubuntu-latest",
191
240
  ...defaults,
192
- " env:",
193
- ` CHANT_RELEASE_COMMIT: ${commit}`,
241
+ ...o.extra.githubEnv([` CHANT_RELEASE_COMMIT: ${commit}`]),
194
242
  " steps:",
195
243
  ...githubSetup(commit),
196
244
  ` - run: ${o.install}`,
245
+ ...o.extra.githubSteps,
197
246
  ...fetches,
198
247
  ...block(cutScript(o, '"$RUNNER_TEMP/chant-cut.json"')),
199
248
  " publish:",
200
249
  " needs: [gate, cut]",
201
250
  " runs-on: ubuntu-latest",
202
251
  ...defaults,
252
+ ...o.extra.githubEnv([]),
203
253
  " steps:",
204
254
  ...githubSetup(commit),
205
255
  ` - run: ${o.install}`,
256
+ ...o.extra.githubSteps,
206
257
  ...fetches,
207
258
  ...(o.images ? [` - run: ${o.chant} release images "$CHANT_RELEASE_LABEL" -o ${RELEASE_DIGESTS_FILE}`, ` - run: echo "CHANT_RELEASE_DIGESTS=$PWD/${RELEASE_DIGESTS_FILE}" >> "$GITHUB_ENV"`] : []),
208
259
  ...(o.build ? [` - run: ${o.build}`] : []),
@@ -229,12 +280,13 @@ function renderGitlabDispatch(o) {
229
280
  'export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.extraheader GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $chant_auth"',
230
281
  "unset chant_auth",
231
282
  ];
232
- const job = (name, needs, script, extra = []) => [
283
+ const job = (name, needs, script, extra = [], vars = []) => [
233
284
  `${name}:`,
234
285
  " rules:",
235
286
  ' - if: $CHANT_RELEASE_LABEL && $CI_PIPELINE_SOURCE =~ /^(web|api|trigger)$/',
236
287
  " variables:",
237
288
  ' GIT_DEPTH: "0"',
289
+ ...vars,
238
290
  ...(needs.length > 0 ? [` needs: [${needs.join(", ")}]`] : []),
239
291
  ...extra,
240
292
  " script:",
@@ -244,19 +296,20 @@ function renderGitlabDispatch(o) {
244
296
  const lines = [
245
297
  ...job("chant-release-gate", [], [...cd, o.install, fetches[0], ...gateScript(o, "$CI_COMMIT_SHA"), 'echo "CHANT_RELEASE_COMMIT=$commit" > "$CI_PROJECT_DIR/chant-release-gate.env"'], [" artifacts:", " reports:", " dotenv: chant-release-gate.env"]),
246
298
  "",
247
- ...job("chant-release-cut", ["chant-release-gate"], [...checkout, ...cd, o.install, ...fetches, ...auth, ...cutScript(o, "/tmp/chant-cut.json")]),
299
+ ...job("chant-release-cut", ["chant-release-gate"], [...checkout, ...cd, o.install, ...o.extra.gitlabScript, ...fetches, ...auth, ...cutScript(o, "/tmp/chant-cut.json")], [], o.extra.gitlabVariables),
248
300
  "",
249
301
  ...job("chant-release-publish", ["chant-release-gate", "chant-release-cut"], [
250
302
  ...checkout,
251
303
  ...cd,
252
304
  o.install,
305
+ ...o.extra.gitlabScript,
253
306
  ...fetches,
254
307
  ...auth,
255
308
  ...(o.images ? [`${o.chant} release images "$CHANT_RELEASE_LABEL" -o ${RELEASE_DIGESTS_FILE}`, `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`] : []),
256
309
  ...(o.build ? [o.build] : []),
257
310
  ...(o.verify ? [`${o.chant} release verify "$CHANT_RELEASE_LABEL"`] : []),
258
311
  `${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
259
- ], [" id_tokens:", " SIGSTORE_ID_TOKEN:", " aud: sigstore"]),
312
+ ], [" id_tokens:", " SIGSTORE_ID_TOKEN:", " aud: sigstore"], o.extra.gitlabVariables),
260
313
  ];
261
314
  if (o.after.length > 0)
262
315
  lines.push("", ...job("chant-release-after", ["chant-release-gate", "chant-release-publish"], [...checkout, ...cd, o.install, ...o.after]));
@@ -318,7 +371,7 @@ export async function runReleaseWorkflow(ctx) {
318
371
  ...(args.buildCommand ? { build: args.buildCommand } : {}),
319
372
  ...(args.ciChant ? { chant: args.ciChant } : {}),
320
373
  });
321
- const target = args.output ? resolve(process.cwd(), args.output) : join(repoRoot, RELEASE_WORKFLOW_FILES[forge]);
374
+ const target = args.output ? resolve(process.cwd(), args.output) : join(repoRoot, release?.workflow?.file ?? RELEASE_WORKFLOW_FILES[forge]);
322
375
  const parts = ["chant", "release", "workflow", "--forge", forge];
323
376
  if (args.ciInstall)
324
377
  parts.push("--install", args.ciInstall);
@@ -335,7 +388,7 @@ export async function runReleaseWorkflow(ctx) {
335
388
  const what = release?.workflow?.trigger === "dispatch" ? "cuts and publishes a release started by hand with its label, from a green commit" : "publishes the release a release/** tag names";
336
389
  console.log(formatSuccess(`Wrote ${shown}: ${what}${extras.length > 0 ? `, and ${extras.join(" and ")}` : ""}.`));
337
390
  if (forge === "gitlab")
338
- console.log(`Include it from .gitlab-ci.yml: include: [{ local: ${RELEASE_WORKFLOW_FILES.gitlab} }]`);
391
+ console.log(`Include it from .gitlab-ci.yml: include: [{ local: ${release?.workflow?.file ?? RELEASE_WORKFLOW_FILES.gitlab} }]`);
339
392
  if (forge === "gitlab" && release?.workflow?.trigger === "dispatch")
340
393
  console.log("The cut and publish jobs push with CHANT_RELEASE_TOKEN: a project access token with write_repository, as a masked CI/CD variable.");
341
394
  return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant",
3
- "version": "0.124.71",
3
+ "version": "0.124.73",
4
4
  "description": "Declarative infrastructure-as-code toolkit — TypeScript on Node.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
@@ -166,7 +166,7 @@ describe("settings", () => {
166
166
  expect(commitSettingsFromEnv(commitSettingsEnv(s), "plywood")).toEqual(s);
167
167
  expect(commitSettingsFromEnv(commitSettingsEnv(settings({ mergeBase: true })), "plywood").mergeBase).toBe(true);
168
168
  const bad = (spec: Partial<OpCommitSpec>) => () => settings(spec);
169
- expect(bad({ allowed: [] })).toThrow(/allowed names at least one path/);
169
+ expect(bad({ allowed: [] })).toThrow(/allowed or allowedFiles names at least one path/);
170
170
  expect(bad({ allowed: ["../x"] })).toThrow(/paths from the repository root/);
171
171
  expect(bad({ command: [] })).toThrow(/command is an argv/);
172
172
  expect(bad({ command: ["-rf"] })).toThrow(/command is an argv/);
@@ -262,6 +262,27 @@ describe("the comment trigger", () => {
262
262
  }
263
263
  });
264
264
 
265
+ test("allowedFiles lets a matching file in any directory through, and still refuses another file and a guarded path (#4758)", async () => {
266
+ const byName = () => settings({ allowed: [], allowedFiles: ["*.tf", "terragrunt.hcl"] });
267
+ const ok = world();
268
+ const { out } = await cycle(ok, byName(), { command: formatter({ "envs/prod/vpc/main.tf": "a=1\n", "live/terragrunt.hcl": "x=1\n" }) });
269
+ expect(out.result).toBe("pushed");
270
+ for (const extra of [{ "notes.md": "x\n" }, { ".github/workflows/x.tf": "x\n" }, { "main.tfstate": "{}\n" }] as Record<string, string>[]) {
271
+ const w = world();
272
+ const { out: refused } = await cycle(w, byName(), { command: formatter(extra) });
273
+ expect(refused.result).toBe("refused");
274
+ expect(refused.reason).toContain(Object.keys(extra)[0]!);
275
+ expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
276
+ }
277
+ });
278
+
279
+ test("allowedFiles round-trips through the job's variables and refuses a path or nothing at all", () => {
280
+ const s = settings({ allowed: [], allowedFiles: ["*.tf"] });
281
+ expect(commitSettingsFromEnv(commitSettingsEnv(s), "plywood").allowedFiles).toEqual(["*.tf"]);
282
+ expect(() => settings({ allowedFiles: ["modules/*.tf"] })).toThrow(/allowedFiles are file names/);
283
+ expect(() => settings({ allowed: [], allowedFiles: [] })).toThrow(/allowed or allowedFiles/);
284
+ });
285
+
265
286
  test("a command that fails pushes nothing", async () => {
266
287
  const w = world();
267
288
  const { out } = await cycle(w, settings(), { command: formatter({}, 3) });
package/src/ci-commit.ts CHANGED
@@ -37,7 +37,12 @@ import type { PrForge } from "./pr-forge";
37
37
  import { NEXT_RELEASE } from "./release-floors";
38
38
 
39
39
  /** The first chant with the commit job and the scheduled Op spec's `commit` (#4722). Products feature-detect on it. */
40
- export const CI_COMMIT_FLOOR = NEXT_RELEASE;
40
+ export const CI_COMMIT_FLOOR = "0.124.71";
41
+
42
+ /** The first chant with a commit job after a check that runs on push, `jobToken` and `after` (#4749). Products feature-detect on it. */
43
+ export const CI_COMMIT_PUSH_FLOOR = "0.124.72";
44
+ /** The first chant whose commit job takes `allowedFiles` (#4758). */
45
+ export const CI_COMMIT_FILES_FLOOR = NEXT_RELEASE;
41
46
 
42
47
  /** What starts a commit run: a person's comment, or a check job's finding. */
43
48
  export type CommitTrigger = "comment" | "check";
@@ -58,6 +63,13 @@ export interface OpCommitSpec {
58
63
  command: string[];
59
64
  /** The only paths the change may touch, from the repository root; a trailing `/` names a directory. */
60
65
  allowed: string[];
66
+ /**
67
+ * File names the change may touch in any directory (#4758), matched on the
68
+ * basename: `*.tf` or an exact name such as `terragrunt.hcl`. A path passes
69
+ * when it is in `allowed` or matches one of these; a guarded path is still
70
+ * refused. With these, `allowed` may be empty.
71
+ */
72
+ allowedFiles?: string[];
61
73
  /** For `on: "check"`: the exit codes of the Op's run that name a finding. Default `[2]`, chant's `drift` code. */
62
74
  findings?: number[];
63
75
  /** The secret (GitHub, Forgejo) or protected variable (GitLab) holding the push token. Required on GitHub and Forgejo; `CHANT_FORGE_TOKEN` by default on GitLab. */
@@ -79,6 +91,19 @@ export interface OpCommitSpec {
79
91
  * its parents are the head and the base tip.
80
92
  */
81
93
  mergeBase?: boolean;
94
+ /**
95
+ * GitHub and Forgejo (#4749): push with the job's own token, so `tokenEnv`
96
+ * may be left out. Such a push starts no workflow run, so the new head gets
97
+ * no plan from it; `after` is where a product does what that run would
98
+ * have done. Refused on GitLab, where a job token cannot push.
99
+ */
100
+ jobToken?: boolean;
101
+ /**
102
+ * Shell lines the push job runs once it has pushed a commit (#4749), with
103
+ * `CHANT_COMMIT_SHA` set to it, such as a product taking the plan locks of
104
+ * the new head. Not run when nothing was pushed.
105
+ */
106
+ after?: string[];
82
107
  }
83
108
 
84
109
  /** A commit job's settings, every default filled and checked. */
@@ -88,12 +113,17 @@ export interface CommitSettings {
88
113
  comment?: string;
89
114
  command: string[];
90
115
  allowed: string[];
116
+ allowedFiles: string[];
91
117
  findings: number[];
92
118
  maxRuns: number;
93
119
  guarded: string[];
94
120
  timeout: number;
95
121
  env: string;
96
122
  mergeBase: boolean;
123
+ /** Push with the job token (#4749). */
124
+ jobToken: boolean;
125
+ /** Lines the push job runs after a push (#4749). */
126
+ after: string[];
97
127
  }
98
128
 
99
129
  export const COMMIT_MAX_RUNS = 3;
@@ -110,6 +140,7 @@ export const COMMIT_ENV = {
110
140
  comment: "CHANT_COMMIT_COMMENT",
111
141
  command: "CHANT_COMMIT_COMMAND",
112
142
  allowed: "CHANT_COMMIT_ALLOWED",
143
+ allowedFiles: "CHANT_COMMIT_ALLOWED_FILES",
113
144
  findings: "CHANT_COMMIT_FINDINGS",
114
145
  maxRuns: "CHANT_COMMIT_MAX_RUNS",
115
146
  guarded: "CHANT_COMMIT_GUARDED",
@@ -131,6 +162,24 @@ export const COMMIT_BASE_REF = "refs/chant/commit-base";
131
162
  export const COMMIT_DECISION_FILE = "decision.json";
132
163
  export const COMMIT_PATCH_FILE = "change.patch";
133
164
  export const COMMIT_RC_FILE = "rc";
165
+ /** What `chant commit land` leaves when it pushed (#4749): the pushed commit, which the push job's `after` lines read. */
166
+ export const COMMIT_PUSHED_FILE = "pushed";
167
+
168
+ /**
169
+ * After a check that runs on push (#4749): fetch the pushed commit, by its
170
+ * sha in `shaVar`, into `into` as the head. The pull request is found from
171
+ * the pushed branch (`resolveCommitRequest`).
172
+ */
173
+ export function commitPushedHeadFetchLine(shaVar: string, into: string = COMMIT_HEAD_REF): string {
174
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(shaVar)) throw new AgentError(`${shaVar} is not a variable name`);
175
+ return `case "$${shaVar}" in *[!0-9a-f]*|'') echo "no pushed commit" >&2; exit 1 ;; esac\ngit -c protocol.version=2 fetch -q --no-tags origin "+$${shaVar}:${into}"`;
176
+ }
177
+
178
+ /** The push job's lines after land (#4749): `after`, run only when a commit was pushed, with \`CHANT_COMMIT_SHA\` set. */
179
+ export function commitAfterLines(s: Pick<CommitSettings, "after">, dir: string = COMMIT_DIR): string[] {
180
+ if (s.after.length === 0) return [];
181
+ return [`if [ -s ${dir}/${COMMIT_PUSHED_FILE} ]; then`, ` export CHANT_COMMIT_SHA="$(cat ${dir}/${COMMIT_PUSHED_FILE})"`, ...s.after.map((l) => ` ${l}`), "fi"];
182
+ }
134
183
 
135
184
  /** The commit identity the job's commits carry. */
136
185
  export const COMMIT_GIT_NAME = "chant commit";
@@ -165,7 +214,11 @@ export function resolveCommitSpec(name: string, spec: OpCommitSpec, product = "c
165
214
  throw new AgentError(`${where}: command is an argv, a program and its arguments, with no control characters`);
166
215
  }
167
216
  const allowed = pathsIn(`${where}: allowed`, spec.allowed);
168
- if (allowed.length === 0) throw new AgentError(`${where}: allowed names at least one path the change may touch`);
217
+ const allowedFiles = spec.allowedFiles ?? [];
218
+ if (!Array.isArray(allowedFiles) || !allowedFiles.every((f) => typeof f === "string" && FILE_PATTERN.test(f))) {
219
+ throw new AgentError(`${where}: allowedFiles are file names, such as "*.tf" or "terragrunt.hcl", with no "/"`);
220
+ }
221
+ if (allowed.length === 0 && allowedFiles.length === 0) throw new AgentError(`${where}: allowed or allowedFiles names at least one path the change may touch`);
169
222
  const guarded = spec.guarded === undefined ? [] : pathsIn(`${where}: guarded`, spec.guarded);
170
223
  if (spec.tokenEnv !== undefined && !VAR.test(spec.tokenEnv)) throw new AgentError(`${where}: tokenEnv is a variable name`);
171
224
  const findings = spec.findings ?? [CHANT_EXIT.drift];
@@ -173,18 +226,25 @@ export function resolveCommitSpec(name: string, spec: OpCommitSpec, product = "c
173
226
  for (const f of findings) intIn(`${where}: findings`, f, 1, 255);
174
227
  const env = spec.env ?? "local";
175
228
  if (!NAME.test(env)) throw new AgentError(`${where}: env is a ledger environment name`);
229
+ if (spec.jobToken !== undefined && typeof spec.jobToken !== "boolean") throw new AgentError(`${where}: jobToken is true or false`);
230
+ if (spec.jobToken && spec.tokenEnv !== undefined) throw new AgentError(`${where}: jobToken pushes with the job's own token, so leave tokenEnv out`);
231
+ const after = spec.after ?? [];
232
+ if (!Array.isArray(after) || !after.every((l) => typeof l === "string" && l.trim() !== "" && !l.includes("\n"))) throw new AgentError(`${where}: after is a list of shell lines, one command each`);
176
233
  return {
177
234
  name,
178
235
  on: spec.on,
179
236
  ...(spec.on === "comment" ? { comment: spec.comment! } : {}),
180
237
  command: [...spec.command],
181
238
  allowed,
239
+ allowedFiles: [...allowedFiles],
182
240
  findings: [...findings],
183
241
  maxRuns: spec.maxRuns === undefined ? COMMIT_MAX_RUNS : intIn(`${where}: maxRuns`, spec.maxRuns, 1, 100),
184
242
  guarded,
185
243
  timeout: spec.timeout === undefined ? COMMIT_TIMEOUT_MINUTES : intIn(`${where}: timeout`, spec.timeout, 1, 120),
186
244
  env,
187
245
  mergeBase: spec.mergeBase === true,
246
+ jobToken: spec.jobToken === true,
247
+ after: [...after],
188
248
  };
189
249
  }
190
250
 
@@ -196,6 +256,7 @@ export function commitSettingsEnv(s: CommitSettings): Record<string, string> {
196
256
  ...(s.comment ? { [COMMIT_ENV.comment]: s.comment } : {}),
197
257
  [COMMIT_ENV.command]: JSON.stringify(s.command),
198
258
  [COMMIT_ENV.allowed]: JSON.stringify(s.allowed),
259
+ ...(s.allowedFiles.length > 0 ? { [COMMIT_ENV.allowedFiles]: JSON.stringify(s.allowedFiles) } : {}),
199
260
  [COMMIT_ENV.findings]: s.findings.join(","),
200
261
  [COMMIT_ENV.maxRuns]: String(s.maxRuns),
201
262
  ...(s.guarded.length > 0 ? { [COMMIT_ENV.guarded]: JSON.stringify(s.guarded) } : {}),
@@ -236,6 +297,7 @@ export function commitSettingsFromEnv(env: Record<string, string | undefined>, p
236
297
  ...(env[COMMIT_ENV.comment] ? { comment: env[COMMIT_ENV.comment] } : {}),
237
298
  command: list(COMMIT_ENV.command) ?? [],
238
299
  allowed: list(COMMIT_ENV.allowed) ?? [],
300
+ ...(list(COMMIT_ENV.allowedFiles) ? { allowedFiles: list(COMMIT_ENV.allowedFiles)! } : {}),
239
301
  ...(f ? { findings: f.split(",").map(Number) } : {}),
240
302
  ...(maxRuns !== undefined ? { maxRuns } : {}),
241
303
  ...(timeout !== undefined ? { timeout } : {}),
@@ -248,14 +310,23 @@ export function commitSettingsFromEnv(env: Record<string, string | undefined>, p
248
310
 
249
311
  // ── what the change may touch ──────────────────────────────────────────────
250
312
 
251
- /** Whether `path` is inside one of `allowed` (a trailing `/` names a directory), matched as git spells it. */
252
- function inAllowed(path: string, allowed: readonly string[]): boolean {
253
- return allowed.some((a) => (a.endsWith("/") ? path.startsWith(a) || `${path}/` === a : path === a));
313
+ /** An `allowedFiles` entry: `*.<ext>` or an exact file name, never a path. */
314
+ const FILE_PATTERN = /^(\*\.[A-Za-z0-9._-]+|[A-Za-z0-9._-]+)$/;
315
+
316
+ /** Whether `path`'s basename matches one of `files` (#4758). */
317
+ function fileAllowed(path: string, files: readonly string[]): boolean {
318
+ const base = path.slice(path.lastIndexOf("/") + 1);
319
+ return files.some((f) => (f.startsWith("*.") ? base.endsWith(f.slice(1)) && base.length > f.length - 1 : base === f));
320
+ }
321
+
322
+ /** Whether `path` is inside one of `allowed` (a trailing `/` names a directory), matched as git spells it, or its file name is in `files`. */
323
+ function inAllowed(path: string, allowed: readonly string[], files: readonly string[] = []): boolean {
324
+ return allowed.some((a) => (a.endsWith("/") ? path.startsWith(a) || `${path}/` === a : path === a)) || fileAllowed(path, files);
254
325
  }
255
326
 
256
327
  /** The paths of a change the job may not push: outside `allowed`, or on a path no job changes ({@link agentForbiddenPaths}). */
257
- export function commitRefusedPaths(paths: readonly string[], s: Pick<CommitSettings, "allowed" | "guarded">): { forbidden: string[]; outside: string[] } {
258
- return { forbidden: agentForbiddenPaths(paths, s.guarded), outside: paths.filter((p) => !inAllowed(p, s.allowed)) };
328
+ export function commitRefusedPaths(paths: readonly string[], s: Pick<CommitSettings, "allowed" | "guarded"> & Partial<Pick<CommitSettings, "allowedFiles">>): { forbidden: string[]; outside: string[] } {
329
+ return { forbidden: agentForbiddenPaths(paths, s.guarded), outside: paths.filter((p) => !inAllowed(p, s.allowed, s.allowedFiles ?? [])) };
259
330
  }
260
331
 
261
332
  // ── the request ────────────────────────────────────────────────────────────
@@ -817,7 +888,7 @@ export async function landCommitChange(i: CommitLandInput): Promise<CommitLandOu
817
888
  const bad = [...new Set([...forbidden, ...outside])];
818
889
  return finish(
819
890
  { result: "refused", reason: `the change touches ${bad.join(", ")}`, paths },
820
- `${code(s.command.join(" "))} changed ${bad.map(code).join(", ")}, which ${s.name} may not change (it may change ${s.allowed.map(code).join(", ")}, and never CI, chant's settings and state, code owners, agent instructions or git settings), so nothing was pushed.`,
891
+ `${code(s.command.join(" "))} changed ${bad.map(code).join(", ")}, which ${s.name} may not change (it may change ${[...s.allowed, ...s.allowedFiles].map(code).join(", ")}, and never CI, chant's settings and state, code owners, agent instructions or git settings), so nothing was pushed.`,
821
892
  );
822
893
  }
823
894