@intentius/chant 0.124.69 → 0.124.71

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 (170) hide show
  1. package/dist/ci-agent.d.ts +12 -1
  2. package/dist/ci-agent.d.ts.map +1 -1
  3. package/dist/ci-agent.js +13 -8
  4. package/dist/ci-commit.d.ts +297 -0
  5. package/dist/ci-commit.d.ts.map +1 -0
  6. package/dist/ci-commit.js +696 -0
  7. package/dist/ci-product-words.d.ts +6 -1
  8. package/dist/ci-product-words.d.ts.map +1 -1
  9. package/dist/ci-product-words.js +3 -1
  10. package/dist/cli/handlers/approve.d.ts.map +1 -1
  11. package/dist/cli/handlers/approve.js +7 -2
  12. package/dist/cli/handlers/commit.d.ts +26 -0
  13. package/dist/cli/handlers/commit.d.ts.map +1 -0
  14. package/dist/cli/handlers/commit.js +142 -0
  15. package/dist/cli/handlers/pr.d.ts +6 -0
  16. package/dist/cli/handlers/pr.d.ts.map +1 -1
  17. package/dist/cli/handlers/pr.js +16 -7
  18. package/dist/cli/handlers/release.d.ts +9 -0
  19. package/dist/cli/handlers/release.d.ts.map +1 -1
  20. package/dist/cli/handlers/release.js +114 -5
  21. package/dist/cli/main.d.ts.map +1 -1
  22. package/dist/cli/main.js +23 -0
  23. package/dist/cli/parse-args.d.ts.map +1 -1
  24. package/dist/cli/parse-args.js +15 -0
  25. package/dist/cli/registry.d.ts +4 -0
  26. package/dist/cli/registry.d.ts.map +1 -1
  27. package/dist/components/product-pipeline.d.ts +33 -0
  28. package/dist/components/product-pipeline.d.ts.map +1 -1
  29. package/dist/components/product-pipeline.js +34 -1
  30. package/dist/components/release-compile.d.ts +2 -0
  31. package/dist/components/release-compile.d.ts.map +1 -1
  32. package/dist/components/release-compile.js +8 -4
  33. package/dist/config.d.ts +46 -0
  34. package/dist/config.d.ts.map +1 -1
  35. package/dist/config.js +9 -0
  36. package/dist/lexicon.d.ts +37 -0
  37. package/dist/lexicon.d.ts.map +1 -1
  38. package/dist/lexicon.js +28 -0
  39. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +4 -0
  40. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
  41. package/dist/lifecycle/__fixtures__/publish-fakes.js +6 -2
  42. package/dist/lifecycle/gated-request.d.ts +3 -1
  43. package/dist/lifecycle/gated-request.d.ts.map +1 -1
  44. package/dist/lifecycle/gated-request.js +5 -2
  45. package/dist/lifecycle/git.d.ts.map +1 -1
  46. package/dist/lifecycle/git.js +57 -0
  47. package/dist/lifecycle/publish-declaration.d.ts +16 -0
  48. package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
  49. package/dist/lifecycle/publish-declaration.js +35 -3
  50. package/dist/lifecycle/publish-forge.d.ts +12 -0
  51. package/dist/lifecycle/publish-forge.d.ts.map +1 -1
  52. package/dist/lifecycle/publish-forge.js +103 -19
  53. package/dist/lifecycle/publish-npm.d.ts +15 -0
  54. package/dist/lifecycle/publish-npm.d.ts.map +1 -1
  55. package/dist/lifecycle/publish-npm.js +28 -1
  56. package/dist/lifecycle/publish-oci.d.ts +2 -0
  57. package/dist/lifecycle/publish-oci.d.ts.map +1 -1
  58. package/dist/lifecycle/publish-oci.js +10 -0
  59. package/dist/lifecycle/release-cut.d.ts +7 -1
  60. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  61. package/dist/lifecycle/release-cut.js +8 -1
  62. package/dist/lifecycle/release-images.d.ts +87 -0
  63. package/dist/lifecycle/release-images.d.ts.map +1 -0
  64. package/dist/lifecycle/release-images.js +139 -0
  65. package/dist/lifecycle/release-publish.d.ts +2 -0
  66. package/dist/lifecycle/release-publish.d.ts.map +1 -1
  67. package/dist/op/activities/activity-contracts.d.ts +4 -4
  68. package/dist/op/activities/review-agent.d.ts.map +1 -1
  69. package/dist/op/activities/review-agent.js +4 -2
  70. package/dist/op/gate.d.ts +5 -1
  71. package/dist/op/gate.d.ts.map +1 -1
  72. package/dist/op/gate.js +7 -2
  73. package/dist/op/op-waves-notify.d.ts +1 -1
  74. package/dist/op/op-waves-notify.d.ts.map +1 -1
  75. package/dist/op/op-waves-notify.js +2 -1
  76. package/dist/op/op-waves-run.d.ts.map +1 -1
  77. package/dist/op/op-waves-run.js +12 -8
  78. package/dist/op/op-waves.d.ts +9 -0
  79. package/dist/op/op-waves.d.ts.map +1 -1
  80. package/dist/op/op-waves.js +11 -0
  81. package/dist/pr-forge-base.d.ts +18 -0
  82. package/dist/pr-forge-base.d.ts.map +1 -0
  83. package/dist/pr-forge-base.js +29 -0
  84. package/dist/release-floors.d.ts +1 -1
  85. package/dist/release-floors.js +1 -1
  86. package/dist/wave-runtime.mjs +305 -305
  87. package/dist/workspace/ci-green-cli.d.ts +7 -3
  88. package/dist/workspace/ci-green-cli.d.ts.map +1 -1
  89. package/dist/workspace/ci-green-cli.js +29 -8
  90. package/dist/workspace/ci-green-forge.d.ts +29 -0
  91. package/dist/workspace/ci-green-forge.d.ts.map +1 -1
  92. package/dist/workspace/ci-green-forge.js +50 -0
  93. package/dist/workspace/ci-green-workflow.d.ts +9 -1
  94. package/dist/workspace/ci-green-workflow.d.ts.map +1 -1
  95. package/dist/workspace/ci-green-workflow.js +15 -3
  96. package/dist/workspace/ci-green.d.ts +35 -1
  97. package/dist/workspace/ci-green.d.ts.map +1 -1
  98. package/dist/workspace/ci-green.js +122 -4
  99. package/dist/workspace/declaration.d.ts +14 -2
  100. package/dist/workspace/declaration.d.ts.map +1 -1
  101. package/dist/workspace/declaration.js +14 -1
  102. package/dist/workspace/declaration.schema.json +17 -2
  103. package/dist/workspace/release-workflow.d.ts +23 -0
  104. package/dist/workspace/release-workflow.d.ts.map +1 -1
  105. package/dist/workspace/release-workflow.js +203 -12
  106. package/package.json +1 -1
  107. package/src/ci-agent.ts +13 -8
  108. package/src/ci-commit.test.ts +415 -0
  109. package/src/ci-commit.ts +857 -0
  110. package/src/ci-product-words.ts +6 -2
  111. package/src/cli/handlers/approve.ts +6 -2
  112. package/src/cli/handlers/commit.ts +152 -0
  113. package/src/cli/handlers/operator.test.ts +2 -0
  114. package/src/cli/handlers/pr-wave-approve-lines.test.ts +32 -0
  115. package/src/cli/handlers/pr.ts +17 -7
  116. package/src/cli/handlers/release.ts +110 -5
  117. package/src/cli/main.ts +23 -0
  118. package/src/cli/parse-args.ts +11 -0
  119. package/src/cli/registry.ts +4 -0
  120. package/src/components/product-pipeline.test.ts +28 -1
  121. package/src/components/product-pipeline.ts +54 -1
  122. package/src/components/release-compile.ts +9 -3
  123. package/src/config.ts +24 -0
  124. package/src/lexicon.ts +56 -0
  125. package/src/lifecycle/__fixtures__/publish-fakes.ts +11 -5
  126. package/src/lifecycle/gated-request-spend.test.ts +115 -0
  127. package/src/lifecycle/gated-request.ts +5 -2
  128. package/src/lifecycle/git.ts +53 -0
  129. package/src/lifecycle/ledger-two-clones.test.ts +132 -0
  130. package/src/lifecycle/publish-declaration.ts +35 -3
  131. package/src/lifecycle/publish-forge-notes.test.ts +193 -0
  132. package/src/lifecycle/publish-forge.ts +101 -22
  133. package/src/lifecycle/publish-npm.ts +31 -2
  134. package/src/lifecycle/publish-oci.ts +10 -0
  135. package/src/lifecycle/publish-targets.test.ts +2 -1
  136. package/src/lifecycle/release-cut.ts +17 -1
  137. package/src/lifecycle/release-images.test.ts +242 -0
  138. package/src/lifecycle/release-images.ts +175 -0
  139. package/src/lifecycle/release-publish.ts +2 -0
  140. package/src/op/activities/review-agent.test.ts +20 -1
  141. package/src/op/activities/review-agent.ts +5 -2
  142. package/src/op/gate.ts +7 -2
  143. package/src/op/op-waves-approve-target.test.ts +108 -0
  144. package/src/op/op-waves-notify.ts +2 -2
  145. package/src/op/op-waves-run.ts +12 -7
  146. package/src/op/op-waves.ts +12 -0
  147. package/src/pr-forge-base.test.ts +37 -0
  148. package/src/pr-forge-base.ts +36 -0
  149. package/src/release-floors.ts +1 -1
  150. package/src/workspace/__fixtures__/release-workflow/forgejo-plain-member.yml +26 -0
  151. package/src/workspace/__fixtures__/release-workflow/forgejo-plain.yml +23 -0
  152. package/src/workspace/__fixtures__/release-workflow/forgejo-secure-member.yml +27 -0
  153. package/src/workspace/__fixtures__/release-workflow/forgejo-secure.yml +24 -0
  154. package/src/workspace/__fixtures__/release-workflow/github-plain-member.yml +26 -0
  155. package/src/workspace/__fixtures__/release-workflow/github-plain.yml +23 -0
  156. package/src/workspace/__fixtures__/release-workflow/github-secure-member.yml +27 -0
  157. package/src/workspace/__fixtures__/release-workflow/github-secure.yml +24 -0
  158. package/src/workspace/__fixtures__/release-workflow/gitlab-plain-member.yml +13 -0
  159. package/src/workspace/__fixtures__/release-workflow/gitlab-plain.yml +12 -0
  160. package/src/workspace/__fixtures__/release-workflow/gitlab-secure-member.yml +14 -0
  161. package/src/workspace/__fixtures__/release-workflow/gitlab-secure.yml +13 -0
  162. package/src/workspace/ci-green-cli.ts +27 -8
  163. package/src/workspace/ci-green-forge.ts +70 -0
  164. package/src/workspace/ci-green-workflow.ts +15 -3
  165. package/src/workspace/ci-green.ts +130 -5
  166. package/src/workspace/ci-verdict-retries.test.ts +376 -0
  167. package/src/workspace/declaration.schema.json +17 -2
  168. package/src/workspace/declaration.ts +28 -4
  169. package/src/workspace/release-workflow.test.ts +151 -0
  170. package/src/workspace/release-workflow.ts +270 -12
@@ -46,11 +46,61 @@
46
46
  import { readFileSync } from "node:fs";
47
47
  import { basename } from "node:path";
48
48
  import { memberSbom, releaseProvenance } from "./publish-attachments.js";
49
+ import { releaseVersion } from "./publish-homebrew.js";
50
+ import { NEXT_RELEASE } from "../release-floors.js";
49
51
  import { readCredential } from "./publish-credentials.js";
50
52
  import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets.js";
51
53
  import { PublishTargetError } from "./release-publish.js";
52
54
  /** The first chant that reads `latest` on a forge target and sends it as GitHub's `make_latest` (#4676). */
53
55
  export const PUBLISH_FORGE_LATEST_FLOOR = "0.124.63";
56
+ /** The first chant whose forge target reads `notes` and may have no assets (#4658). Products feature-detect on it. */
57
+ export const PUBLISH_FORGE_NOTES_FLOOR = NEXT_RELEASE;
58
+ /** `text` with `{label}`, `{version}` and `{tag}` filled in. */
59
+ function fillNotesText(text, values) {
60
+ return text.replaceAll("{label}", values.label).replaceAll("{version}", values.version).replaceAll("{tag}", values.tag);
61
+ }
62
+ /**
63
+ * The section of `page` that starts at the heading `heading` names (#4658),
64
+ * up to the next heading of the same level or higher, trimmed. A heading
65
+ * matches when it is the pattern, or the pattern and then whitespace, so
66
+ * `## [1.2.3] - 2026-11-07` matches `## [1.2.3]`, and neither `## 1.2.30`
67
+ * nor `## 1.2.3-rc.1` matches `## 1.2.3`. Links that start with `/` are
68
+ * made absolute against `linkBase`. Throws when there is no such heading or
69
+ * the section is empty.
70
+ */
71
+ export function releaseNotesSection(page, heading, linkBase) {
72
+ const level = /^(#+)/.exec(heading)[1].length;
73
+ const lines = page.split("\n");
74
+ const matches = (l) => {
75
+ const t = l.trimEnd();
76
+ return t === heading || (t.startsWith(heading) && /^\s/.test(t.slice(heading.length)));
77
+ };
78
+ const start = lines.findIndex(matches);
79
+ if (start < 0)
80
+ throw new Error(`it has no heading "${heading}"`);
81
+ // A `#` line inside a fenced code block is code, not a heading.
82
+ let end = lines.length;
83
+ let fence = null;
84
+ for (let i = start + 1; i < lines.length; i++) {
85
+ const f = /^\s*(```|~~~)/.exec(lines[i]);
86
+ if (f)
87
+ fence = fence === null ? f[1] : fence === f[1] ? null : fence;
88
+ if (fence !== null || f)
89
+ continue;
90
+ const m = /^(#{1,6}) /.exec(lines[i]);
91
+ if (m && m[1].length <= level) {
92
+ end = i;
93
+ break;
94
+ }
95
+ }
96
+ const body = lines.slice(start + 1, end).join("\n").trim();
97
+ if (!body)
98
+ throw new Error(`its "${heading}" section is empty`);
99
+ if (!linkBase)
100
+ return body;
101
+ const base = linkBase.replace(/\/+$/, "");
102
+ return body.replace(/\]\((\/(?!\/)[^)\s]*)/g, (_, path) => `](${base}${path}`);
103
+ }
54
104
  /** The variables a forge's token is read from, in order. */
55
105
  export function forgeTokenEnv(decl) {
56
106
  if (decl.tokenEnv)
@@ -125,7 +175,7 @@ class ForgeClient {
125
175
  return this.toRelease(found.json, tag);
126
176
  }
127
177
  /** GitHub and Forgejo: the draft release for `tag`, made at `commit` when there is none. */
128
- async draft(tag, commit, name) {
178
+ async draft(tag, commit, name, body) {
129
179
  const list = await this.call("GET", `${this.repoPath}/releases?per_page=100`);
130
180
  if (list.status !== 200)
131
181
  this.fail("listing releases", list.status, list.text);
@@ -136,22 +186,31 @@ class ForgeClient {
136
186
  return this.toRelease(mine, tag);
137
187
  }
138
188
  this.ctx.log(`creating a draft ${this.decl.forge} release for ${tag} at ${commit.slice(0, 12)}`);
139
- const create = await this.call("POST", `${this.repoPath}/releases`, JSON.stringify({ tag_name: tag, target_commitish: commit, name, draft: true }));
189
+ const create = await this.call("POST", `${this.repoPath}/releases`, JSON.stringify({ tag_name: tag, target_commitish: commit, name, draft: true, ...(body !== undefined ? { body } : {}) }));
140
190
  if (create.status !== 201 || !create.json)
141
191
  this.fail(`creating a draft release ${tag}`, create.status, create.text);
142
192
  return this.toRelease(create.json, tag);
143
193
  }
144
- /** GitHub and Forgejo: publish the draft `id`, with GitHub's `make_latest` when `latest` is declared. */
145
- async publishDraft(id, tag) {
146
- const latest = this.decl.latest;
147
- const body = latest === undefined ? { draft: false } : { draft: false, make_latest: String(latest) };
194
+ /**
195
+ * GitHub and Forgejo: publish the draft `id` with its notes. GitHub gets
196
+ * `make_latest`: the declared `latest`, else `false` for a release cut to a
197
+ * channel and `true` for any other (#4658). Forgejo has no such setting and
198
+ * takes the newest release that is not a prerelease, so a channel's release
199
+ * is marked a prerelease there.
200
+ */
201
+ async publishDraft(id, tag, o) {
202
+ const body = { draft: false, ...(o.notes !== undefined ? { body: o.notes } : {}) };
203
+ if (this.decl.forge === "github")
204
+ body.make_latest = String(this.decl.latest ?? !o.channel);
205
+ else if (o.channel)
206
+ body.prerelease = true;
148
207
  const res = await this.call("PATCH", `${this.repoPath}/releases/${id}`, JSON.stringify(body));
149
208
  if (res.status !== 200)
150
209
  this.fail(`publishing the draft release ${tag}`, res.status, res.text);
151
210
  }
152
211
  /** GitLab: create the release for `tag` at `commit` with a link to each asset. */
153
- async createWithLinks(tag, commit, name, links) {
154
- const res = await this.call("POST", `${this.repoPath}/releases`, JSON.stringify({ tag_name: tag, ref: commit, name, assets: { links: links.map((l) => ({ ...l, link_type: "package" })) } }));
212
+ async createWithLinks(tag, commit, name, links, notes) {
213
+ const res = await this.call("POST", `${this.repoPath}/releases`, JSON.stringify({ tag_name: tag, ref: commit, name, ...(notes !== undefined ? { description: notes } : {}), assets: { links: links.map((l) => ({ ...l, link_type: "package" })) } }));
155
214
  if (res.status !== 201)
156
215
  this.fail(`creating release ${tag}`, res.status, res.text);
157
216
  }
@@ -210,9 +269,11 @@ export function forgeTarget(decl, deps) {
210
269
  checkReleaseDigest(ctx.release, "asset", ctx.cwd, p, [digest]);
211
270
  return { path: p, name: basename(p), bytes, digest };
212
271
  });
213
- // #4049: the SBOM and the provenance statement over the assets go on the release with them.
272
+ // #4049: the SBOM and the provenance statement over the assets go on the release with them. A release of notes alone has no asset to state.
214
273
  const sbom = memberSbom(ctx, decl.sbom, `${decl.repo}@${tag}`, `the ${decl.forge} target`);
215
- const provenance = releaseProvenance(ctx, assets.map((a) => ({ name: a.name, digest: a.digest })));
274
+ const provenance = assets.length > 0
275
+ ? releaseProvenance(ctx, assets.map((a) => ({ name: a.name, digest: a.digest })))
276
+ : null;
216
277
  for (const a of [sbom, provenance])
217
278
  if (a)
218
279
  assets.push({ path: a.name, name: a.name, bytes: a.bytes, digest: a.digest, attachment: a.kind });
@@ -222,7 +283,25 @@ export function forgeTarget(decl, deps) {
222
283
  throw new PublishTargetError("publish-forge-asset-name-taken", `two assets are named ${a.name}, and a release holds one asset per name`);
223
284
  names.add(a.name);
224
285
  }
225
- return { tag, api, token, assets };
286
+ return { tag, api, token, assets, notes: releaseNotes(ctx, tag) };
287
+ };
288
+ // #4658: the notes are read when the target is planned, so a missing or empty section refuses before any target publishes.
289
+ const releaseNotes = (ctx, tag) => {
290
+ const n = decl.notes;
291
+ if (!n)
292
+ return undefined;
293
+ const label = ctx.label ?? tag;
294
+ const values = { label, version: releaseVersion(ctx.label) ?? label, tag };
295
+ const heading = fillNotesText(n.heading, values);
296
+ let section;
297
+ try {
298
+ section = releaseNotesSection(readFileSync(memberFile(ctx.cwd, n.file), "utf8"), heading, n.linkBase);
299
+ }
300
+ catch (err) {
301
+ const why = err.code === "ENOENT" ? "it does not exist" : err.message;
302
+ throw new PublishTargetError("publish-forge-notes-missing", `the ${decl.forge} release's notes come from ${n.file}, and ${why}`, `Write the "${heading}" section in ${n.file}, or change notes.heading.`);
303
+ }
304
+ return [...(n.before ? [fillNotesText(n.before, values), ""] : []), section, ...(n.after ? ["", fillNotesText(n.after, values)] : [])].join("\n") + "\n";
226
305
  };
227
306
  const att = (a) => (a.attachment ? { attachment: a.attachment } : {});
228
307
  const where = (tag, name) => `${decl.forge} ${decl.repo} release ${tag}, asset ${name}`;
@@ -234,11 +313,14 @@ export function forgeTarget(decl, deps) {
234
313
  credentialEnv: tokenNames,
235
314
  key: publishTargetKey(decl),
236
315
  async plan(ctx) {
237
- const { tag, assets } = setup(ctx);
238
- return assets.map((a) => ({ name: a.path, destination: where(tag, a.name), digest: a.digest, ...att(a) }));
316
+ const { tag, assets, notes } = setup(ctx);
317
+ return [
318
+ ...assets.map((a) => ({ name: a.path, destination: where(tag, a.name), digest: a.digest, ...att(a) })),
319
+ ...(notes !== undefined ? [{ name: decl.notes.file, destination: `${decl.forge} ${decl.repo} release ${tag}, notes`, notes }] : []),
320
+ ];
239
321
  },
240
322
  async stage(ctx) {
241
- const { tag, api, token, assets } = setup(ctx);
323
+ const { tag, api, token, assets, notes } = setup(ctx);
242
324
  ctx.log(`using the token from ${token.from}`);
243
325
  const client = new ForgeClient(decl, api, token, fetchImpl, ctx);
244
326
  const done = (items, state) => ({ target: this.name, destination: this.destination, items, state });
@@ -268,7 +350,7 @@ export function forgeTarget(decl, deps) {
268
350
  }
269
351
  return done(items, {});
270
352
  }
271
- const rel = await client.draft(tag, ctx.release.commit, ctx.label ?? tag);
353
+ const rel = await client.draft(tag, ctx.release.commit, ctx.label ?? tag, notes);
272
354
  const items = [];
273
355
  for (const a of assets) {
274
356
  if (rel.assets.has(a.name)) {
@@ -285,21 +367,23 @@ export function forgeTarget(decl, deps) {
285
367
  return done(items, { releaseId: rel.id });
286
368
  },
287
369
  async reveal(ctx, staged) {
288
- const { tag, api, token } = setup(ctx);
370
+ const { tag, api, token, notes } = setup(ctx);
289
371
  const client = new ForgeClient(decl, api, token, fetchImpl, ctx);
290
372
  const items = staged.items.map((i) => ({ name: i.name, destination: i.destination, ...(i.digest ? { digest: i.digest } : {}), ...(i.attachment ? { attachment: i.attachment } : {}) }));
291
373
  if (staged.state.published === "true")
292
374
  return { target: this.name, destination: this.destination, items: items.map((i) => ({ ...i, present: true })) };
293
375
  if (decl.forge === "gitlab") {
294
376
  ctx.log(`creating the gitlab release ${tag} at ${ctx.release.commit.slice(0, 12)} with ${items.length} asset link(s)`);
295
- await client.createWithLinks(tag, ctx.release.commit, ctx.label ?? tag, items.map((i) => ({ name: basename(i.name), url: i.destination })));
377
+ await client.createWithLinks(tag, ctx.release.commit, ctx.label ?? tag, items.map((i) => ({ name: basename(i.name), url: i.destination })), notes);
296
378
  }
297
379
  else {
298
380
  const id = staged.state.releaseId;
299
381
  if (!id)
300
382
  throw new PublishTargetError("publish-forge-failed", `the staged ${decl.forge} release for ${tag} has no draft id to publish`);
301
- ctx.log(`publishing the draft ${decl.forge} release ${tag}${decl.latest === undefined ? "" : ` with make_latest ${String(decl.latest)}`}`);
302
- await client.publishDraft(id, tag);
383
+ const channel = ctx.tag !== null;
384
+ const latest = decl.forge === "github" ? ` with make_latest ${String(decl.latest ?? !channel)}` : channel ? " as a prerelease, since it was cut to a channel" : "";
385
+ ctx.log(`publishing the draft ${decl.forge} release ${tag}${notes !== undefined ? " with its notes" : ""}${latest}`);
386
+ await client.publishDraft(id, tag, { ...(notes !== undefined ? { notes } : {}), channel });
303
387
  }
304
388
  return { target: this.name, destination: this.destination, items };
305
389
  },
@@ -53,6 +53,15 @@
53
53
  */
54
54
  import type { NpmPublishDeclaration } from "./publish-declaration.js";
55
55
  import { type PublishContext, type PublishDeps, type PublishTarget } from "./release-publish.js";
56
+ export interface NpmPackage {
57
+ path: string;
58
+ abs: string;
59
+ name: string;
60
+ version: string;
61
+ digest?: string;
62
+ /** The SBOM file at its root, or undefined under `sbom: false`. */
63
+ sbom?: string;
64
+ }
56
65
  /** The arguments of one `npm publish`, which stages under `tag`. */
57
66
  export declare function npmPublishArgs(decl: Pick<NpmPublishDeclaration, "registry" | "access">, abs: string, ctx: Pick<PublishContext, "provenance">, tag?: string): string[];
58
67
  /** The arguments of the `npm dist-tag add` that reveals a staged version under `tag`. */
@@ -65,5 +74,11 @@ export declare function npmAuditSignaturesArgs(decl: Pick<NpmPublishDeclaration,
65
74
  export declare const NPM_REGISTRY_POLL_MS = 10000;
66
75
  /** Between progress lines while the reveal waits for the registry (#4271). */
67
76
  export declare const NPM_REGISTRY_PROGRESS_MS = 60000;
77
+ /**
78
+ * #4657: refuse a package whose `pins` file holds an image digest the release
79
+ * does not record, and a target none of whose packages has the file. Read
80
+ * by the plan, so nothing is published, and by `chant release verify`.
81
+ */
82
+ export declare function checkPackagePins(decl: Pick<NpmPublishDeclaration, "pins">, release: PublishContext["release"], pkgs: ReadonlyArray<Pick<NpmPackage, "path" | "abs" | "name">>): void;
68
83
  export declare function npmTarget(decl: NpmPublishDeclaration, deps: PublishDeps): PublishTarget;
69
84
  //# sourceMappingURL=publish-npm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"publish-npm.d.ts","sourceRoot":"","sources":["../../src/lifecycle/publish-npm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAOH,OAAO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AAE,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC,CAAC,GAAG,IAAI,CAiBpL;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,WAAW,GAAG,aAAa,CA2MvF"}
@@ -57,6 +57,7 @@ import { tmpdir } from "node:os";
57
57
  import { join } from "node:path";
58
58
  import { packageSbom } from "./publish-attachments.js";
59
59
  import { checkReleaseDigest, fileDigest, isDir, memberFile, publishTargetKey } from "./publish-targets.js";
60
+ import { readPins, unknownPins } from "./release-images.js";
60
61
  import { NPM_STAGE_TAG, PublishTargetError } from "./release-publish.js";
61
62
  /** npm's output when a publish could not authenticate, as publish-packages.sh matches it. */
62
63
  const NPM_AUTH_FAILED = /ENEEDAUTH|E401|need auth/;
@@ -156,6 +157,28 @@ export const NPM_REGISTRY_PROGRESS_MS = 60000;
156
157
  const NPM_VIEW_NOT_YET = /\bE404\b|\b404 Not Found\b|is not in (this|the npm) registry|No match found for version|\b(ETARGET|notarget)\b/;
157
158
  /** npm's errors for a version the registry does not serve yet. */
158
159
  const NPM_NOT_SERVED = /\b(ETARGET|ERESOLVE|notarget)\b|No matching version found/;
160
+ /**
161
+ * #4657: refuse a package whose `pins` file holds an image digest the release
162
+ * does not record, and a target none of whose packages has the file. Read
163
+ * by the plan, so nothing is published, and by `chant release verify`.
164
+ */
165
+ export function checkPackagePins(decl, release, pkgs) {
166
+ if (!decl.pins)
167
+ return;
168
+ let found = 0;
169
+ for (const pkg of pkgs) {
170
+ const text = readPins(pkg.abs, decl.pins, isDir(pkg.abs));
171
+ if (text === null)
172
+ continue;
173
+ found++;
174
+ const unknown = unknownPins(text, release);
175
+ if (unknown.length > 0) {
176
+ throw new PublishTargetError("publish-npm-pin-unknown", `${pkg.name} (${pkg.path}) pins ${unknown.join(", ")} in ${decl.pins}, which release ${release.releaseDigest} does not record as an image`, "Build the package from the digests the cut wrote (CHANT_RELEASE_DIGESTS, or chant release images <label>), or cut a new release.");
177
+ }
178
+ }
179
+ if (found === 0)
180
+ throw new PublishTargetError("publish-npm-pins-missing", `no package of the npm target holds ${decl.pins}, which pins names`, "Build the package so it carries the file, or remove pins.");
181
+ }
159
182
  export function npmTarget(decl, deps) {
160
183
  const bin = deps.npm ?? "npm";
161
184
  const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
@@ -210,7 +233,11 @@ export function npmTarget(decl, deps) {
210
233
  rmSync(dir, { recursive: true, force: true });
211
234
  }
212
235
  };
213
- const read = (ctx) => decl.packages.map((p) => readPackage(ctx, p, decl.sbom));
236
+ const read = (ctx) => {
237
+ const pkgs = decl.packages.map((p) => readPackage(ctx, p, decl.sbom));
238
+ checkPackagePins(decl, ctx.release, pkgs);
239
+ return pkgs;
240
+ };
214
241
  const extra = (pkg) => ({ ...(pkg.digest ? { digest: pkg.digest } : {}), ...(pkg.sbom ? { sbom: pkg.sbom } : {}) });
215
242
  const plan = async (ctx) => read(ctx).map((pkg) => ({ name: `${pkg.name}@${pkg.version}`, destination: staging ? `${shown(NPM_STAGE_TAG)}, then ${revealTag(ctx)}` : shown(revealTag(ctx)), ...extra(pkg) }));
216
243
  /**
@@ -60,5 +60,7 @@ export declare function referrerManifest(a: Attachment, subject: {
60
60
  }): Uint8Array;
61
61
  /** The tags to point at the digest: the context's tag when set, else the declared ones with `{label}` filled in. */
62
62
  export declare function ociTags(decl: OciPublishDeclaration, ctx: Pick<PublishContext, "tag" | "label">): string[];
63
+ /** The digest an OCI archive (a layout directory or a tar file of one) is pushed under: its top manifest's (#4657). */
64
+ export declare function ociArchiveDigest(abs: string): string;
63
65
  export declare function ociTarget(decl: OciPublishDeclaration, deps: PublishDeps): PublishTarget;
64
66
  //# sourceMappingURL=publish-oci.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"publish-oci.d.ts","sourceRoot":"","sources":["../../src/lifecycle/publish-oci.ts"],"names":[],"mappings":"AAAA;;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,EAAE,KAAK,WAAW,EAAuC,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIvJ,kFAAkF;AAClF,MAAM,WAAW,aAAa;IAC5B,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa,CAajE;AAgMD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,UAAU,CAWxH;AAED,oHAAoH;AACpH,wBAAgB,OAAO,CAAC,IAAI,EAAE,qBAAqB,EAAE,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,KAAK,GAAG,OAAO,CAAC,GAAG,MAAM,EAAE,CAIzG;AAED,uHAAuH;AACvH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOpD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,WAAW,GAAG,aAAa,CAyGvF"}
@@ -266,6 +266,16 @@ export function ociTags(decl, ctx) {
266
266
  const declared = decl.tags ?? (ctx.label ? ["{label}"] : []);
267
267
  return declared.filter((t) => ctx.label !== null || !t.includes("{label}")).map((t) => t.split("{label}").join(ctx.label ?? ""));
268
268
  }
269
+ /** The digest an OCI archive (a layout directory or a tar file of one) is pushed under: its top manifest's (#4657). */
270
+ export function ociArchiveDigest(abs) {
271
+ const layout = readLayout(abs);
272
+ try {
273
+ return layout.top.digest;
274
+ }
275
+ finally {
276
+ layout.cleanup();
277
+ }
278
+ }
269
279
  export function ociTarget(decl, deps) {
270
280
  const repo = parseRepository(decl.repository);
271
281
  const fetchImpl = deps.fetch ?? ((url, init) => fetch(url, init));
@@ -66,7 +66,7 @@ export declare function greenOverrideSubject(commit: string): string;
66
66
  /** The rule an override of a cut names (#4693): `ci-green`, or `ci-green-<lane>` for a lane's tag. */
67
67
  export declare function greenOverrideRule(lane: string | null): string;
68
68
  /** The stable codes a cut refuses with. */
69
- export type ReleaseCutCode = "not-a-git-repository" | "release-commit-not-green" | "release-commit-revoked" | "release-worktree-dirty" | "release-no-environments" | "release-no-components" | "release-build-inputs-differ" | "release-image-invalid" | "release-image-unknown-component" | "release-unsigned" | "release-signer-refused" | "declaration-invalid";
69
+ export type ReleaseCutCode = "not-a-git-repository" | "release-commit-not-green" | "release-commit-revoked" | "release-worktree-dirty" | "release-no-environments" | "release-no-components" | "release-build-inputs-differ" | "release-image-invalid" | "release-image-unknown-component" | "release-image-name-taken" | "release-image-build-failed" | "release-unsigned" | "release-signer-refused" | "declaration-invalid";
70
70
  export declare class ReleaseCutError extends Error {
71
71
  readonly code: ReleaseCutCode;
72
72
  readonly fix?: string | undefined;
@@ -122,6 +122,12 @@ export interface CutRequest {
122
122
  * image, and the cut builds nothing for it.
123
123
  */
124
124
  images?: Readonly<Record<string, string>>;
125
+ /**
126
+ * Build the images `release.images` declares (#4657), before any
127
+ * environment is compiled, so the build command can read their digests.
128
+ * Given the commit being cut; returns each as an image artifact.
129
+ */
130
+ buildImages?: (commit: string) => Promise<ReleaseArtifact[]> | ReleaseArtifact[];
125
131
  }
126
132
  export interface CutResult {
127
133
  release: Release;
@@ -1 +1 @@
1
- {"version":3,"file":"release-cut.d.ts","sourceRoot":"","sources":["../../src/lifecycle/release-cut.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AASH,OAAO,EAUL,KAAK,OAAO,EACZ,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAGnB,MAAM,iBAAiB,CAA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E,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IAC5F,wEAAwE;IACxE,iBAAiB,EAAE,OAAO,CAAC;IAC3B,wFAAwF;IACxF,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,6GAA6G;IAC7G,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACrC;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CA+DnE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAyEpE"}
@@ -315,6 +315,8 @@ async function prepare(req, record = false) {
315
315
  if (envs.length === 0) {
316
316
  throw new ReleaseCutError("release-no-environments", "this member's chant.config.ts declares no environments, so there is nothing to compile a release for", "Declare them in promotion order: environments: [\"dev\", \"staging\", \"prod\"]");
317
317
  }
318
+ // #4657: the images first, so the build command that packs a package can pin their digests.
319
+ const builtImages = req.buildImages ? await req.buildImages(commit) : [];
318
320
  const compiled = [];
319
321
  for (const env of envs)
320
322
  compiled.push(await req.compiler.compile(env));
@@ -340,6 +342,11 @@ async function prepare(req, record = false) {
340
342
  handedArtifacts.push(artifact);
341
343
  }
342
344
  const handedTo = new Set(handedArtifacts.map((a) => a.component));
345
+ for (const image of builtImages) {
346
+ if (enabled.has(image.component) || handedTo.has(image.component)) {
347
+ throw new ReleaseCutError("release-image-name-taken", `release.images names "${image.component}", which is also a component of this member, and a release records one image per name`, "Rename the image in release.images.");
348
+ }
349
+ }
343
350
  // Which environment each component's artifacts are built in: the first one it is enabled in.
344
351
  const firstEnv = new Map();
345
352
  for (const t of compiled) {
@@ -351,7 +358,7 @@ async function prepare(req, record = false) {
351
358
  const realCwd = realpathSync(cwd);
352
359
  const previous = firstEnv.size > 0 ? await previousRelease(top, commit, cwd) : undefined;
353
360
  const reused = [];
354
- const artifacts = [...handedArtifacts];
361
+ const artifacts = [...handedArtifacts, ...builtImages];
355
362
  const toBuild = new Map();
356
363
  for (const [component, target] of firstEnv) {
357
364
  const prior = previous?.artifactDigests.filter((a) => a.component === component) ?? [];
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Images a release builds in its cut, and the digests its package pins
3
+ * (#4657, option 1).
4
+ *
5
+ * A package that pins container images by digest needs those digests when it
6
+ * is packed, and they exist only once the images are built. So the cut builds
7
+ * each image `release.images` declares first, as an OCI archive, and records
8
+ * the archive's digest in the release as an image artifact. It writes the
9
+ * digests to a file, `{ "<name>": "sha256:..." }`, and runs the build that
10
+ * packs the package with {@link RELEASE_DIGESTS_ENV} naming that file. The
11
+ * digest of an OCI archive is the digest of its top manifest, which is the
12
+ * digest a registry serves once the archive is pushed by the `oci` target.
13
+ *
14
+ * The publish job builds the images again from the release's commit
15
+ * (`chant release images`), with `SOURCE_DATE_EPOCH` set to the commit's
16
+ * time as in the cut, and refuses an archive whose digest is not the one the
17
+ * release records, so what is pushed is what the package pins. An image build
18
+ * that writes the same archive twice is the requirement (#4657's thread has
19
+ * the check against terragucci's Dockerfiles).
20
+ *
21
+ * An npm target's `pins` names the file in a package that carries the
22
+ * digests. The publish plan and `chant release verify` read it and refuse a
23
+ * digest the release does not record as an image.
24
+ */
25
+ import type { PublishDeclaration } from "./publish-declaration.js";
26
+ import type { Release, ReleaseArtifact } from "./release-store.js";
27
+ /** The variable that names the digests file a release's package build reads. */
28
+ export declare const RELEASE_DIGESTS_ENV = "CHANT_RELEASE_DIGESTS";
29
+ /** The first chant with `release.images`, `CHANT_RELEASE_DIGESTS`, `chant release images` and an npm target's `pins` (#4657). Products feature-detect on it. */
30
+ export declare const RELEASE_IMAGES_FLOOR = "0.124.71";
31
+ /** One image a release builds in its cut. */
32
+ export interface ReleaseImageDeclaration {
33
+ /** The image's name: its key in the digests file, and its artifact's `component` in the release. */
34
+ name: string;
35
+ /** The shell command, run in the member's directory, that writes the archive. */
36
+ build: string;
37
+ /** The OCI archive the command writes, a layout directory or a tar file, relative to the member. The `oci` target's `image`. */
38
+ archive: string;
39
+ }
40
+ export declare class ReleaseImageError extends Error {
41
+ readonly code: string;
42
+ readonly fix?: string | undefined;
43
+ constructor(code: string, message: string, fix?: string | undefined);
44
+ }
45
+ /** Check a member's `release.images`: names valid and unique, archives inside the member. */
46
+ export declare function checkReleaseImages(images: readonly ReleaseImageDeclaration[]): void;
47
+ /** The digest of an OCI archive: its top manifest's, as `index.json` names it. */
48
+ export type ArchiveDigest = (abs: string) => string;
49
+ export interface BuildImagesInput {
50
+ images: readonly ReleaseImageDeclaration[];
51
+ /** The member's directory. */
52
+ cwd: string;
53
+ /** The commit's time in seconds, passed to each build as `SOURCE_DATE_EPOCH`. */
54
+ sourceDateEpoch: number;
55
+ label: string | null;
56
+ env?: NodeJS.ProcessEnv;
57
+ archiveDigest: ArchiveDigest;
58
+ /** Run one build command; the default runs it through the shell with its output on stderr. */
59
+ run?: (command: string, o: {
60
+ cwd: string;
61
+ env: NodeJS.ProcessEnv;
62
+ }) => number | null;
63
+ }
64
+ /**
65
+ * Build each image and return it as the release's image artifact. The
66
+ * command runs with `SOURCE_DATE_EPOCH` and, for a cut with a label,
67
+ * `CHANT_RELEASE_LABEL`; an archive it did not write, or a command that
68
+ * fails, stops the cut.
69
+ */
70
+ export declare function buildReleaseImages(i: BuildImagesInput): ReleaseArtifact[];
71
+ /** The release's built images by name: every image artifact with a path, which a handed image (#4694) has not. */
72
+ export declare function releaseImageDigests(release: Pick<Release, "artifactDigests">, names?: readonly string[]): Record<string, string>;
73
+ /** Write the digests file a package build reads. */
74
+ export declare function writeReleaseDigests(file: string, digests: Record<string, string>): void;
75
+ /** Every `sha256:` digest in a pins file's text. */
76
+ export declare function pinnedDigests(text: string): string[];
77
+ /** The digests in `text` that the release does not record as an image. */
78
+ export declare function unknownPins(text: string, release: Pick<Release, "artifactDigests">): string[];
79
+ /** A pins file read from a package directory or a packed `.tgz`, or null when the package has none. */
80
+ export declare function readPins(abs: string, pins: string, isDirectory: boolean): string | null;
81
+ /**
82
+ * For `chant release verify` (#4657): the first package an npm target's
83
+ * `pins` finds holding an image digest the release does not record, said in
84
+ * a sentence, or null. A package not built here is not read.
85
+ */
86
+ export declare function packagePinProblem(cwd: string, release: Pick<Release, "artifactDigests">, targets: readonly PublishDeclaration[]): string | null;
87
+ //# sourceMappingURL=release-images.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release-images.d.ts","sourceRoot":"","sources":["../../src/lifecycle/release-images.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAMH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEhE,gFAAgF;AAChF,eAAO,MAAM,mBAAmB,0BAA0B,CAAC;AAE3D,gKAAgK;AAChK,eAAO,MAAM,oBAAoB,aAAe,CAAC;AAEjD,6CAA6C;AAC7C,MAAM,WAAW,uBAAuB;IACtC,oGAAoG;IACpG,IAAI,EAAE,MAAM,CAAC;IACb,iFAAiF;IACjF,KAAK,EAAE,MAAM,CAAC;IACd,gIAAgI;IAChI,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IAExC,QAAQ,CAAC,IAAI,EAAE,MAAM;IAErB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM;IAHvB,YACW,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACN,GAAG,CAAC,EAAE,MAAM,YAAA,EAItB;CACF;AAID,6FAA6F;AAC7F,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,uBAAuB,EAAE,GAAG,IAAI,CAUnF;AAED,kFAAkF;AAClF,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,MAA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E,OAAO,GAAG,MAAM,GAAG,IAAI,CAOvF;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,iBAAiB,CAAC,EAAE,OAAO,EAAE,SAAS,kBAAkB,EAAE,GAAG,MAAM,GAAG,IAAI,CAY/I"}
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Images a release builds in its cut, and the digests its package pins
3
+ * (#4657, option 1).
4
+ *
5
+ * A package that pins container images by digest needs those digests when it
6
+ * is packed, and they exist only once the images are built. So the cut builds
7
+ * each image `release.images` declares first, as an OCI archive, and records
8
+ * the archive's digest in the release as an image artifact. It writes the
9
+ * digests to a file, `{ "<name>": "sha256:..." }`, and runs the build that
10
+ * packs the package with {@link RELEASE_DIGESTS_ENV} naming that file. The
11
+ * digest of an OCI archive is the digest of its top manifest, which is the
12
+ * digest a registry serves once the archive is pushed by the `oci` target.
13
+ *
14
+ * The publish job builds the images again from the release's commit
15
+ * (`chant release images`), with `SOURCE_DATE_EPOCH` set to the commit's
16
+ * time as in the cut, and refuses an archive whose digest is not the one the
17
+ * release records, so what is pushed is what the package pins. An image build
18
+ * that writes the same archive twice is the requirement (#4657's thread has
19
+ * the check against terragucci's Dockerfiles).
20
+ *
21
+ * An npm target's `pins` names the file in a package that carries the
22
+ * digests. The publish plan and `chant release verify` read it and refuse a
23
+ * digest the release does not record as an image.
24
+ */
25
+ import { spawnSync } from "node:child_process";
26
+ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
27
+ import { dirname, isAbsolute, relative, resolve } from "node:path";
28
+ import { NEXT_RELEASE } from "../release-floors.js";
29
+ /** The variable that names the digests file a release's package build reads. */
30
+ export const RELEASE_DIGESTS_ENV = "CHANT_RELEASE_DIGESTS";
31
+ /** The first chant with `release.images`, `CHANT_RELEASE_DIGESTS`, `chant release images` and an npm target's `pins` (#4657). Products feature-detect on it. */
32
+ export const RELEASE_IMAGES_FLOOR = NEXT_RELEASE;
33
+ export class ReleaseImageError extends Error {
34
+ constructor(code, message, fix) {
35
+ super(message);
36
+ this.code = code;
37
+ this.fix = fix;
38
+ this.name = "ReleaseImageError";
39
+ }
40
+ }
41
+ const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
42
+ /** Check a member's `release.images`: names valid and unique, archives inside the member. */
43
+ export function checkReleaseImages(images) {
44
+ const seen = new Set();
45
+ for (const i of images) {
46
+ if (!NAME.test(i.name))
47
+ throw new ReleaseImageError("release-image-name-invalid", `release.images: "${i.name}" is not a name of letters, digits, ".", "_" and "-"`);
48
+ if (seen.has(i.name))
49
+ throw new ReleaseImageError("release-image-name-taken", `release.images names "${i.name}" twice`);
50
+ seen.add(i.name);
51
+ if (isAbsolute(i.archive) || i.archive.split(/[\\/]/).includes("..")) {
52
+ throw new ReleaseImageError("release-image-archive-outside", `release.images "${i.name}": the archive ${i.archive} is not a path inside the member`);
53
+ }
54
+ }
55
+ }
56
+ const defaultRun = (command, o) => spawnSync(command, { cwd: o.cwd, env: o.env, shell: true, stdio: ["ignore", 2, 2] }).status;
57
+ /**
58
+ * Build each image and return it as the release's image artifact. The
59
+ * command runs with `SOURCE_DATE_EPOCH` and, for a cut with a label,
60
+ * `CHANT_RELEASE_LABEL`; an archive it did not write, or a command that
61
+ * fails, stops the cut.
62
+ */
63
+ export function buildReleaseImages(i) {
64
+ checkReleaseImages(i.images);
65
+ const run = i.run ?? defaultRun;
66
+ const out = [];
67
+ for (const image of i.images) {
68
+ const env = { ...(i.env ?? process.env), SOURCE_DATE_EPOCH: String(i.sourceDateEpoch) };
69
+ delete env.CHANT_RELEASE_LABEL;
70
+ if (i.label !== null)
71
+ env.CHANT_RELEASE_LABEL = i.label;
72
+ const status = run(image.build, { cwd: i.cwd, env });
73
+ if (status !== 0)
74
+ throw new ReleaseImageError("release-image-build-failed", `the build of image "${image.name}" exited ${status ?? "with a signal"}: ${image.build}`);
75
+ const abs = resolve(i.cwd, image.archive);
76
+ if (!existsSync(abs))
77
+ throw new ReleaseImageError("release-image-no-archive", `the build of image "${image.name}" wrote no ${image.archive}`, "Make the command write the OCI archive at archive, such as docker buildx build --output type=oci,dest=<archive>,rewrite-timestamp=true.");
78
+ out.push({ component: image.name, kind: "image", path: relative(i.cwd, abs).split("\\").join("/"), digest: i.archiveDigest(abs) });
79
+ }
80
+ return out;
81
+ }
82
+ /** The release's built images by name: every image artifact with a path, which a handed image (#4694) has not. */
83
+ export function releaseImageDigests(release, names) {
84
+ const out = {};
85
+ for (const a of release.artifactDigests) {
86
+ if (a.kind !== "image")
87
+ continue;
88
+ if (names && !names.includes(a.component))
89
+ continue;
90
+ out[a.component] = a.digest;
91
+ }
92
+ return out;
93
+ }
94
+ /** Write the digests file a package build reads. */
95
+ export function writeReleaseDigests(file, digests) {
96
+ mkdirSync(dirname(file), { recursive: true });
97
+ const sorted = Object.fromEntries(Object.entries(digests).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
98
+ writeFileSync(file, `${JSON.stringify(sorted, null, 2)}\n`);
99
+ }
100
+ const DIGEST = /sha256:[0-9a-f]{64}/g;
101
+ /** Every `sha256:` digest in a pins file's text. */
102
+ export function pinnedDigests(text) {
103
+ return [...new Set(text.match(DIGEST) ?? [])];
104
+ }
105
+ /** The digests in `text` that the release does not record as an image. */
106
+ export function unknownPins(text, release) {
107
+ const known = new Set(release.artifactDigests.filter((a) => a.kind === "image").map((a) => a.digest));
108
+ return pinnedDigests(text).filter((d) => !known.has(d));
109
+ }
110
+ /** A pins file read from a package directory or a packed `.tgz`, or null when the package has none. */
111
+ export function readPins(abs, pins, isDirectory) {
112
+ if (isDirectory) {
113
+ const file = resolve(abs, pins);
114
+ return existsSync(file) ? readFileSync(file, "utf-8") : null;
115
+ }
116
+ const run = spawnSync("tar", ["-xzOf", abs, `package/${pins.replace(/^\.\//, "")}`], { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
117
+ return run.status === 0 ? run.stdout : null;
118
+ }
119
+ /**
120
+ * For `chant release verify` (#4657): the first package an npm target's
121
+ * `pins` finds holding an image digest the release does not record, said in
122
+ * a sentence, or null. A package not built here is not read.
123
+ */
124
+ export function packagePinProblem(cwd, release, targets) {
125
+ for (const t of targets) {
126
+ if (t.type !== "npm" || !t.pins)
127
+ continue;
128
+ for (const p of t.packages) {
129
+ const abs = resolve(cwd, p);
130
+ if (!existsSync(abs))
131
+ continue;
132
+ const text = readPins(abs, t.pins, statSync(abs).isDirectory());
133
+ const unknown = text === null ? [] : unknownPins(text, release);
134
+ if (unknown.length > 0)
135
+ return `${p} pins ${unknown.join(", ")} in ${t.pins}, which the release does not record as an image`;
136
+ }
137
+ }
138
+ return null;
139
+ }