@intentius/chant 0.124.77 → 0.124.79

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 (228) hide show
  1. package/dist/__fixtures__/notify-messages/events.d.ts +9 -0
  2. package/dist/__fixtures__/notify-messages/events.d.ts.map +1 -0
  3. package/dist/__fixtures__/notify-messages/events.js +21 -0
  4. package/dist/__fixtures__/product-words.d.ts +14 -0
  5. package/dist/__fixtures__/product-words.d.ts.map +1 -1
  6. package/dist/__fixtures__/product-words.js +11 -0
  7. package/dist/__fixtures__/terragucci-notify.d.ts +66 -0
  8. package/dist/__fixtures__/terragucci-notify.d.ts.map +1 -0
  9. package/dist/__fixtures__/terragucci-notify.js +133 -0
  10. package/dist/action-pins.d.ts +8 -0
  11. package/dist/action-pins.d.ts.map +1 -1
  12. package/dist/action-pins.js +8 -0
  13. package/dist/agent-guard.d.ts.map +1 -1
  14. package/dist/agent-guard.js +1 -2
  15. package/dist/change-set.d.ts +10 -1
  16. package/dist/change-set.d.ts.map +1 -1
  17. package/dist/change-set.js +4 -1
  18. package/dist/ci-agent.d.ts +16 -2
  19. package/dist/ci-agent.d.ts.map +1 -1
  20. package/dist/ci-agent.js +6 -1
  21. package/dist/ci-commit.d.ts +66 -2
  22. package/dist/ci-commit.d.ts.map +1 -1
  23. package/dist/ci-commit.js +147 -19
  24. package/dist/ci-own-jobs.d.ts.map +1 -1
  25. package/dist/ci-own-jobs.js +1 -2
  26. package/dist/ci-product-words.d.ts +18 -4
  27. package/dist/ci-product-words.d.ts.map +1 -1
  28. package/dist/ci-product-words.js +26 -6
  29. package/dist/ci-product.d.ts +7 -3
  30. package/dist/ci-product.d.ts.map +1 -1
  31. package/dist/ci-product.js +8 -5
  32. package/dist/cli/handlers/release.d.ts +8 -0
  33. package/dist/cli/handlers/release.d.ts.map +1 -1
  34. package/dist/cli/handlers/release.js +68 -6
  35. package/dist/cli/handlers/run-wave.js +1 -0
  36. package/dist/cli/main.d.ts.map +1 -1
  37. package/dist/cli/main.js +7 -0
  38. package/dist/cli/mcp/product-tools.d.ts +6 -0
  39. package/dist/cli/mcp/product-tools.d.ts.map +1 -1
  40. package/dist/cli/mcp/product-tools.js +7 -0
  41. package/dist/cli/mcp/read-only.d.ts +12 -0
  42. package/dist/cli/mcp/read-only.d.ts.map +1 -1
  43. package/dist/cli/mcp/read-only.js +16 -0
  44. package/dist/cli/mcp/server.d.ts +11 -0
  45. package/dist/cli/mcp/server.d.ts.map +1 -1
  46. package/dist/cli/mcp/server.js +26 -5
  47. package/dist/cli/mcp/types.d.ts +5 -1
  48. package/dist/cli/mcp/types.d.ts.map +1 -1
  49. package/dist/components/capability.d.ts +42 -0
  50. package/dist/components/capability.d.ts.map +1 -1
  51. package/dist/components/group-digest.d.ts +17 -0
  52. package/dist/components/group-digest.d.ts.map +1 -0
  53. package/dist/components/group-digest.js +18 -0
  54. package/dist/components/groups.d.ts +2 -11
  55. package/dist/components/groups.d.ts.map +1 -1
  56. package/dist/components/groups.js +2 -12
  57. package/dist/components/index.d.ts +1 -1
  58. package/dist/components/index.d.ts.map +1 -1
  59. package/dist/components/pr-env-components.d.ts.map +1 -1
  60. package/dist/components/pr-env-components.js +1 -2
  61. package/dist/config.d.ts +28 -8
  62. package/dist/config.d.ts.map +1 -1
  63. package/dist/config.js +21 -1
  64. package/dist/lexicon.d.ts +8 -0
  65. package/dist/lexicon.d.ts.map +1 -1
  66. package/dist/lexicon.js +8 -0
  67. package/dist/lifecycle/release-cut.d.ts +7 -1
  68. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  69. package/dist/lifecycle/release-cut.js +1 -0
  70. package/dist/lifecycle/release-images.d.ts +86 -3
  71. package/dist/lifecycle/release-images.d.ts.map +1 -1
  72. package/dist/lifecycle/release-images.js +131 -6
  73. package/dist/lifecycle/release-publish.d.ts +8 -1
  74. package/dist/lifecycle/release-publish.d.ts.map +1 -1
  75. package/dist/lifecycle/release-publish.js +30 -3
  76. package/dist/lifecycle/release-version.d.ts +86 -0
  77. package/dist/lifecycle/release-version.d.ts.map +1 -0
  78. package/dist/lifecycle/release-version.js +209 -0
  79. package/dist/mcp/types.d.ts +26 -0
  80. package/dist/mcp/types.d.ts.map +1 -1
  81. package/dist/notify-product.d.ts +11 -2
  82. package/dist/notify-product.d.ts.map +1 -1
  83. package/dist/notify-product.js +15 -4
  84. package/dist/notify-relay.d.ts.map +1 -1
  85. package/dist/notify-relay.js +1 -2
  86. package/dist/notify.d.ts +36 -4
  87. package/dist/notify.d.ts.map +1 -1
  88. package/dist/notify.js +31 -21
  89. package/dist/notify.schema.json +1 -0
  90. package/dist/op/activities/review-product.d.ts +111 -0
  91. package/dist/op/activities/review-product.d.ts.map +1 -0
  92. package/dist/op/activities/review-product.js +115 -0
  93. package/dist/op/gate.d.ts +17 -0
  94. package/dist/op/gate.d.ts.map +1 -1
  95. package/dist/op/gate.js +36 -0
  96. package/dist/op/index.d.ts +8 -6
  97. package/dist/op/index.d.ts.map +1 -1
  98. package/dist/op/index.js +5 -4
  99. package/dist/op/op-waves-after-plan.d.ts +76 -1
  100. package/dist/op/op-waves-after-plan.d.ts.map +1 -1
  101. package/dist/op/op-waves-after-plan.js +142 -3
  102. package/dist/op/op-waves-capability-spec.js +1 -2
  103. package/dist/op/op-waves-capability.d.ts +89 -2
  104. package/dist/op/op-waves-capability.d.ts.map +1 -1
  105. package/dist/op/op-waves-capability.js +215 -7
  106. package/dist/op/op-waves-run-hooks.d.ts +104 -0
  107. package/dist/op/op-waves-run-hooks.d.ts.map +1 -0
  108. package/dist/op/op-waves-run-hooks.js +146 -0
  109. package/dist/op/op-waves-run.d.ts +21 -0
  110. package/dist/op/op-waves-run.d.ts.map +1 -1
  111. package/dist/op/op-waves-run.js +233 -13
  112. package/dist/op/op-waves.d.ts +11 -1
  113. package/dist/op/op-waves.d.ts.map +1 -1
  114. package/dist/op/op-waves.js +7 -1
  115. package/dist/op/runtime.d.ts +2 -0
  116. package/dist/op/runtime.d.ts.map +1 -1
  117. package/dist/policy-engine.d.ts.map +1 -1
  118. package/dist/policy-engine.js +1 -2
  119. package/dist/pr-forge-reads.d.ts +124 -0
  120. package/dist/pr-forge-reads.d.ts.map +1 -0
  121. package/dist/pr-forge-reads.js +322 -0
  122. package/dist/pr-forge.d.ts +14 -0
  123. package/dist/pr-forge.d.ts.map +1 -1
  124. package/dist/pr-forge.js +21 -13
  125. package/dist/pr-plan-note.d.ts +293 -0
  126. package/dist/pr-plan-note.d.ts.map +1 -0
  127. package/dist/pr-plan-note.js +361 -0
  128. package/dist/release-floors.d.ts +13 -1
  129. package/dist/release-floors.d.ts.map +1 -1
  130. package/dist/release-floors.js +13 -1
  131. package/dist/state-export.d.ts.map +1 -1
  132. package/dist/state-export.js +1 -2
  133. package/dist/state-migration.d.ts.map +1 -1
  134. package/dist/state-migration.js +1 -2
  135. package/dist/state-unlock.d.ts.map +1 -1
  136. package/dist/state-unlock.js +1 -2
  137. package/dist/wave-runtime.mjs +314 -314
  138. package/dist/workspace/change-set.schema.json +7 -0
  139. package/dist/workspace/release-workflow.d.ts +7 -0
  140. package/dist/workspace/release-workflow.d.ts.map +1 -1
  141. package/dist/workspace/release-workflow.js +13 -2
  142. package/package.json +1 -1
  143. package/src/__fixtures__/notify-messages/events.ts +23 -0
  144. package/src/__fixtures__/notify-messages/messages.json +50 -0
  145. package/src/__fixtures__/pr-loop/terragucci-plan.note.golden.md +53 -0
  146. package/src/__fixtures__/pr-loop/terragucci-plan.note.json +83 -0
  147. package/src/__fixtures__/product-words.ts +12 -0
  148. package/src/__fixtures__/review-agent/terragucci-review.json +94 -0
  149. package/src/__fixtures__/terragucci-notify.ts +170 -0
  150. package/src/action-pins.test.ts +11 -1
  151. package/src/action-pins.ts +9 -0
  152. package/src/agent-guard.test.ts +1 -2
  153. package/src/agent-guard.ts +1 -2
  154. package/src/change-set.test.ts +20 -0
  155. package/src/change-set.ts +11 -1
  156. package/src/ci-agent.test.ts +9 -0
  157. package/src/ci-agent.ts +15 -2
  158. package/src/ci-commit.test.ts +162 -0
  159. package/src/ci-commit.ts +167 -21
  160. package/src/ci-own-jobs.test.ts +1 -2
  161. package/src/ci-own-jobs.ts +1 -2
  162. package/src/ci-product-words.ts +35 -7
  163. package/src/ci-product.ts +9 -6
  164. package/src/cli/handlers/build-pr-loop-control.test.ts +1 -2
  165. package/src/cli/handlers/build-run-group.test.ts +1 -2
  166. package/src/cli/handlers/release.ts +60 -7
  167. package/src/cli/handlers/run-wave.ts +1 -0
  168. package/src/cli/main.ts +7 -0
  169. package/src/cli/mcp/product-tools.test.ts +50 -0
  170. package/src/cli/mcp/product-tools.ts +8 -0
  171. package/src/cli/mcp/read-only.ts +19 -0
  172. package/src/cli/mcp/server.test.ts +30 -0
  173. package/src/cli/mcp/server.ts +28 -5
  174. package/src/cli/mcp/types.ts +6 -1
  175. package/src/components/capability.ts +41 -0
  176. package/src/components/group-digest.ts +20 -0
  177. package/src/components/groups.ts +3 -13
  178. package/src/components/index.ts +2 -0
  179. package/src/components/pr-env-components.test.ts +1 -2
  180. package/src/components/pr-env-components.ts +1 -2
  181. package/src/config.ts +38 -3
  182. package/src/gate-policy-bundle.test.ts +1 -1
  183. package/src/lexicon.ts +9 -0
  184. package/src/lifecycle/release-cut.ts +11 -0
  185. package/src/lifecycle/release-images-dockerfile.test.ts +229 -0
  186. package/src/lifecycle/release-images.ts +171 -8
  187. package/src/lifecycle/release-publish.ts +34 -3
  188. package/src/lifecycle/release-version.test.ts +155 -0
  189. package/src/lifecycle/release-version.ts +227 -0
  190. package/src/mcp/types.ts +27 -0
  191. package/src/notify-message-words.test.ts +185 -0
  192. package/src/notify-product.ts +16 -4
  193. package/src/notify-relay.ts +1 -2
  194. package/src/notify.schema.json +1 -0
  195. package/src/notify.ts +59 -19
  196. package/src/op/activities/review-product.test.ts +116 -0
  197. package/src/op/activities/review-product.ts +199 -0
  198. package/src/op/gate.ts +46 -0
  199. package/src/op/index.ts +10 -4
  200. package/src/op/op-waves-after-plan-wave.test.ts +226 -0
  201. package/src/op/op-waves-after-plan.ts +170 -5
  202. package/src/op/op-waves-capability-spec.ts +1 -1
  203. package/src/op/op-waves-capability.test.ts +6 -0
  204. package/src/op/op-waves-capability.ts +243 -10
  205. package/src/op/op-waves-run-hooks.test.ts +184 -0
  206. package/src/op/op-waves-run-hooks.ts +195 -0
  207. package/src/op/op-waves-run.ts +240 -16
  208. package/src/op/op-waves-step-wave.test.ts +277 -0
  209. package/src/op/op-waves.ts +15 -2
  210. package/src/op/runtime.ts +2 -0
  211. package/src/op/schedule-overdue.test.ts +26 -0
  212. package/src/policy-engine.test.ts +1 -2
  213. package/src/policy-engine.ts +1 -2
  214. package/src/pr-forge-reads.test.ts +285 -0
  215. package/src/pr-forge-reads.ts +424 -0
  216. package/src/pr-forge.ts +30 -16
  217. package/src/pr-plan-note.test.ts +105 -0
  218. package/src/pr-plan-note.ts +520 -0
  219. package/src/release-floors.ts +19 -1
  220. package/src/state-export.test.ts +1 -2
  221. package/src/state-export.ts +1 -2
  222. package/src/state-migration.test.ts +1 -2
  223. package/src/state-migration.ts +1 -2
  224. package/src/state-unlock.test.ts +1 -2
  225. package/src/state-unlock.ts +1 -2
  226. package/src/workspace/change-set.schema.json +7 -0
  227. package/src/workspace/release-workflow.test.ts +18 -0
  228. package/src/workspace/release-workflow.ts +23 -2
package/src/config.ts CHANGED
@@ -109,8 +109,30 @@ export const ChantConfigSchema = z.object({
109
109
  release: z.object({
110
110
  autoRecord: z.boolean().optional(),
111
111
  publish: z.array(PublishDeclarationSchema).optional(),
112
- images: z.array(z.object({ name: z.string().min(1), build: z.string().min(1), archive: z.string().min(1) }).strict()).optional(),
112
+ images: z
113
+ .array(
114
+ z.union([
115
+ z.object({ name: z.string().min(1), build: z.string().min(1), archive: z.string().min(1) }).strict(),
116
+ // #4819: chant builds the Dockerfile as the reproducible OCI archive itself.
117
+ z
118
+ .object({
119
+ name: z.string().min(1),
120
+ dockerfile: z.string().min(1),
121
+ context: z.string().min(1).optional(),
122
+ platforms: z.array(z.string().min(1)).min(1).optional(),
123
+ archive: z.string().min(1).optional(),
124
+ prepare: z.string().min(1).optional(),
125
+ })
126
+ .strict(),
127
+ ]),
128
+ )
129
+ .optional(),
113
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(),
114
136
  workflow: z.object({
115
137
  trigger: z.enum(["tag", "dispatch"]).optional(),
116
138
  gate: z.enum(["last-green", "head"]).optional(),
@@ -393,9 +415,12 @@ export interface ChantConfig {
393
415
  * `build` writes the OCI archive at `archive`, and the cut records its
394
416
  * digest and hands every digest to the build through `CHANT_RELEASE_DIGESTS`,
395
417
  * so a package can pin the images it ships with. An `oci` target pushes
396
- * the archive. See ./lifecycle/release-images.ts.
418
+ * the archive. An entry may name a `dockerfile` (with `context`,
419
+ * `platforms`, `archive` and `prepare`) in place of `build`, and chant
420
+ * runs the reproducible build itself (#4819). See
421
+ * ./lifecycle/release-images.ts.
397
422
  */
398
- images?: Array<{ name: string; build: string; archive: string }>;
423
+ images?: import("./lifecycle/release-images").ReleaseImageDeclaration[];
399
424
  /**
400
425
  * The green lane `chant release cut` and `chant release candidates` check
401
426
  * when `--lane` is not given (#4692): one `ci.green.lanes` declares in
@@ -403,6 +428,16 @@ export interface ChantConfig {
403
428
  * rather than `ci/green/<sha>`.
404
429
  */
405
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;
406
441
  /**
407
442
  * The release pipeline `chant release workflow` writes (#4656): a
408
443
  * dispatched release with gate, cut, publish and post-release jobs, the
@@ -37,6 +37,6 @@ describe("the gate-policy bundle", () => {
37
37
  outdir: "out",
38
38
  logLevel: "silent",
39
39
  });
40
- expect(Object.keys(result.metafile.inputs).map((i) => i.replace(/^.*?packages\//, "packages/")).sort()).toEqual(["packages/core/src/policy-engine.ts", "packages/core/src/release-floors.ts"]);
40
+ expect(Object.keys(result.metafile.inputs).map((i) => i.replace(/^.*?packages\//, "packages/")).sort()).toEqual(["packages/core/src/policy-engine.ts"]);
41
41
  });
42
42
  });
package/src/lexicon.ts CHANGED
@@ -1314,6 +1314,15 @@ export interface CompositeEntry {
1314
1314
  archetype?: Archetype;
1315
1315
  }
1316
1316
 
1317
+ /**
1318
+ * The first chant whose Pulumi lexicon's ci-setup installs a release without
1319
+ * linking it onto PATH (`link: false`) and exports the fetch-and-check script
1320
+ * for image builds (`ciFetchScript`, #4814). It lives here, beside
1321
+ * {@link LexiconPlugin.ciSetup}, so it freezes with chant's release; the
1322
+ * lexicon re-exports it as `PULUMI_CI_SETUP_FLOOR`.
1323
+ */
1324
+ export const CI_SETUP_UNLINKED_FLOOR = "0.124.78";
1325
+
1317
1326
  export interface LexiconPlugin {
1318
1327
  // ── Required ──────────────────────────────────────────────
1319
1328
  /** Human-readable name (e.g. "aws", "gcp") */
@@ -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) {
@@ -0,0 +1,229 @@
1
+ /**
2
+ * #4819: a `release.images` entry that names a Dockerfile, which chant builds
3
+ * as the reproducible OCI archive itself, and the helpers that turn the cut's
4
+ * digests file and a product's `{ name: reference }` into the table its
5
+ * bundle bakes in and the pins file its npm target reads. terragucci's and
6
+ * plywood's `scripts/release-image.sh` and `releaseDigests` are what these
7
+ * replace; the expectations below are what those wrote.
8
+ */
9
+
10
+ import { spawnSync } from "node:child_process";
11
+ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
12
+ import { tmpdir } from "node:os";
13
+ import { join } from "node:path";
14
+ import { describe, expect, test } from "vitest";
15
+ import { ChantConfigSchema } from "../config";
16
+ import {
17
+ buildReleaseImages,
18
+ checkReleaseImages,
19
+ RELEASE_DIGESTS_ENV,
20
+ RELEASE_IMAGE_BUILDER,
21
+ RELEASE_IMAGE_DOCKERFILE_FLOOR,
22
+ releaseImageBuildCommand,
23
+ releaseImagePins,
24
+ ReleaseImageError,
25
+ resolveReleaseImages,
26
+ writeReleaseImagePins,
27
+ type ReleaseImageDeclaration,
28
+ } from "./release-images";
29
+
30
+ const D = (c: string) => `sha256:${c.repeat(64)}`;
31
+ const scratch = () => mkdtempSync(join(tmpdir(), "chant-release-image-"));
32
+
33
+ describe("a release.images entry that names a Dockerfile (#4819)", () => {
34
+ test("chant builds it the way both products' release-image.sh did", () => {
35
+ expect(releaseImageBuildCommand({ name: "pulumi", dockerfile: "images/plywood-pulumi/Dockerfile" })).toBe(
36
+ [
37
+ `{ docker buildx inspect ${RELEASE_IMAGE_BUILDER} >/dev/null 2>&1 || docker buildx create --name ${RELEASE_IMAGE_BUILDER} --driver docker-container >/dev/null; }`,
38
+ "mkdir -p dist/images",
39
+ 'docker buildx build --builder chant-release --no-cache --platform linux/amd64,linux/arm64 --provenance=false --sbom=false --build-arg SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" --output type=oci,dest=dist/images/pulumi.tar,rewrite-timestamp=true -f images/plywood-pulumi/Dockerfile . >&2',
40
+ ].join(" && "),
41
+ );
42
+ const own = releaseImageBuildCommand({ name: "tofu", dockerfile: "images/Dockerfile.tofu", context: "images/ctx", platforms: ["linux/amd64"], archive: "out/tofu image.tar" });
43
+ expect(own).toContain("--platform linux/amd64 ");
44
+ expect(own).toContain("--output 'type=oci,dest=out/tofu image.tar,rewrite-timestamp=true' -f images/Dockerfile.tofu images/ctx >&2");
45
+ expect(own).toContain("mkdir -p out && ");
46
+ });
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
+
57
+ test("the archive defaults to dist/images/<name>.tar, and a build entry is as it was", () => {
58
+ const images: ReleaseImageDeclaration[] = [
59
+ { name: "pulumi", dockerfile: "images/plywood-pulumi/Dockerfile" },
60
+ { name: "old", build: "scripts/release-image.sh old", archive: "dist/images/old.tar" },
61
+ ];
62
+ expect(resolveReleaseImages(images).map((i) => [i.name, i.archive])).toEqual([
63
+ ["pulumi", "dist/images/pulumi.tar"],
64
+ ["old", "dist/images/old.tar"],
65
+ ]);
66
+ expect(resolveReleaseImages(images)[1]).toEqual({ name: "old", build: "scripts/release-image.sh old", archive: "dist/images/old.tar" });
67
+ });
68
+
69
+ test("the prepare command runs once, before the builds, with no digests file named", () => {
70
+ const cwd = scratch();
71
+ const runs: { command: string; digests: string | undefined; epoch: string | undefined }[] = [];
72
+ const prepare = "npm run build && npm pack -w @intentius/plywood --pack-destination images/pack";
73
+ const built = buildReleaseImages({
74
+ images: [
75
+ { name: "pulumi", dockerfile: "images/plywood-pulumi/Dockerfile", prepare },
76
+ { name: "plunge", dockerfile: "images/plywood-plunge/Dockerfile", prepare },
77
+ ],
78
+ cwd,
79
+ sourceDateEpoch: 1_700_000_000,
80
+ label: "0.3.0",
81
+ env: { PATH: process.env.PATH, [RELEASE_DIGESTS_ENV]: "/tmp/stale.json" },
82
+ archiveDigest: (abs) => (abs.endsWith("pulumi.tar") ? D("a") : D("b")),
83
+ run: (command, o) => {
84
+ runs.push({ command, digests: o.env[RELEASE_DIGESTS_ENV], epoch: o.env.SOURCE_DATE_EPOCH });
85
+ const m = /dest=([^,]+),/.exec(command);
86
+ if (m) {
87
+ mkdirSync(join(cwd, "dist/images"), { recursive: true });
88
+ writeFileSync(join(cwd, m[1]!), "");
89
+ }
90
+ return 0;
91
+ },
92
+ });
93
+ expect(runs.map((r) => r.command.slice(0, 20))).toEqual([prepare.slice(0, 20), "{ docker buildx insp", "{ docker buildx insp"]);
94
+ expect(runs[0]!.digests).toBeUndefined();
95
+ expect(runs.every((r) => r.epoch === "1700000000")).toBe(true);
96
+ expect(built).toEqual([
97
+ { component: "pulumi", kind: "image", path: "dist/images/pulumi.tar", digest: D("a") },
98
+ { component: "plunge", kind: "image", path: "dist/images/plunge.tar", digest: D("b") },
99
+ ]);
100
+ });
101
+
102
+ test("run: the command reaches docker as the argv both scripts passed", () => {
103
+ const cwd = scratch();
104
+ const bin = join(cwd, "bin");
105
+ mkdirSync(bin);
106
+ const log = join(cwd, "docker.log");
107
+ // A docker that records its argv, and writes the archive --output names.
108
+ writeFileSync(
109
+ join(bin, "docker"),
110
+ `#!/bin/sh\nprintf '%s\\n' "$*" >> "${log}"\nfor a in "$@"; do case "$a" in type=oci,dest=*) d="\${a#type=oci,dest=}"; d="\${d%%,*}"; : > "$d" ;; esac; done\nexit 0\n`,
111
+ );
112
+ chmodSync(join(bin, "docker"), 0o755);
113
+ buildReleaseImages({
114
+ images: [{ name: "tofu", dockerfile: "images/Dockerfile.tofu" }],
115
+ cwd,
116
+ sourceDateEpoch: 42,
117
+ label: null,
118
+ env: { ...process.env, PATH: `${bin}:${process.env.PATH}` },
119
+ archiveDigest: () => D("c"),
120
+ });
121
+ const calls = readFileSync(log, "utf-8").trim().split("\n");
122
+ expect(calls).toEqual([
123
+ "buildx inspect chant-release",
124
+ "buildx build --builder chant-release --no-cache --platform linux/amd64,linux/arm64 --provenance=false --sbom=false --build-arg SOURCE_DATE_EPOCH=42 --output type=oci,dest=dist/images/tofu.tar,rewrite-timestamp=true -f images/Dockerfile.tofu .",
125
+ ]);
126
+ expect(existsSync(join(cwd, "dist/images/tofu.tar"))).toBe(true);
127
+ });
128
+
129
+ test("an entry with both build and dockerfile, a path outside the member, or a bad platform is refused", () => {
130
+ const refused = (i: unknown) => {
131
+ try {
132
+ checkReleaseImages([i as ReleaseImageDeclaration]);
133
+ return "";
134
+ } catch (e) {
135
+ return (e as ReleaseImageError).code;
136
+ }
137
+ };
138
+ expect(refused({ name: "a", dockerfile: "D", build: "x", archive: "a.tar" })).toBe("release-image-invalid");
139
+ expect(refused({ name: "a", dockerfile: "../D" })).toBe("release-image-archive-outside");
140
+ expect(refused({ name: "a", dockerfile: "D", context: "/abs" })).toBe("release-image-archive-outside");
141
+ expect(refused({ name: "a", dockerfile: "D", platforms: ["linux/amd64; rm"] })).toBe("release-image-invalid");
142
+ expect(refused({ name: "a", dockerfile: "D", platforms: [] })).toBe("release-image-invalid");
143
+ expect(refused({ name: "a", dockerfile: "D", platforms: ["linux/arm64/v8"] })).toBe("");
144
+ });
145
+
146
+ test("chant.config.ts takes either form", () => {
147
+ const ok = (images: unknown) => ChantConfigSchema.safeParse({ release: { images } }).success;
148
+ expect(ok([{ name: "pulumi", dockerfile: "images/plywood-pulumi/Dockerfile", context: ".", platforms: ["linux/amd64"], archive: "dist/images/pulumi.tar", prepare: "npm run build" }])).toBe(true);
149
+ expect(ok([{ name: "old", build: "x", archive: "a.tar" }])).toBe(true);
150
+ expect(ok([{ name: "old", build: "x" }])).toBe(false);
151
+ expect(ok([{ name: "both", build: "x", archive: "a.tar", dockerfile: "D" }])).toBe(false);
152
+ });
153
+
154
+ test("the floor names the next release", () => expect(RELEASE_IMAGE_DOCKERFILE_FLOOR).toBe("0.124.78"));
155
+ });
156
+
157
+ describe("the digest table and the pins file (#4819)", () => {
158
+ const digestsFile = (named: Record<string, string>) => {
159
+ const f = join(scratch(), "digests.json");
160
+ writeFileSync(f, JSON.stringify(named));
161
+ return f;
162
+ };
163
+
164
+ test("outside a release build there is no table, and the pins file is removed", () => {
165
+ const dir = scratch();
166
+ const out = join(dir, "dist/image-digests.json");
167
+ mkdirSync(join(dir, "dist"));
168
+ writeFileSync(out, "{}\n");
169
+ const table = releaseImagePins({ images: { pulumi: "ghcr.io/intentius/plywood-pulumi:0.3.0-pulumi3.272.0" }, version: "0.3.0", env: {} });
170
+ expect(table).toBeUndefined();
171
+ writeReleaseImagePins(table, { out });
172
+ expect(existsSync(out)).toBe(false);
173
+ });
174
+
175
+ test("plywood's table: each image's reference at the version, to the digest the cut recorded", () => {
176
+ const file = digestsFile({ plunge: D("b"), pulumi: D("a") });
177
+ const images = { pulumi: "ghcr.io/intentius/plywood-pulumi:0.3.0-pulumi3.272.0", plunge: "ghcr.io/intentius/plywood-plunge:0.3.0-plunge0.2.0" };
178
+ const table = releaseImagePins({ images, version: "0.3.0", env: { [RELEASE_DIGESTS_ENV]: file, CHANT_RELEASE_LABEL: "0.3.0" } });
179
+ expect(table).toEqual({ "ghcr.io/intentius/plywood-pulumi:0.3.0-pulumi3.272.0": D("a"), "ghcr.io/intentius/plywood-plunge:0.3.0-plunge0.2.0": D("b") });
180
+ expect(Object.keys(table!)).toEqual(Object.values(images));
181
+
182
+ const dir = scratch();
183
+ const bundle = join(dir, "plywood.mjs");
184
+ writeFileSync(bundle, `const digests = ${JSON.stringify(table)};\n`);
185
+ const out = join(dir, "dist/image-digests.json");
186
+ writeReleaseImagePins(table, { out, bundles: [bundle] });
187
+ // The bytes both build-cli.mjs scripts wrote.
188
+ expect(readFileSync(out, "utf-8")).toBe(`${JSON.stringify(table, null, 2)}\n`);
189
+ });
190
+
191
+ test("terragucci's table, for its four images", () => {
192
+ const names = ["tofu", "terraform", "terragrunt", "choudoufu"];
193
+ const file = digestsFile(Object.fromEntries(names.map((n, i) => [n, D(String(i + 1))])));
194
+ const images = Object.fromEntries(names.map((n) => [n, `ghcr.io/intentius/terragucci-${n}:0.4.51-${n}`]));
195
+ const table = releaseImagePins({ images, version: "0.4.51", env: { [RELEASE_DIGESTS_ENV]: file } })!;
196
+ expect(Object.entries(table)).toEqual(names.map((n, i) => [`ghcr.io/intentius/terragucci-${n}:0.4.51-${n}`, D(String(i + 1))]));
197
+ });
198
+
199
+ test("a label that is not the version, a missing digest, and a bundle without the digests are refused", () => {
200
+ const file = digestsFile({ pulumi: D("a"), plunge: "latest" });
201
+ const code = (f: () => unknown) => {
202
+ try {
203
+ f();
204
+ return "";
205
+ } catch (e) {
206
+ return `${(e as ReleaseImageError).code}: ${(e as Error).message}`;
207
+ }
208
+ };
209
+ expect(code(() => releaseImagePins({ images: { pulumi: "r" }, version: "0.3.0", env: { [RELEASE_DIGESTS_ENV]: file, CHANT_RELEASE_LABEL: "0.3.1" } }))).toBe(
210
+ "release-label-not-version: the release is labelled 0.3.1, and the package is at 0.3.0",
211
+ );
212
+ expect(code(() => releaseImagePins({ images: { plunge: "r" }, version: "0.3.0", env: { [RELEASE_DIGESTS_ENV]: file } }))).toBe(
213
+ `release-image-digest-missing: ${file} has no digest for the plunge image, which the release builds`,
214
+ );
215
+ const dir = scratch();
216
+ const bundle = join(dir, "b.mjs");
217
+ writeFileSync(bundle, "nothing here\n");
218
+ expect(code(() => writeReleaseImagePins({ "ghcr.io/x:1": D("a") }, { out: join(dir, "p.json"), bundles: [bundle] }))).toBe(`release-pin-not-bundled: ${bundle} does not carry ghcr.io/x:1@${D("a")}`);
219
+ expect(existsSync(join(dir, "p.json"))).toBe(false);
220
+ });
221
+
222
+ test("plain Node loads the module a product's build script imports", () => {
223
+ // The products' build-cli.mjs run under node with no TypeScript loader; the module must reach only node: built-ins at run time.
224
+ const src = readFileSync(join(__dirname, "release-images.ts"), "utf-8");
225
+ const runtime = [...src.matchAll(/^import (?!type)[^;]*from "([^"]+)";/gm)].map((m) => m[1]);
226
+ expect(runtime.filter((s) => !s!.startsWith("node:") && s !== "../release-floors")).toEqual([]);
227
+ expect(spawnSync("node", ["--version"]).status).toBe(0);
228
+ });
229
+ });
@@ -21,11 +21,23 @@
21
21
  * An npm target's `pins` names the file in a package that carries the
22
22
  * digests. The publish plan and `chant release verify` read it and refuse a
23
23
  * digest the release does not record as an image.
24
+ *
25
+ * An entry may name a Dockerfile instead of a command (#4819): chant runs
26
+ * the reproducible build itself ({@link releaseImageBuildCommand}), a
27
+ * `docker-container` buildx builder writing an OCI archive with timestamps
28
+ * rewritten from `SOURCE_DATE_EPOCH` and no attestations, for every
29
+ * platform. Its `prepare` command (the bundle the image carries, a packed
30
+ * package) runs first with no digests file named, so the image is the same
31
+ * in the cut and the publish job. A product's package build turns the
32
+ * digests file and its `{ name: reference }` into the table it bakes in with
33
+ * {@link releaseImagePins}, and writes the pins file with
34
+ * {@link writeReleaseImagePins}. This module reaches only Node's built-ins at
35
+ * run time, so a product's build script imports it under plain Node.
24
36
  */
25
37
 
26
38
  import { spawnSync } from "node:child_process";
27
- import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
28
- import { dirname, isAbsolute, relative, resolve } from "node:path";
39
+ import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
40
+ import { dirname, isAbsolute, posix, relative, resolve } from "node:path";
29
41
  import type { PublishDeclaration } from "./publish-declaration";
30
42
  import type { Release, ReleaseArtifact } from "./release-store";
31
43
 
@@ -35,8 +47,15 @@ export const RELEASE_DIGESTS_ENV = "CHANT_RELEASE_DIGESTS";
35
47
  /** The first chant with `release.images`, `CHANT_RELEASE_DIGESTS`, `chant release images` and an npm target's `pins` (#4657). Products feature-detect on it. */
36
48
  export const RELEASE_IMAGES_FLOOR = "0.124.71";
37
49
 
38
- /** One image a release builds in its cut. */
39
- export interface ReleaseImageDeclaration {
50
+ /**
51
+ * The first chant whose `release.images` takes a Dockerfile entry, with
52
+ * `releaseImagePins` and `writeReleaseImagePins` for a product's package
53
+ * build (#4819).
54
+ */
55
+ export const RELEASE_IMAGE_DOCKERFILE_FLOOR = "0.124.78";
56
+
57
+ /** One image a release builds in its cut with a command of the product's. */
58
+ export interface ReleaseImageBuild {
40
59
  /** The image's name: its key in the digests file, and its artifact's `component` in the release. */
41
60
  name: string;
42
61
  /** The shell command, run in the member's directory, that writes the archive. */
@@ -45,6 +64,65 @@ export interface ReleaseImageDeclaration {
45
64
  archive: string;
46
65
  }
47
66
 
67
+ /** One image chant builds from a Dockerfile (#4819). */
68
+ export interface ReleaseImageDockerfile {
69
+ name: string;
70
+ /** The Dockerfile, relative to the member. */
71
+ dockerfile: string;
72
+ /** The build context, relative to the member. Default `.`. */
73
+ context?: string;
74
+ /** The platforms the archive's image index holds. Default {@link RELEASE_IMAGE_PLATFORMS}. */
75
+ platforms?: string[];
76
+ /** Where the archive goes, relative to the member. Default `dist/images/<name>.tar`. */
77
+ archive?: string;
78
+ /** A command run once before the builds, with `CHANT_RELEASE_DIGESTS` unset: what the image copies in, such as the bundle or a packed package. */
79
+ prepare?: string;
80
+ }
81
+
82
+ /** One image a release builds in its cut. */
83
+ export type ReleaseImageDeclaration = ReleaseImageBuild | ReleaseImageDockerfile;
84
+
85
+ /** The platforms a Dockerfile entry builds by default. Building arm64 on amd64 needs QEMU's binfmt handlers. */
86
+ export const RELEASE_IMAGE_PLATFORMS: readonly string[] = ["linux/amd64", "linux/arm64"];
87
+
88
+ /** The buildx builder a Dockerfile entry builds with, created with the `docker-container` driver when missing: the default driver cannot rewrite timestamps in an OCI archive. */
89
+ export const RELEASE_IMAGE_BUILDER = "chant-release";
90
+
91
+ const PLATFORM = /^[a-z0-9]+\/[a-z0-9_]+(?:\/[a-z0-9]+)?$/;
92
+
93
+ /** A word the shell reads as itself. */
94
+ const sh = (s: string): string => (/^[A-Za-z0-9_./:=,@+%-]+$/.test(s) ? s : `'${s.replace(/'/g, "'\\''")}'`);
95
+
96
+ const isDockerfile = (i: ReleaseImageDeclaration): i is ReleaseImageDockerfile => "dockerfile" in i && i.dockerfile !== undefined;
97
+
98
+ const archiveOf = (i: ReleaseImageDeclaration): string => i.archive ?? `dist/images/${i.name}.tar`;
99
+
100
+ /**
101
+ * The shell command a Dockerfile entry builds with (#4819), the one
102
+ * terragucci's and plywood's `scripts/release-image.sh` ran: `--no-cache`,
103
+ * no provenance or SBOM in the archive (chant attaches its own), the
104
+ * `SOURCE_DATE_EPOCH` the cut sets passed as a build argument and used to
105
+ * rewrite every timestamp, and every platform in one image index.
106
+ */
107
+ export function releaseImageBuildCommand(i: ReleaseImageDockerfile, o: { versionArg?: boolean } = {}): string {
108
+ const archive = archiveOf(i);
109
+ const b = RELEASE_IMAGE_BUILDER;
110
+ return [
111
+ `{ docker buildx inspect ${b} >/dev/null 2>&1 || docker buildx create --name ${b} --driver docker-container >/dev/null; }`,
112
+ `mkdir -p ${sh(posix.dirname(archive))}`,
113
+ [
114
+ `docker buildx build --builder ${b} --no-cache --platform ${sh((i.platforms ?? RELEASE_IMAGE_PLATFORMS).join(","))}`,
115
+ `--provenance=false --sbom=false --build-arg SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH"${o.versionArg ? ' --build-arg CHANT_RELEASE_LABEL="$CHANT_RELEASE_LABEL"' : ""}`,
116
+ `--output ${sh(`type=oci,dest=${archive},rewrite-timestamp=true`)} -f ${sh(i.dockerfile)} ${sh(i.context ?? ".")} >&2`,
117
+ ].join(" "),
118
+ ].join(" && ");
119
+ }
120
+
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. */
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));
124
+ }
125
+
48
126
  export class ReleaseImageError extends Error {
49
127
  constructor(
50
128
  readonly code: string,
@@ -58,15 +136,22 @@ export class ReleaseImageError extends Error {
58
136
 
59
137
  const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
60
138
 
61
- /** Check a member's `release.images`: names valid and unique, archives inside the member. */
139
+ const outside = (p: string): boolean => isAbsolute(p) || p.split(/[\\/]/).includes("..");
140
+
141
+ /** Check a member's `release.images`: names valid and unique, one of `build` and `dockerfile`, paths inside the member, platforms of the form os/arch. */
62
142
  export function checkReleaseImages(images: readonly ReleaseImageDeclaration[]): void {
63
143
  const seen = new Set<string>();
64
144
  for (const i of images) {
65
145
  if (!NAME.test(i.name)) throw new ReleaseImageError("release-image-name-invalid", `release.images: "${i.name}" is not a name of letters, digits, ".", "_" and "-"`);
66
146
  if (seen.has(i.name)) throw new ReleaseImageError("release-image-name-taken", `release.images names "${i.name}" twice`);
67
147
  seen.add(i.name);
68
- if (isAbsolute(i.archive) || i.archive.split(/[\\/]/).includes("..")) {
69
- throw new ReleaseImageError("release-image-archive-outside", `release.images "${i.name}": the archive ${i.archive} is not a path inside the member`);
148
+ if (isDockerfile(i) && "build" in i) throw new ReleaseImageError("release-image-invalid", `release.images "${i.name}" names a build command and a Dockerfile; chant builds a Dockerfile itself, so name one`);
149
+ const paths: [string, string | undefined][] = isDockerfile(i) ? [["the archive", archiveOf(i)], ["the Dockerfile", i.dockerfile], ["the context", i.context]] : [["the archive", i.archive]];
150
+ for (const [what, p] of paths) {
151
+ if (p !== undefined && outside(p)) throw new ReleaseImageError("release-image-archive-outside", `release.images "${i.name}": ${what} ${p} is not a path inside the member`);
152
+ }
153
+ if (isDockerfile(i) && i.platforms !== undefined && (i.platforms.length === 0 || !i.platforms.every((p) => PLATFORM.test(p)))) {
154
+ throw new ReleaseImageError("release-image-invalid", `release.images "${i.name}": platforms is a list of os/arch such as linux/amd64, not ${JSON.stringify(i.platforms)}`);
70
155
  }
71
156
  }
72
157
  }
@@ -83,6 +168,11 @@ export interface BuildImagesInput {
83
168
  label: string | null;
84
169
  env?: NodeJS.ProcessEnv;
85
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;
86
176
  /** Run one build command; the default runs it through the shell with its output on stderr. */
87
177
  run?: (command: string, o: { cwd: string; env: NodeJS.ProcessEnv }) => number | null;
88
178
  }
@@ -100,10 +190,24 @@ export function buildReleaseImages(i: BuildImagesInput): ReleaseArtifact[] {
100
190
  checkReleaseImages(i.images);
101
191
  const run = i.run ?? defaultRun;
102
192
  const out: ReleaseArtifact[] = [];
103
- for (const image of i.images) {
193
+ const envFor = (): NodeJS.ProcessEnv => {
104
194
  const env: NodeJS.ProcessEnv = { ...(i.env ?? process.env), SOURCE_DATE_EPOCH: String(i.sourceDateEpoch) };
105
195
  delete env.CHANT_RELEASE_LABEL;
106
196
  if (i.label !== null) env.CHANT_RELEASE_LABEL = i.label;
197
+ return env;
198
+ };
199
+ // #4819: each prepare command once, before any build, with no digests file, as the image's contents are built in the cut and the publish job alike.
200
+ const prepared = new Set<string>();
201
+ for (const image of i.images) {
202
+ if (!isDockerfile(image) || !image.prepare || prepared.has(image.prepare)) continue;
203
+ prepared.add(image.prepare);
204
+ const env = envFor();
205
+ delete env[RELEASE_DIGESTS_ENV];
206
+ const status = run(image.prepare, { cwd: i.cwd, env });
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}`);
208
+ }
209
+ for (const image of resolveReleaseImages(i.images, i.versionArg ? { versionArg: true } : {})) {
210
+ const env = envFor();
107
211
  const status = run(image.build, { cwd: i.cwd, env });
108
212
  if (status !== 0) throw new ReleaseImageError("release-image-build-failed", `the build of image "${image.name}" exited ${status ?? "with a signal"}: ${image.build}`);
109
213
  const abs = resolve(i.cwd, image.archive);
@@ -124,6 +228,65 @@ export function releaseImageDigests(release: Pick<Release, "artifactDigests">, n
124
228
  return out;
125
229
  }
126
230
 
231
+ // ── a product's package build (#4819) ──────────────────────────────────
232
+
233
+ const SHA256 = /^sha256:[0-9a-f]{64}$/;
234
+
235
+ export interface ReleaseImagePinsInput {
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`. */
237
+ images: Record<string, string>;
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). */
239
+ version: string;
240
+ env?: NodeJS.ProcessEnv;
241
+ }
242
+
243
+ /**
244
+ * The digest table a release's package build bakes into its bundle: each
245
+ * reference in `images` to the digest the cut recorded for its name, in
246
+ * `images`' order. Undefined outside a release build (no
247
+ * `CHANT_RELEASE_DIGESTS`), when a pipeline names the images by tag. Refuses
248
+ * a label that is not the version and a name the digests file has no digest
249
+ * for.
250
+ */
251
+ export function releaseImagePins(i: ReleaseImagePinsInput): Record<string, string> | undefined {
252
+ const env = i.env ?? process.env;
253
+ const file = env[RELEASE_DIGESTS_ENV];
254
+ if (!file) return undefined;
255
+ const label = env.CHANT_RELEASE_LABEL;
256
+ if (label && label !== i.version) {
257
+ throw new ReleaseImageError("release-label-not-version", `the release is labelled ${label}, and the package is at ${i.version}`, `Set the package's version to ${label} on the default branch, then cut the merged commit.`);
258
+ }
259
+ const named = JSON.parse(readFileSync(file, "utf-8")) as Record<string, unknown>;
260
+ const table: Record<string, string> = {};
261
+ for (const [name, reference] of Object.entries(i.images)) {
262
+ const digest = named[name];
263
+ if (typeof digest !== "string" || !SHA256.test(digest)) throw new ReleaseImageError("release-image-digest-missing", `${file} has no digest for the ${name} image, which the release builds`);
264
+ table[reference] = digest;
265
+ }
266
+ return table;
267
+ }
268
+
269
+ /**
270
+ * Write the pins file an npm target's `pins` names, once the bundle is
271
+ * built: the table as JSON, after checking that every bundle in `bundles`
272
+ * carries each digest. With no table (not a release build), remove the file,
273
+ * so a package never ships a stale one.
274
+ */
275
+ export function writeReleaseImagePins(table: Record<string, string> | undefined, o: { out: string; bundles?: readonly string[] }): void {
276
+ if (!table) {
277
+ rmSync(o.out, { force: true });
278
+ return;
279
+ }
280
+ for (const bundle of o.bundles ?? []) {
281
+ const text = readFileSync(bundle, "utf-8");
282
+ for (const [reference, digest] of Object.entries(table)) {
283
+ if (!text.includes(digest)) throw new ReleaseImageError("release-pin-not-bundled", `${bundle} does not carry ${reference}@${digest}`);
284
+ }
285
+ }
286
+ mkdirSync(dirname(o.out), { recursive: true });
287
+ writeFileSync(o.out, `${JSON.stringify(table, null, 2)}\n`);
288
+ }
289
+
127
290
  /** Write the digests file a package build reads. */
128
291
  export function writeReleaseDigests(file: string, digests: Record<string, string>): void {
129
292
  mkdirSync(dirname(file), { recursive: true });