@intentius/chant 0.124.78 → 0.124.80

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 (184) hide show
  1. package/dist/action-pins.d.ts.map +1 -1
  2. package/dist/action-pins.js +1 -2
  3. package/dist/change-set.d.ts +10 -1
  4. package/dist/change-set.d.ts.map +1 -1
  5. package/dist/change-set.js +4 -1
  6. package/dist/ci-agent.d.ts +16 -2
  7. package/dist/ci-agent.d.ts.map +1 -1
  8. package/dist/ci-agent.js +6 -1
  9. package/dist/ci-commit.d.ts.map +1 -1
  10. package/dist/ci-commit.js +2 -3
  11. package/dist/ci-note-commands.d.ts +199 -0
  12. package/dist/ci-note-commands.d.ts.map +1 -0
  13. package/dist/ci-note-commands.js +372 -0
  14. package/dist/ci-product.d.ts +6 -2
  15. package/dist/ci-product.d.ts.map +1 -1
  16. package/dist/ci-product.js +5 -1
  17. package/dist/cli/handlers/build.d.ts.map +1 -1
  18. package/dist/cli/handlers/build.js +7 -1
  19. package/dist/cli/handlers/pr-notes.d.ts +13 -0
  20. package/dist/cli/handlers/pr-notes.d.ts.map +1 -0
  21. package/dist/cli/handlers/pr-notes.js +73 -0
  22. package/dist/cli/handlers/release.d.ts +8 -0
  23. package/dist/cli/handlers/release.d.ts.map +1 -1
  24. package/dist/cli/handlers/release.js +64 -2
  25. package/dist/cli/handlers/run-wave.js +1 -0
  26. package/dist/cli/main.d.ts.map +1 -1
  27. package/dist/cli/main.js +17 -1
  28. package/dist/cli/mcp/product-tools.d.ts +6 -0
  29. package/dist/cli/mcp/product-tools.d.ts.map +1 -1
  30. package/dist/cli/mcp/product-tools.js +6 -0
  31. package/dist/cli/mcp/read-only.d.ts +12 -0
  32. package/dist/cli/mcp/read-only.d.ts.map +1 -1
  33. package/dist/cli/mcp/read-only.js +16 -0
  34. package/dist/cli/mcp/server.d.ts +11 -0
  35. package/dist/cli/mcp/server.d.ts.map +1 -1
  36. package/dist/cli/mcp/server.js +26 -5
  37. package/dist/cli/mcp/types.d.ts +5 -1
  38. package/dist/cli/mcp/types.d.ts.map +1 -1
  39. package/dist/cli/parse-args.d.ts.map +1 -1
  40. package/dist/cli/parse-args.js +10 -0
  41. package/dist/cli/registry.d.ts +4 -0
  42. package/dist/cli/registry.d.ts.map +1 -1
  43. package/dist/components/capability.d.ts +53 -0
  44. package/dist/components/capability.d.ts.map +1 -1
  45. package/dist/components/group-digest.d.ts +17 -0
  46. package/dist/components/group-digest.d.ts.map +1 -0
  47. package/dist/components/group-digest.js +18 -0
  48. package/dist/components/groups.d.ts +2 -11
  49. package/dist/components/groups.d.ts.map +1 -1
  50. package/dist/components/groups.js +2 -12
  51. package/dist/components/index.d.ts +1 -1
  52. package/dist/components/index.d.ts.map +1 -1
  53. package/dist/components/pr-pipeline.d.ts +22 -0
  54. package/dist/components/pr-pipeline.d.ts.map +1 -1
  55. package/dist/components/pr-pipeline.js +26 -0
  56. package/dist/components/product-pipeline.d.ts +12 -0
  57. package/dist/components/product-pipeline.d.ts.map +1 -1
  58. package/dist/components/product-pipeline.js +5 -1
  59. package/dist/config.d.ts +14 -0
  60. package/dist/config.d.ts.map +1 -1
  61. package/dist/config.js +5 -0
  62. package/dist/lexicon.d.ts.map +1 -1
  63. package/dist/lexicon.js +1 -2
  64. package/dist/lifecycle/release-cut.d.ts +7 -1
  65. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  66. package/dist/lifecycle/release-cut.js +1 -0
  67. package/dist/lifecycle/release-images.d.ts +12 -3
  68. package/dist/lifecycle/release-images.d.ts.map +1 -1
  69. package/dist/lifecycle/release-images.js +6 -7
  70. package/dist/lifecycle/release-publish.d.ts +8 -1
  71. package/dist/lifecycle/release-publish.d.ts.map +1 -1
  72. package/dist/lifecycle/release-publish.js +30 -3
  73. package/dist/lifecycle/release-version.d.ts +86 -0
  74. package/dist/lifecycle/release-version.d.ts.map +1 -0
  75. package/dist/lifecycle/release-version.js +208 -0
  76. package/dist/mcp/types.d.ts +26 -0
  77. package/dist/mcp/types.d.ts.map +1 -1
  78. package/dist/notify-product.d.ts.map +1 -1
  79. package/dist/notify-product.js +1 -2
  80. package/dist/op/activities/review-product.d.ts.map +1 -1
  81. package/dist/op/activities/review-product.js +1 -2
  82. package/dist/op/gate.d.ts +17 -0
  83. package/dist/op/gate.d.ts.map +1 -1
  84. package/dist/op/gate.js +36 -0
  85. package/dist/op/index.d.ts +8 -6
  86. package/dist/op/index.d.ts.map +1 -1
  87. package/dist/op/index.js +5 -4
  88. package/dist/op/op-waves-after-plan.d.ts +109 -1
  89. package/dist/op/op-waves-after-plan.d.ts.map +1 -1
  90. package/dist/op/op-waves-after-plan.js +180 -3
  91. package/dist/op/op-waves-capability-spec.js +1 -2
  92. package/dist/op/op-waves-capability.d.ts +93 -3
  93. package/dist/op/op-waves-capability.d.ts.map +1 -1
  94. package/dist/op/op-waves-capability.js +218 -10
  95. package/dist/op/op-waves-run-hooks.d.ts +104 -0
  96. package/dist/op/op-waves-run-hooks.d.ts.map +1 -0
  97. package/dist/op/op-waves-run-hooks.js +145 -0
  98. package/dist/op/op-waves-run.d.ts +21 -0
  99. package/dist/op/op-waves-run.d.ts.map +1 -1
  100. package/dist/op/op-waves-run.js +307 -21
  101. package/dist/op/op-waves.d.ts +11 -1
  102. package/dist/op/op-waves.d.ts.map +1 -1
  103. package/dist/op/op-waves.js +7 -1
  104. package/dist/op/runtime.d.ts +2 -0
  105. package/dist/op/runtime.d.ts.map +1 -1
  106. package/dist/pr-forge-reads.d.ts +151 -1
  107. package/dist/pr-forge-reads.d.ts.map +1 -1
  108. package/dist/pr-forge-reads.js +265 -1
  109. package/dist/pr-plan-note.d.ts.map +1 -1
  110. package/dist/pr-plan-note.js +1 -2
  111. package/dist/release-floors.d.ts +19 -1
  112. package/dist/release-floors.d.ts.map +1 -1
  113. package/dist/release-floors.js +23 -5
  114. package/dist/wave-runtime.mjs +312 -312
  115. package/dist/workspace/change-set.schema.json +7 -0
  116. package/dist/workspace/release-workflow.d.ts +7 -0
  117. package/dist/workspace/release-workflow.d.ts.map +1 -1
  118. package/dist/workspace/release-workflow.js +11 -1
  119. package/package.json +1 -1
  120. package/src/action-pins.test.ts +1 -2
  121. package/src/action-pins.ts +1 -3
  122. package/src/change-set.test.ts +20 -0
  123. package/src/change-set.ts +11 -1
  124. package/src/ci-agent.test.ts +9 -0
  125. package/src/ci-agent.ts +15 -2
  126. package/src/ci-commit.test.ts +2 -3
  127. package/src/ci-commit.ts +2 -3
  128. package/src/ci-note-commands.test.ts +377 -0
  129. package/src/ci-note-commands.ts +479 -0
  130. package/src/ci-product.ts +6 -2
  131. package/src/cli/handlers/build.ts +7 -1
  132. package/src/cli/handlers/pr-notes.ts +70 -0
  133. package/src/cli/handlers/release.ts +55 -2
  134. package/src/cli/handlers/run-wave.ts +1 -0
  135. package/src/cli/main.ts +17 -1
  136. package/src/cli/mcp/product-tools.test.ts +49 -0
  137. package/src/cli/mcp/product-tools.ts +7 -0
  138. package/src/cli/mcp/read-only.ts +19 -0
  139. package/src/cli/mcp/server.test.ts +30 -0
  140. package/src/cli/mcp/server.ts +28 -5
  141. package/src/cli/mcp/types.ts +6 -1
  142. package/src/cli/parse-args.ts +8 -0
  143. package/src/cli/registry.ts +4 -0
  144. package/src/components/capability.ts +52 -0
  145. package/src/components/group-digest.ts +20 -0
  146. package/src/components/groups.ts +3 -13
  147. package/src/components/index.ts +2 -0
  148. package/src/components/pr-pipeline.ts +35 -0
  149. package/src/components/product-pipeline.test.ts +14 -0
  150. package/src/components/product-pipeline.ts +13 -1
  151. package/src/config.ts +15 -0
  152. package/src/lexicon.ts +1 -2
  153. package/src/lifecycle/release-cut.ts +11 -0
  154. package/src/lifecycle/release-images-dockerfile.test.ts +10 -2
  155. package/src/lifecycle/release-images.ts +12 -8
  156. package/src/lifecycle/release-publish.ts +34 -3
  157. package/src/lifecycle/release-version.test.ts +155 -0
  158. package/src/lifecycle/release-version.ts +226 -0
  159. package/src/mcp/types.ts +27 -0
  160. package/src/notify-message-words.test.ts +1 -2
  161. package/src/notify-product.ts +1 -2
  162. package/src/op/activities/review-product.ts +1 -2
  163. package/src/op/gate.ts +46 -0
  164. package/src/op/index.ts +10 -4
  165. package/src/op/op-waves-after-plan-wave.test.ts +225 -0
  166. package/src/op/op-waves-after-plan.ts +228 -5
  167. package/src/op/op-waves-capability-spec.ts +1 -1
  168. package/src/op/op-waves-capability.test.ts +9 -1
  169. package/src/op/op-waves-capability.ts +246 -13
  170. package/src/op/op-waves-gate-port.test.ts +232 -0
  171. package/src/op/op-waves-run-hooks.test.ts +183 -0
  172. package/src/op/op-waves-run-hooks.ts +194 -0
  173. package/src/op/op-waves-run.ts +313 -25
  174. package/src/op/op-waves-step-wave.test.ts +276 -0
  175. package/src/op/op-waves.ts +15 -2
  176. package/src/op/runtime.ts +2 -0
  177. package/src/pr-forge-reads-compare.test.ts +145 -0
  178. package/src/pr-forge-reads.test.ts +203 -0
  179. package/src/pr-forge-reads.ts +398 -1
  180. package/src/pr-plan-note.ts +1 -2
  181. package/src/release-floors.ts +32 -5
  182. package/src/workspace/change-set.schema.json +7 -0
  183. package/src/workspace/release-workflow.test.ts +18 -0
  184. package/src/workspace/release-workflow.ts +21 -1
@@ -225,3 +225,17 @@ describe("the commit jobs (#4722)", () => {
225
225
  expect(() => productCheckCommit(words, "fmt-check", { command: [], allowed: ["infra/"] })).toThrow(/argv/);
226
226
  });
227
227
  });
228
+
229
+ describe("GitLab's comment commands by polling the notes (#4785)", () => {
230
+ test("noteCommands is one switch: the note-commands job's command, with the jobs a command starts", () => {
231
+ const jobs = productPipelineJobs("gitlab", "production", { words: PLYWOOD, waves, locks: "plan", previewComment: true, noteCommands: true });
232
+ expect(jobs.noteCommands!.command).toBe("npx --no-install plywood components pr-notes --forge gitlab --preview-comment --apply-on-merge --locks");
233
+ expect(productPipelineJobs("gitlab", "production", { words: PLYWOOD, waves, locks: "plan" }).noteCommands).toBeUndefined();
234
+ });
235
+
236
+ test("refused on GitHub and Forgejo, which start a workflow on a comment", () => {
237
+ for (const forge of ["github", "forgejo"] as const) {
238
+ expect(() => productPipelineJobs(forge, "production", { words: PLYWOOD, waves, locks: "plan", noteCommands: true })).toThrow(/--note-commands polls GitLab's merge request notes/);
239
+ }
240
+ });
241
+ });
@@ -34,7 +34,7 @@ import {
34
34
  type CiProductWords,
35
35
  type CiProductWordsInput,
36
36
  } from "../ci-product-words";
37
- import { prActionJob, prCommentLockJobs, prCommentPreviewJob, prLoopJobs, prLoopPostJob, prLoopRunner, prStaleJob, withProductBin, type PrActionJob, type PrCommentLockJob, type PrCommentPreviewJob, type PrLoopJob, type PrLoopPipelineOptions } from "./pr-pipeline";
37
+ import { prActionJob, prCommentLockJobs, prCommentPreviewJob, prLoopJobs, prLoopPostJob, prLoopRunner, prNoteCommandsJob, prStaleJob, withProductBin, type PrActionJob, type PrCommentLockJob, type PrCommentPreviewJob, type PrLoopJob, type PrLoopPipelineOptions } from "./pr-pipeline";
38
38
  import type { DriverComponent } from "./driver";
39
39
  import type { ScheduledOpSpec } from "../lexicon";
40
40
  import type { CiRunner } from "../ci-jobs";
@@ -155,6 +155,15 @@ export interface ProductPipelineJobs {
155
155
  * lexicons render the same job, `stale-notes`.
156
156
  */
157
157
  stale?: { command: string; env: Record<string, string>; runner?: CiRunner };
158
+ /**
159
+ * GitLab's comment commands (#4785), with `noteCommands`: the command of
160
+ * the `note-commands` job, which a schedule starts with
161
+ * `CHANT_NOTE_COMMANDS=1` on the target branch. It polls the merge
162
+ * requests' notes and starts the jobs the commands ask for. The GitLab
163
+ * lexicon renders the same job from `chant build --pr-loop
164
+ * --note-commands`. Refused on GitHub and Forgejo.
165
+ */
166
+ noteCommands?: { command: string; runner?: CiRunner };
158
167
  /**
159
168
  * The agent (#4616), with `agent`: the comment it answers, `/<product>
160
169
  * agent <ask>`, and the scheduled Op spec whose generated workflow runs
@@ -301,6 +310,9 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
301
310
  if (action) out.action = { ...action, ...(prLoopRunner(options, "apply") !== undefined ? { runner: prLoopRunner(options, "apply")! } : {}) };
302
311
  const stale = prStaleJob(forge, env, prLoop, member);
303
312
  if (stale) out.stale = { ...stale, ...defaultRunner };
313
+ // #4785: GitLab's comment commands, polled from the notes; waves on merge are retried by an apply on a merged merge request.
314
+ const notes = prNoteCommandsJob(forge, { ...prLoop, ...(options.waves || options.componentWaves ? { applyOnMerge: true } : {}) });
315
+ if (notes) out.noteCommands = { ...notes, ...defaultRunner };
304
316
  const preview = prCommentPreviewJob(forge, env, prLoop, member);
305
317
  if (preview) out.preview = { ...preview, ...(defaultRunner.runner !== undefined ? { noteRunner: defaultRunner.runner } : {}) };
306
318
  // #4616: the agent answers its comment from a workflow of its own, generated from this spec.
package/src/config.ts CHANGED
@@ -128,6 +128,11 @@ export const ChantConfigSchema = z.object({
128
128
  )
129
129
  .optional(),
130
130
  lane: z.string().regex(/^[a-z0-9][a-z0-9-]*$/, "a ci.green lane name: lowercase letters, digits and dashes").optional(),
131
+ // #4840: the label stamped into these packages' package.json at the cut and the publish.
132
+ version: z.object({
133
+ packages: z.array(z.string().min(1)).min(1),
134
+ lockfile: z.union([z.string().min(1), z.literal(false)]).optional(),
135
+ }).strict().optional(),
131
136
  workflow: z.object({
132
137
  trigger: z.enum(["tag", "dispatch"]).optional(),
133
138
  gate: z.enum(["last-green", "head"]).optional(),
@@ -423,6 +428,16 @@ export interface ChantConfig {
423
428
  * rather than `ci/green/<sha>`.
424
429
  */
425
430
  lane?: string;
431
+ /**
432
+ * The package directories whose `package.json` the release stamps with
433
+ * its label (#4840), so the version needs no commit: the cut stamps them
434
+ * before it builds the images and runs the build and puts them back, and
435
+ * the publish job stamps them with `chant release stamp <label>` before
436
+ * its build. The lockfile's entries for them follow (`lockfile`, default
437
+ * `package-lock.json` when there is one). See
438
+ * ./lifecycle/release-version.ts.
439
+ */
440
+ version?: import("./lifecycle/release-version").ReleaseVersionConfig;
426
441
  /**
427
442
  * The release pipeline `chant release workflow` writes (#4656): a
428
443
  * dispatched release with gate, cut, publish and post-release jobs, the
package/src/lexicon.ts CHANGED
@@ -47,7 +47,6 @@ import type { DisruptionQuery, DisruptionVerdict } from "./lifecycle/disruption"
47
47
  import type { OwnerChainVerdict } from "./owner-chain";
48
48
  import type { CommandGroup } from "./cli/command-group";
49
49
  import type { Archetype } from "./components/component";
50
- import { NEXT_RELEASE } from "./release-floors";
51
50
 
52
51
  // Re-exported so a lexicon that hosts Op runs (#2121) can type its
53
52
  // `opRuntime` from the same entry it imports the plugin contract from.
@@ -1322,7 +1321,7 @@ export interface CompositeEntry {
1322
1321
  * {@link LexiconPlugin.ciSetup}, so it freezes with chant's release; the
1323
1322
  * lexicon re-exports it as `PULUMI_CI_SETUP_FLOOR`.
1324
1323
  */
1325
- export const CI_SETUP_UNLINKED_FLOOR = NEXT_RELEASE;
1324
+ export const CI_SETUP_UNLINKED_FLOOR = "0.124.78";
1326
1325
 
1327
1326
  export interface LexiconPlugin {
1328
1327
  // ── Required ──────────────────────────────────────────────
@@ -114,6 +114,10 @@ export type ReleaseCutCode =
114
114
  | "release-image-unknown-component"
115
115
  | "release-image-name-taken"
116
116
  | "release-image-build-failed"
117
+ | "release-version-no-label"
118
+ | "release-version-label-invalid"
119
+ | "release-version-no-package"
120
+ | "release-version-invalid"
117
121
  | "release-unsigned"
118
122
  | "release-signer-refused"
119
123
  | "declaration-invalid";
@@ -179,6 +183,12 @@ export interface CutRequest {
179
183
  * Given the commit being cut; returns each as an image artifact.
180
184
  */
181
185
  buildImages?: (commit: string) => Promise<ReleaseArtifact[]> | ReleaseArtifact[];
186
+ /**
187
+ * Stamp the label into the files `release.version` names (#4840), once the
188
+ * tree is found clean and before the images are built or any environment
189
+ * compiled. The caller puts the files back after the cut.
190
+ */
191
+ stamp?: () => void | Promise<void>;
182
192
  }
183
193
 
184
194
  export interface CutResult {
@@ -456,6 +466,7 @@ async function prepare(req: CutRequest, record = false): Promise<Prepared> {
456
466
  "Commit or stash them, or cut from a clean checkout of the commit.",
457
467
  );
458
468
  }
469
+ await req.stamp?.();
459
470
 
460
471
  let envs = req.environments;
461
472
  if (!envs) {
@@ -13,7 +13,6 @@ import { tmpdir } from "node:os";
13
13
  import { join } from "node:path";
14
14
  import { describe, expect, test } from "vitest";
15
15
  import { ChantConfigSchema } from "../config";
16
- import { NEXT_RELEASE } from "../release-floors";
17
16
  import {
18
17
  buildReleaseImages,
19
18
  checkReleaseImages,
@@ -46,6 +45,15 @@ describe("a release.images entry that names a Dockerfile (#4819)", () => {
46
45
  expect(own).toContain("mkdir -p out && ");
47
46
  });
48
47
 
48
+ test("under release.version the build passes the label as CHANT_RELEASE_LABEL, for the image's version label (#4840)", () => {
49
+ const entry = { name: "pulumi", dockerfile: "images/plywood-pulumi/Dockerfile" };
50
+ const plain = releaseImageBuildCommand(entry);
51
+ expect(plain).not.toContain("CHANT_RELEASE_LABEL");
52
+ expect(releaseImageBuildCommand(entry, { versionArg: true })).toBe(
53
+ plain.replace('--build-arg SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH"', '--build-arg SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" --build-arg CHANT_RELEASE_LABEL="$CHANT_RELEASE_LABEL"'),
54
+ );
55
+ });
56
+
49
57
  test("the archive defaults to dist/images/<name>.tar, and a build entry is as it was", () => {
50
58
  const images: ReleaseImageDeclaration[] = [
51
59
  { name: "pulumi", dockerfile: "images/plywood-pulumi/Dockerfile" },
@@ -143,7 +151,7 @@ describe("a release.images entry that names a Dockerfile (#4819)", () => {
143
151
  expect(ok([{ name: "both", build: "x", archive: "a.tar", dockerfile: "D" }])).toBe(false);
144
152
  });
145
153
 
146
- test("the floor names the next release", () => expect(RELEASE_IMAGE_DOCKERFILE_FLOOR).toBe(NEXT_RELEASE));
154
+ test("the floor names the next release", () => expect(RELEASE_IMAGE_DOCKERFILE_FLOOR).toBe("0.124.78"));
147
155
  });
148
156
 
149
157
  describe("the digest table and the pins file (#4819)", () => {
@@ -38,7 +38,6 @@
38
38
  import { spawnSync } from "node:child_process";
39
39
  import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
40
40
  import { dirname, isAbsolute, posix, relative, resolve } from "node:path";
41
- import { NEXT_RELEASE } from "../release-floors";
42
41
  import type { PublishDeclaration } from "./publish-declaration";
43
42
  import type { Release, ReleaseArtifact } from "./release-store";
44
43
 
@@ -53,7 +52,7 @@ export const RELEASE_IMAGES_FLOOR = "0.124.71";
53
52
  * `releaseImagePins` and `writeReleaseImagePins` for a product's package
54
53
  * build (#4819).
55
54
  */
56
- export const RELEASE_IMAGE_DOCKERFILE_FLOOR = NEXT_RELEASE;
55
+ export const RELEASE_IMAGE_DOCKERFILE_FLOOR = "0.124.78";
57
56
 
58
57
  /** One image a release builds in its cut with a command of the product's. */
59
58
  export interface ReleaseImageBuild {
@@ -105,7 +104,7 @@ const archiveOf = (i: ReleaseImageDeclaration): string => i.archive ?? `dist/ima
105
104
  * `SOURCE_DATE_EPOCH` the cut sets passed as a build argument and used to
106
105
  * rewrite every timestamp, and every platform in one image index.
107
106
  */
108
- export function releaseImageBuildCommand(i: ReleaseImageDockerfile): string {
107
+ export function releaseImageBuildCommand(i: ReleaseImageDockerfile, o: { versionArg?: boolean } = {}): string {
109
108
  const archive = archiveOf(i);
110
109
  const b = RELEASE_IMAGE_BUILDER;
111
110
  return [
@@ -113,15 +112,15 @@ export function releaseImageBuildCommand(i: ReleaseImageDockerfile): string {
113
112
  `mkdir -p ${sh(posix.dirname(archive))}`,
114
113
  [
115
114
  `docker buildx build --builder ${b} --no-cache --platform ${sh((i.platforms ?? RELEASE_IMAGE_PLATFORMS).join(","))}`,
116
- `--provenance=false --sbom=false --build-arg SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH"`,
115
+ `--provenance=false --sbom=false --build-arg SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH"${o.versionArg ? ' --build-arg CHANT_RELEASE_LABEL="$CHANT_RELEASE_LABEL"' : ""}`,
117
116
  `--output ${sh(`type=oci,dest=${archive},rewrite-timestamp=true`)} -f ${sh(i.dockerfile)} ${sh(i.context ?? ".")} >&2`,
118
117
  ].join(" "),
119
118
  ].join(" && ");
120
119
  }
121
120
 
122
121
  /** Each entry as a command and an archive: a Dockerfile entry's command is {@link releaseImageBuildCommand}, its archive the default when it names none. */
123
- export function resolveReleaseImages(images: readonly ReleaseImageDeclaration[]): ReleaseImageBuild[] {
124
- return images.map((i) => (isDockerfile(i) ? { name: i.name, build: releaseImageBuildCommand(i), archive: archiveOf(i) } : i));
122
+ export function resolveReleaseImages(images: readonly ReleaseImageDeclaration[], o: { versionArg?: boolean } = {}): ReleaseImageBuild[] {
123
+ return images.map((i) => (isDockerfile(i) ? { name: i.name, build: releaseImageBuildCommand(i, o), archive: archiveOf(i) } : i));
125
124
  }
126
125
 
127
126
  export class ReleaseImageError extends Error {
@@ -169,6 +168,11 @@ export interface BuildImagesInput {
169
168
  label: string | null;
170
169
  env?: NodeJS.ProcessEnv;
171
170
  archiveDigest: ArchiveDigest;
171
+ /**
172
+ * `release.version` stamps the label (#4840): a Dockerfile entry gets it as
173
+ * the build argument `CHANT_RELEASE_LABEL`, for the image's version label.
174
+ */
175
+ versionArg?: boolean;
172
176
  /** Run one build command; the default runs it through the shell with its output on stderr. */
173
177
  run?: (command: string, o: { cwd: string; env: NodeJS.ProcessEnv }) => number | null;
174
178
  }
@@ -202,7 +206,7 @@ export function buildReleaseImages(i: BuildImagesInput): ReleaseArtifact[] {
202
206
  const status = run(image.prepare, { cwd: i.cwd, env });
203
207
  if (status !== 0) throw new ReleaseImageError("release-image-build-failed", `the prepare command of image "${image.name}" exited ${status ?? "with a signal"}: ${image.prepare}`);
204
208
  }
205
- for (const image of resolveReleaseImages(i.images)) {
209
+ for (const image of resolveReleaseImages(i.images, i.versionArg ? { versionArg: true } : {})) {
206
210
  const env = envFor();
207
211
  const status = run(image.build, { cwd: i.cwd, env });
208
212
  if (status !== 0) throw new ReleaseImageError("release-image-build-failed", `the build of image "${image.name}" exited ${status ?? "with a signal"}: ${image.build}`);
@@ -231,7 +235,7 @@ const SHA256 = /^sha256:[0-9a-f]{64}$/;
231
235
  export interface ReleaseImagePinsInput {
232
236
  /** Each image's name in `release.images`, to its reference at this version: `ghcr.io/intentius/plywood-pulumi:0.3.0-pulumi3.272.0`. */
233
237
  images: Record<string, string>;
234
- /** The package's version. A cut's label (`CHANT_RELEASE_LABEL`) must be it. */
238
+ /** The package's version. A cut's label (`CHANT_RELEASE_LABEL`) must be it, as it is when `release.version` stamps the package (#4840). */
235
239
  version: string;
236
240
  env?: NodeJS.ProcessEnv;
237
241
  }
@@ -41,6 +41,7 @@
41
41
 
42
42
  import { execFileSync } from "node:child_process";
43
43
  import type { Release } from "./release-store";
44
+ import { stampedChanges, type ReleaseVersionConfig } from "./release-version";
44
45
  import { createRedactor, type Redactor } from "./publish-credentials";
45
46
 
46
47
  /** Whether this run can sign provenance with an OIDC token, and why not when it can't. */
@@ -421,7 +422,10 @@ export async function preparePublish(req: {
421
422
  }
422
423
  // A target publishes files from this checkout, so they must be the release commit's (#4047).
423
424
  if (targets.length > 0) {
424
- const refused = checkCheckoutIsRelease(cwd, release.commit, name);
425
+ // #4840: the files release.version names may carry the label, as the publish job's `chant release stamp` writes them.
426
+ const { loadChantConfig } = await import("../config");
427
+ const version = (await loadChantConfig(cwd)).config.release?.version;
428
+ const refused = checkCheckoutIsRelease(cwd, release.commit, name, version ? { version, label } : {});
425
429
  if (refused) return { refusal: refused };
426
430
  }
427
431
 
@@ -455,8 +459,16 @@ export async function preparePublish(req: {
455
459
  * checkout is the release's commit with nothing changed, so a publish refuses
456
460
  * a `HEAD` that is another commit and a tree with changes git sees. A publish
457
461
  * with no target reads nothing and checks neither.
462
+ *
463
+ * Under `release.version` (#4840), a file it names that is exactly the
464
+ * commit's stamped with the release's label is the commit's too.
458
465
  */
459
- export function checkCheckoutIsRelease(cwd: string, commit: string, name: string): PublishRefusal | null {
466
+ export function checkCheckoutIsRelease(
467
+ cwd: string,
468
+ commit: string,
469
+ name: string,
470
+ o: { version?: ReleaseVersionConfig; label?: string | null } = {},
471
+ ): PublishRefusal | null {
460
472
  const head = tryGit(cwd, ["rev-parse", "HEAD"]);
461
473
  if (head !== commit) {
462
474
  return {
@@ -465,7 +477,8 @@ export function checkCheckoutIsRelease(cwd: string, commit: string, name: string
465
477
  fix: `Check out the release's commit, as a CI job on its tag does: git checkout ${commit}`,
466
478
  };
467
479
  }
468
- const status = tryGit(cwd, ["status", "--porcelain", "--untracked-files=normal"]);
480
+ let status = tryGit(cwd, ["status", "--porcelain", "--untracked-files=normal"]);
481
+ if (status && o.version) status = withoutStamps(cwd, commit, o.version, o.label ?? null, status);
469
482
  if (status) {
470
483
  const n = status.split("\n").length;
471
484
  return {
@@ -477,6 +490,24 @@ export function checkCheckoutIsRelease(cwd: string, commit: string, name: string
477
490
  return null;
478
491
  }
479
492
 
493
+ /** The porcelain status without the files {@link stampedChanges} takes as the commit's stamped with the label. */
494
+ function withoutStamps(cwd: string, commit: string, version: ReleaseVersionConfig, label: string | null, status: string): string {
495
+ let raw: string;
496
+ let top: string;
497
+ try {
498
+ raw = execFileSync("git", ["status", "--porcelain", "--untracked-files=normal"], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
499
+ top = execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
500
+ } catch {
501
+ return status;
502
+ }
503
+ const stamped = stampedChanges({ cwd, top, commit, config: version, label, status: raw });
504
+ return raw
505
+ .split("\n")
506
+ .filter((l) => l.length > 0 && !stamped.has(l.slice(3)))
507
+ .join("\n")
508
+ .trim();
509
+ }
510
+
480
511
  function tryGit(cwd: string, args: string[]): string | null {
481
512
  try {
482
513
  return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
@@ -0,0 +1,155 @@
1
+ /**
2
+ * #4840: `release.version` stamps the release's label into package.json at
3
+ * the cut and the publish, so a product needs no version-bump commit.
4
+ */
5
+
6
+ import { afterAll, describe, expect, test } from "vitest";
7
+ import { readFileSync, rmSync } from "node:fs";
8
+ import { dirname, join } from "node:path";
9
+ import { cutRelease, ReleaseCutError } from "./release-cut";
10
+ import { checkCheckoutIsRelease } from "./release-publish";
11
+ import { checkVersionLabel, releaseVersionFiles, ReleaseVersionError, stampedChanges, stampReleaseVersion, stampText, type ReleaseVersionConfig } from "./release-version";
12
+ import type { CompiledTarget, TargetCompiler } from "../components/release-compile";
13
+ import { TestRepo } from "../workspace/trust/test-repo";
14
+ import { ChantConfigSchema } from "../config";
15
+
16
+ const repos: TestRepo[] = [];
17
+ afterAll(() => {
18
+ for (const r of repos) rmSync(dirname(r.dir), { recursive: true, force: true });
19
+ });
20
+
21
+ const PKG = `{\n "name": "@acme/cli",\n "version": "0.4.52",\n "dependencies": {\n "@intentius/chant": "0.124.77"\n }\n}\n`;
22
+ const ROOT = `{\n "name": "acme",\n "private": true,\n "workspaces": ["packages/*"]\n}\n`;
23
+ const LOCK = `{\n "name": "acme",\n "lockfileVersion": 3,\n "requires": true,\n "packages": {\n "": {\n "name": "acme",\n "workspaces": [\n "packages/*"\n ]\n },\n "packages/cli": {\n "name": "@acme/cli",\n "version": "0.4.52"\n },\n "node_modules/@acme/cli": {\n "resolved": "packages/cli",\n "link": true\n }\n }\n}\n`;
24
+
25
+ /** A workspace with one package, as terragucci's is, committed and green. */
26
+ function workspace(label: string): { r: TestRepo; head: string } {
27
+ const r = new TestRepo(label);
28
+ repos.push(r);
29
+ r.write("chant.config.ts", `export default { environments: ["dev"] };\n`);
30
+ r.write("package.json", ROOT);
31
+ r.write("package-lock.json", LOCK);
32
+ r.write("packages/cli/package.json", PKG);
33
+ const head = r.commit("init");
34
+ r.git(["tag", `ci/green/${head}`]);
35
+ return { r, head };
36
+ }
37
+
38
+ const CONFIG: ReleaseVersionConfig = { packages: ["packages/cli"] };
39
+
40
+ describe("stamping the label (#4840)", () => {
41
+ test("a package.json changes in its version alone, and a lockfile in the package's entry", () => {
42
+ expect(stampText(PKG, "0.4.53", "package")).toBe(PKG.replace(`"version": "0.4.52"`, `"version": "0.4.53"`));
43
+ expect(stampText(LOCK, "0.4.53", "lockfile", ["packages/cli"])).toBe(LOCK.replace(`"version": "0.4.52"`, `"version": "0.4.53"`));
44
+ // The member's own package: the root entry and the lockfile's top-level version.
45
+ const rootLock = `{\n "name": "yodel",\n "version": "0.12.1",\n "lockfileVersion": 3,\n "packages": {\n "": {\n "name": "yodel",\n "version": "0.12.1"\n }\n }\n}\n`;
46
+ expect(stampText(rootLock, "0.13.0", "lockfile", ["."])).toBe(rootLock.replaceAll("0.12.1", "0.13.0"));
47
+ // A tab-indented file keeps its tabs.
48
+ expect(stampText(`{\n\t"name": "a",\n\t"version": "1.0.0"\n}\n`, "1.0.1", "package")).toBe(`{\n\t"name": "a",\n\t"version": "1.0.1"\n}\n`);
49
+ });
50
+
51
+ test("the files are each package's package.json and the lockfile when there is one", () => {
52
+ const { r } = workspace("release-version-files");
53
+ expect(releaseVersionFiles(r.dir, CONFIG)).toEqual(["packages/cli/package.json", "package-lock.json"]);
54
+ expect(releaseVersionFiles(r.dir, { packages: ["."], lockfile: false })).toEqual(["package.json"]);
55
+ });
56
+
57
+ test("stamp, then restore, puts every file back byte for byte", () => {
58
+ const { r } = workspace("release-version-restore");
59
+ const s = stampReleaseVersion({ cwd: r.dir, config: CONFIG, label: "0.4.53" });
60
+ expect(JSON.parse(readFileSync(join(r.dir, "packages/cli/package.json"), "utf-8")).version).toBe("0.4.53");
61
+ expect(JSON.parse(readFileSync(join(r.dir, "package-lock.json"), "utf-8")).packages["packages/cli"].version).toBe("0.4.53");
62
+ s.restore();
63
+ expect(readFileSync(join(r.dir, "packages/cli/package.json"), "utf-8")).toBe(PKG);
64
+ expect(readFileSync(join(r.dir, "package-lock.json"), "utf-8")).toBe(LOCK);
65
+ expect(r.git(["status", "--porcelain"])).toBe("");
66
+ });
67
+
68
+ test("a label npm can't take as a version, no label, and a missing package are refused before anything is written", () => {
69
+ expect(() => checkVersionLabel(null)).toThrow(ReleaseVersionError);
70
+ expect(() => checkVersionLabel("v1.4.0")).toThrow(/"v1.4.0" is not a version npm takes/);
71
+ expect((() => { try { checkVersionLabel("v1.4.0"); } catch (e) { return (e as ReleaseVersionError).fix; } })()).toBe("Label the release MAJOR.MINOR.PATCH, such as 1.4.0, with no v.");
72
+ expect(() => checkVersionLabel("1.4")).toThrow(/not a version/);
73
+ expect(() => checkVersionLabel("1.4.0-rc.1")).not.toThrow();
74
+ const { r } = workspace("release-version-refuse");
75
+ expect(() => stampReleaseVersion({ cwd: r.dir, config: { packages: ["packages/cli", "packages/nope"] }, label: "0.4.53" })).toThrow(/packages\/nope\/package.json, which does not exist/);
76
+ expect(r.git(["status", "--porcelain"])).toBe("");
77
+ expect(() => stampReleaseVersion({ cwd: r.dir, config: { packages: ["../other"] }, label: "0.4.53" })).toThrow(/not a path inside the member/);
78
+ });
79
+
80
+ test("chant.config.ts takes release.version, and refuses a misspelt key", () => {
81
+ expect(ChantConfigSchema.safeParse({ release: { version: { packages: ["packages/cli"], lockfile: false } } }).success).toBe(true);
82
+ expect(ChantConfigSchema.safeParse({ release: { version: { package: ["packages/cli"] } } }).success).toBe(false);
83
+ expect(ChantConfigSchema.safeParse({ release: { version: { packages: [] } } }).success).toBe(false);
84
+ });
85
+ });
86
+
87
+ describe("the publish takes a stamped tree as the commit's (#4840)", () => {
88
+ test("only the named files, stamped with this release's label, pass the checkout check", () => {
89
+ const { r, head } = workspace("release-version-publish");
90
+ // Today's check, with no release.version: a stamped tree is dirty.
91
+ stampReleaseVersion({ cwd: r.dir, config: CONFIG, label: "0.4.53" });
92
+ expect(checkCheckoutIsRelease(r.dir, head, "0.4.53")?.code).toBe("release-worktree-dirty");
93
+ expect(checkCheckoutIsRelease(r.dir, head, "0.4.53", { version: CONFIG, label: "0.4.53" })).toBeNull();
94
+ // Another release's label is not this one's.
95
+ expect(checkCheckoutIsRelease(r.dir, head, "0.4.54", { version: CONFIG, label: "0.4.54" })?.code).toBe("release-worktree-dirty");
96
+ // Any other change in a stamped file, or another file changed, is still dirty.
97
+ r.write("README.md", "changed\n");
98
+ expect(checkCheckoutIsRelease(r.dir, head, "0.4.53", { version: CONFIG, label: "0.4.53" })?.code).toBe("release-worktree-dirty");
99
+ r.git(["checkout", "--", "."]);
100
+ r.git(["clean", "-fdq"]);
101
+ r.write("packages/cli/package.json", PKG.replace("0.4.52", "0.4.53").replace("0.124.77", "0.124.78"));
102
+ expect(stampedChanges({ cwd: r.dir, top: r.dir, commit: head, config: CONFIG, label: "0.4.53", status: r.git(["status", "--porcelain"]) }).size).toBe(0);
103
+ });
104
+ });
105
+
106
+ describe("the cut stamps after its clean-tree check and before it builds (#4840)", () => {
107
+ test("the images and the compile read the label from package.json, and the tree is the commit's after", async () => {
108
+ const { r } = workspace("release-version-cut");
109
+ const seen: string[] = [];
110
+ const version = () => JSON.parse(readFileSync(join(r.dir, "packages/cli/package.json"), "utf-8")).version as string;
111
+ const compiler: TargetCompiler = {
112
+ async compile(env): Promise<CompiledTarget> {
113
+ seen.push(`compile ${version()}`);
114
+ return { env, params: [], components: [], buildSteps: {}, buildInputs: {}, componentFiles: {}, templates: [{ component: null, path: "dist/out.json", content: "{}\n" }] };
115
+ },
116
+ async buildArtifacts() {
117
+ return [];
118
+ },
119
+ };
120
+ let stamped: ReturnType<typeof stampReleaseVersion> | null = null;
121
+ try {
122
+ await cutRelease({
123
+ cwd: r.dir,
124
+ compiler,
125
+ label: "0.4.53",
126
+ actor: "alice",
127
+ env: {},
128
+ now: () => new Date("2026-11-08T10:00:00.000Z"),
129
+ stamp: () => {
130
+ seen.push(`stamp ${version()}`);
131
+ stamped = stampReleaseVersion({ cwd: r.dir, config: CONFIG, label: "0.4.53" });
132
+ },
133
+ buildImages: () => {
134
+ seen.push(`images ${version()}`);
135
+ return [];
136
+ },
137
+ });
138
+ } finally {
139
+ (stamped as ReturnType<typeof stampReleaseVersion> | null)?.restore();
140
+ }
141
+ expect(seen).toEqual(["stamp 0.4.52", "images 0.4.53", "compile 0.4.53"]);
142
+ expect(r.git(["status", "--porcelain"])).toBe("");
143
+ });
144
+
145
+ test("a dirty tree is refused before anything is stamped", async () => {
146
+ const { r } = workspace("release-version-cut-dirty");
147
+ r.write("packages/cli/package.json", PKG.replace("0.4.52", "9.9.9"));
148
+ let called = false;
149
+ const compiler: TargetCompiler = { async compile(env) { return { env, params: [], components: [], buildSteps: {}, buildInputs: {}, componentFiles: {}, templates: [] }; }, async buildArtifacts() { return []; } };
150
+ const err = await cutRelease({ cwd: r.dir, compiler, label: "0.4.53", actor: "alice", env: {}, stamp: () => { called = true; } }).catch((e: unknown) => e);
151
+ expect(err).toBeInstanceOf(ReleaseCutError);
152
+ expect((err as ReleaseCutError).code).toBe("release-worktree-dirty");
153
+ expect(called).toBe(false);
154
+ });
155
+ });