@intentius/chant 0.124.99 → 0.124.101

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 (245) hide show
  1. package/bin/chant +3 -3
  2. package/dist/action-pins.d.ts +2 -0
  3. package/dist/action-pins.js +3 -0
  4. package/dist/ci-detect.d.ts +13 -0
  5. package/dist/ci-detect.js +12 -0
  6. package/dist/ci-system.d.ts +66 -0
  7. package/dist/ci-system.js +61 -0
  8. package/dist/cli/commands/carve-emit.js +2 -2
  9. package/dist/cli/commands/check-lexicon-plugin.d.ts +2 -2
  10. package/dist/cli/commands/check-lexicon-plugin.js +3 -3
  11. package/dist/cli/commands/check-lexicon.js +4 -4
  12. package/dist/cli/commands/init-lexicon/templates/project.d.ts +1 -1
  13. package/dist/cli/commands/init-lexicon/templates/project.js +4 -4
  14. package/dist/cli/commands/init.d.ts +13 -0
  15. package/dist/cli/commands/init.js +30 -2
  16. package/dist/cli/handlers/build.js +27 -0
  17. package/dist/cli/handlers/release-doctor.d.ts +12 -0
  18. package/dist/cli/handlers/release-doctor.js +118 -0
  19. package/dist/cli/handlers/release-init.d.ts +10 -0
  20. package/dist/cli/handlers/release-init.js +342 -0
  21. package/dist/cli/handlers/release.d.ts +50 -1
  22. package/dist/cli/handlers/release.js +688 -30
  23. package/dist/cli/handlers/run-generate.js +11 -0
  24. package/dist/cli/main.d.ts +2 -0
  25. package/dist/cli/main.js +45 -97
  26. package/dist/cli/parse-args.js +55 -0
  27. package/dist/cli/registry.d.ts +18 -0
  28. package/dist/cli/release-commands/artifacts.d.ts +3 -0
  29. package/dist/cli/release-commands/artifacts.js +14 -0
  30. package/dist/cli/release-commands/candidates.d.ts +3 -0
  31. package/dist/cli/release-commands/candidates.js +16 -0
  32. package/dist/cli/release-commands/changed.d.ts +3 -0
  33. package/dist/cli/release-commands/changed.js +14 -0
  34. package/dist/cli/release-commands/compose.d.ts +3 -0
  35. package/dist/cli/release-commands/compose.js +16 -0
  36. package/dist/cli/release-commands/cut.d.ts +3 -0
  37. package/dist/cli/release-commands/cut.js +49 -0
  38. package/dist/cli/release-commands/doctor.d.ts +3 -0
  39. package/dist/cli/release-commands/doctor.js +14 -0
  40. package/dist/cli/release-commands/export.d.ts +3 -0
  41. package/dist/cli/release-commands/export.js +12 -0
  42. package/dist/cli/release-commands/images.d.ts +3 -0
  43. package/dist/cli/release-commands/images.js +13 -0
  44. package/dist/cli/release-commands/index.d.ts +8 -0
  45. package/dist/cli/release-commands/index.js +52 -0
  46. package/dist/cli/release-commands/init.d.ts +3 -0
  47. package/dist/cli/release-commands/init.js +16 -0
  48. package/dist/cli/release-commands/list.d.ts +3 -0
  49. package/dist/cli/release-commands/list.js +10 -0
  50. package/dist/cli/release-commands/next.d.ts +3 -0
  51. package/dist/cli/release-commands/next.js +13 -0
  52. package/dist/cli/release-commands/publish.d.ts +3 -0
  53. package/dist/cli/release-commands/publish.js +22 -0
  54. package/dist/cli/release-commands/stamp.d.ts +3 -0
  55. package/dist/cli/release-commands/stamp.js +15 -0
  56. package/dist/cli/release-commands/status.d.ts +3 -0
  57. package/dist/cli/release-commands/status.js +17 -0
  58. package/dist/cli/release-commands/tag.d.ts +3 -0
  59. package/dist/cli/release-commands/tag.js +12 -0
  60. package/dist/cli/release-commands/types.d.ts +20 -0
  61. package/dist/cli/release-commands/types.js +1 -0
  62. package/dist/cli/release-commands/verify.d.ts +3 -0
  63. package/dist/cli/release-commands/verify.js +15 -0
  64. package/dist/cli/release-commands/workflow.d.ts +3 -0
  65. package/dist/cli/release-commands/workflow.js +13 -0
  66. package/dist/codegen/pinned-upgrade.js +1 -1
  67. package/dist/components/capability-plugin.d.ts +1 -1
  68. package/dist/components/capability-plugin.js +1 -1
  69. package/dist/components/cli-support.d.ts +1 -1
  70. package/dist/components/cli-support.js +1 -1
  71. package/dist/config-environments.d.ts +8 -1
  72. package/dist/config-environments.js +2 -0
  73. package/dist/config.d.ts +299 -6
  74. package/dist/config.js +102 -5
  75. package/dist/dead-guards.d.ts +5 -1
  76. package/dist/dead-guards.js +34 -23
  77. package/dist/discovery/sandbox/driver.js +1 -1
  78. package/dist/discovery/specifier-resolve.js +1 -1
  79. package/dist/floor-table.d.ts +3 -1
  80. package/dist/floor-table.data.js +23 -3
  81. package/dist/floor-table.js +4 -3
  82. package/dist/forge-remote.d.ts +13 -0
  83. package/dist/forge-remote.js +15 -0
  84. package/dist/lexicon.d.ts +41 -2
  85. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +62 -0
  86. package/dist/lifecycle/__fixtures__/publish-fakes.js +270 -3
  87. package/dist/lifecycle/publish-attachments.d.ts +2 -1
  88. package/dist/lifecycle/publish-attachments.js +19 -2
  89. package/dist/lifecycle/publish-cargo.d.ts +99 -0
  90. package/dist/lifecycle/publish-cargo.js +412 -0
  91. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  92. package/dist/lifecycle/publish-credentials.js +8 -0
  93. package/dist/lifecycle/publish-declaration.d.ts +199 -4
  94. package/dist/lifecycle/publish-declaration.js +200 -9
  95. package/dist/lifecycle/publish-forge.d.ts +45 -2
  96. package/dist/lifecycle/publish-forge.js +434 -34
  97. package/dist/lifecycle/publish-git-ssh.d.ts +15 -0
  98. package/dist/lifecycle/publish-git-ssh.js +30 -4
  99. package/dist/lifecycle/publish-github.d.ts +40 -2
  100. package/dist/lifecycle/publish-github.js +100 -3
  101. package/dist/lifecycle/publish-homebrew.d.ts +7 -9
  102. package/dist/lifecycle/publish-homebrew.js +34 -197
  103. package/dist/lifecycle/publish-index.d.ts +141 -0
  104. package/dist/lifecycle/publish-index.js +719 -0
  105. package/dist/lifecycle/publish-marketplace.js +77 -0
  106. package/dist/lifecycle/publish-mcp-registry.d.ts +66 -0
  107. package/dist/lifecycle/publish-mcp-registry.js +306 -0
  108. package/dist/lifecycle/publish-npm.js +165 -2
  109. package/dist/lifecycle/publish-oci.d.ts +34 -1
  110. package/dist/lifecycle/publish-oci.js +246 -7
  111. package/dist/lifecycle/publish-pypi.d.ts +136 -0
  112. package/dist/lifecycle/publish-pypi.js +657 -0
  113. package/dist/lifecycle/publish-record.d.ts +6 -3
  114. package/dist/lifecycle/publish-record.js +6 -3
  115. package/dist/lifecycle/publish-signing.d.ts +147 -0
  116. package/dist/lifecycle/publish-signing.js +257 -0
  117. package/dist/lifecycle/publish-targets.d.ts +27 -1
  118. package/dist/lifecycle/publish-targets.js +80 -0
  119. package/dist/lifecycle/publish-tauri.js +43 -0
  120. package/dist/lifecycle/publish-train-names.d.ts +54 -0
  121. package/dist/lifecycle/publish-train-names.js +118 -0
  122. package/dist/lifecycle/publish-verify.d.ts +121 -0
  123. package/dist/lifecycle/publish-verify.js +130 -0
  124. package/dist/lifecycle/query.js +8 -0
  125. package/dist/lifecycle/release-artifacts.d.ts +212 -0
  126. package/dist/lifecycle/release-artifacts.js +571 -0
  127. package/dist/lifecycle/release-changelog.d.ts +13 -1
  128. package/dist/lifecycle/release-changelog.js +35 -2
  129. package/dist/lifecycle/release-cut.d.ts +58 -3
  130. package/dist/lifecycle/release-cut.js +132 -34
  131. package/dist/lifecycle/release-doctor.d.ts +113 -0
  132. package/dist/lifecycle/release-doctor.js +996 -0
  133. package/dist/lifecycle/release-green.d.ts +86 -0
  134. package/dist/lifecycle/release-green.js +286 -0
  135. package/dist/lifecycle/release-init.d.ts +255 -0
  136. package/dist/lifecycle/release-init.js +859 -0
  137. package/dist/lifecycle/release-intents.d.ts +73 -0
  138. package/dist/lifecycle/release-intents.js +128 -0
  139. package/dist/lifecycle/release-next.d.ts +111 -0
  140. package/dist/lifecycle/release-next.js +252 -0
  141. package/dist/lifecycle/release-prerelease.d.ts +19 -0
  142. package/dist/lifecycle/release-prerelease.js +30 -0
  143. package/dist/lifecycle/release-publish.d.ts +256 -10
  144. package/dist/lifecycle/release-publish.js +246 -34
  145. package/dist/lifecycle/release-status-change.d.ts +226 -0
  146. package/dist/lifecycle/release-status-change.js +478 -0
  147. package/dist/lifecycle/release-status.d.ts +11 -0
  148. package/dist/lifecycle/release-status.js +1 -1
  149. package/dist/lifecycle/release-store.d.ts +73 -2
  150. package/dist/lifecycle/release-store.js +32 -1
  151. package/dist/lifecycle/release-tag.d.ts +142 -0
  152. package/dist/lifecycle/release-tag.js +323 -0
  153. package/dist/lifecycle/release-verify.d.ts +73 -1
  154. package/dist/lifecycle/release-verify.js +117 -2
  155. package/dist/lifecycle/release-version-formats.d.ts +73 -0
  156. package/dist/lifecycle/release-version-formats.js +570 -0
  157. package/dist/lifecycle/release-version.d.ts +58 -10
  158. package/dist/lifecycle/release-version.js +164 -36
  159. package/dist/lifecycle/release-workstation.d.ts +3 -2
  160. package/dist/lifecycle/release-workstation.js +3 -2
  161. package/dist/module-source.d.ts +2 -2
  162. package/dist/module-source.js +8 -8
  163. package/dist/op/generate-pipeline.js +1 -1
  164. package/dist/pr-forge-base.js +4 -2
  165. package/dist/pr-forge.d.ts +20 -2
  166. package/dist/pr-forge.js +46 -10
  167. package/dist/release-floors.d.ts +10 -1
  168. package/dist/release-floors.js +10 -1
  169. package/dist/tool-pins.d.ts +38 -0
  170. package/dist/tool-pins.js +54 -0
  171. package/dist/ts-loader.d.ts +1 -1
  172. package/dist/ts-loader.js +6 -6
  173. package/dist/wave-runtime.mjs +337 -334
  174. package/dist/workspace/ci-forge.d.ts +17 -0
  175. package/dist/workspace/ci-forge.js +17 -0
  176. package/dist/workspace/ci-init.js +1 -1
  177. package/dist/workspace/composites.schema.json +1 -0
  178. package/dist/workspace/declaration.d.ts +8 -0
  179. package/dist/workspace/declaration.js +12 -0
  180. package/dist/workspace/declaration.schema.json +8 -0
  181. package/dist/workspace/environments.d.ts +2 -0
  182. package/dist/workspace/environments.js +1 -1
  183. package/dist/workspace/identity-gate-rule.d.ts +61 -5
  184. package/dist/workspace/identity-gate-rule.js +81 -12
  185. package/dist/workspace/member-pipeline.d.ts +2 -1
  186. package/dist/workspace/member-pipeline.js +5 -2
  187. package/dist/workspace/reason-codes.d.ts +6 -0
  188. package/dist/workspace/reason-codes.js +8 -1
  189. package/dist/workspace/release-changed.d.ts +179 -0
  190. package/dist/workspace/release-changed.js +625 -0
  191. package/dist/workspace/release-changed.schema.json +206 -0
  192. package/dist/workspace/release-steps/artifacts.d.ts +7 -0
  193. package/dist/workspace/release-steps/artifacts.js +45 -0
  194. package/dist/workspace/release-steps/builds.d.ts +12 -0
  195. package/dist/workspace/release-steps/builds.js +38 -0
  196. package/dist/workspace/release-steps/doctor.d.ts +8 -0
  197. package/dist/workspace/release-steps/doctor.js +14 -0
  198. package/dist/workspace/release-steps/goreleaser.d.ts +16 -0
  199. package/dist/workspace/release-steps/goreleaser.js +36 -0
  200. package/dist/workspace/release-steps/green.d.ts +3 -0
  201. package/dist/workspace/release-steps/green.js +6 -0
  202. package/dist/workspace/release-steps/images.d.ts +22 -0
  203. package/dist/workspace/release-steps/images.js +59 -0
  204. package/dist/workspace/release-steps/index.d.ts +9 -0
  205. package/dist/workspace/release-steps/index.js +46 -0
  206. package/dist/workspace/release-steps/pypi.d.ts +15 -0
  207. package/dist/workspace/release-steps/pypi.js +21 -0
  208. package/dist/workspace/release-steps/qemu.d.ts +21 -0
  209. package/dist/workspace/release-steps/qemu.js +35 -0
  210. package/dist/workspace/release-steps/signing.d.ts +18 -0
  211. package/dist/workspace/release-steps/signing.js +30 -0
  212. package/dist/workspace/release-steps/stamp.d.ts +3 -0
  213. package/dist/workspace/release-steps/stamp.js +4 -0
  214. package/dist/workspace/release-steps/targets.d.ts +31 -0
  215. package/dist/workspace/release-steps/targets.js +40 -0
  216. package/dist/workspace/release-steps/types.d.ts +104 -0
  217. package/dist/workspace/release-steps/types.js +2 -0
  218. package/dist/workspace/release-steps/verify.d.ts +3 -0
  219. package/dist/workspace/release-steps/verify.js +4 -0
  220. package/dist/workspace/release-toolchains.d.ts +59 -0
  221. package/dist/workspace/release-toolchains.js +133 -0
  222. package/dist/workspace/release-train-workflow.d.ts +29 -0
  223. package/dist/workspace/release-train-workflow.js +85 -0
  224. package/dist/workspace/release-train.d.ts +3 -1
  225. package/dist/workspace/release-train.js +20 -3
  226. package/dist/workspace/release-workflow.d.ts +160 -61
  227. package/dist/workspace/release-workflow.js +539 -193
  228. package/dist/workspace/releases.schema.json +70 -1
  229. package/dist/workspace/search-contract.d.ts +1 -1
  230. package/dist/workspace/security.js +9 -2
  231. package/dist/workspace/train-cut.d.ts +182 -0
  232. package/dist/workspace/train-cut.js +482 -0
  233. package/dist/workspace/train-prepare.d.ts +61 -0
  234. package/dist/workspace/train-prepare.js +267 -0
  235. package/dist/workspace/train-publish.d.ts +177 -0
  236. package/dist/workspace/train-publish.js +575 -0
  237. package/dist/workspace/train-range-labels.d.ts +33 -0
  238. package/dist/workspace/train-range-labels.js +109 -0
  239. package/dist/workspace/trust/seal.d.ts +13 -3
  240. package/dist/workspace/trust/seal.js +14 -4
  241. package/dist/workspace/work-cli.d.ts +3 -2
  242. package/dist/workspace/work-cli.js +3 -2
  243. package/dist/workspace/workspace-ledger.d.ts +14 -1
  244. package/dist/workspace/workspace-ledger.js +33 -7
  245. package/package.json +26 -26
@@ -4,7 +4,8 @@
4
4
  * each forge's REST API and an injectable `fetch`.
5
5
  *
6
6
  * The tag is the declaration's `tag`, else the one the cut made
7
- * (`release/<label>`, or `release/<member>/<label>`), so a release with no
7
+ * (`release.tag`, #5150; `release/<label>` or `release/<member>/<label>`
8
+ * when unset), so a release with no
8
9
  * label and no declared tag is refused.
9
10
  *
10
11
  * A publish is two steps (#4048), so a consumer never sees a release with
@@ -40,20 +41,41 @@
40
41
  * (./publish-attachments.ts). They go on the draft with the assets, so
41
42
  * nothing is visible before they are attached.
42
43
  *
44
+ * The release's notes (#4658, #5153) are a section of a file in the member,
45
+ * notes generated for the release, or both, between `before` and `after`.
46
+ * Generated notes are the forge's own (GitHub's `generate-notes`, GitLab's
47
+ * changelog API) or chant's, from the conventional commits in the member
48
+ * since its previous release. The stage decides them: the draft is made
49
+ * with them, or edited to them when it already exists, and they are kept in
50
+ * the publish record, so the reveal publishes what the draft showed, and a
51
+ * resumed reveal does not ask the forge again.
52
+ *
53
+ * When the publish signs (#5164, ./publish-signing.ts), the stage also
54
+ * uploads `<file>.sigstore.json` beside each file and
55
+ * `release.slsa.sigstore.json`, SLSA provenance over the declared assets. A
56
+ * bundle already on the draft is kept, since signing again gives other bytes.
57
+ *
43
58
  * The token is read from `tokenEnv`, else `GITHUB_TOKEN`, `GITLAB_TOKEN`
44
59
  * then `CI_JOB_TOKEN`, or `FORGEJO_TOKEN`, and is masked in all output.
45
60
  */
61
+ import { execFileSync } from "node:child_process";
46
62
  import { readFileSync } from "node:fs";
47
63
  import { basename } from "node:path";
48
64
  import { memberSbom, releaseProvenance } from "./publish-attachments.js";
65
+ import { SIGSTORE_BUNDLE_SUFFIX, SLSA_BUNDLE_FILE, SLSA_PROVENANCE_PREDICATE, slsaProvenanceStatement } from "./publish-signing.js";
49
66
  import { releaseVersion } from "./publish-homebrew.js";
50
67
  import { readCredential } from "./publish-credentials.js";
51
- import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets.js";
68
+ import { changelogNotes } from "./release-changelog.js";
69
+ import { bytesDigest, checkReleaseDigest, expandArtifactAssets, memberFile, publishTargetKey } from "./publish-targets.js";
70
+ import { trainName, waitUntilServed } from "./publish-train-names.js";
52
71
  import { PublishTargetError } from "./release-publish.js";
72
+ import { prereleaseOf } from "./release-prerelease.js";
53
73
  /** The first chant that reads `latest` on a forge target and sends it as GitHub's `make_latest` (#4676). */
54
74
  export const PUBLISH_FORGE_LATEST_FLOOR = "0.124.63";
55
75
  /** The first chant whose forge target reads `notes` and may have no assets (#4658). Products feature-detect on it. */
56
76
  export const PUBLISH_FORGE_NOTES_FLOOR = "0.124.71";
77
+ /** The first chant whose forge target generates notes, `notes.generate` (#5153). Products feature-detect on it. */
78
+ export const PUBLISH_FORGE_GENERATED_NOTES_FLOOR = "0.124.101";
57
79
  /** `text` with `{label}`, `{version}` and `{tag}` filled in. */
58
80
  function fillNotesText(text, values) {
59
81
  return text.replaceAll("{label}", values.label).replaceAll("{version}", values.version).replaceAll("{tag}", values.tag);
@@ -161,7 +183,15 @@ class ForgeClient {
161
183
  for (const a of body.assets ?? [])
162
184
  assets.set(a.name, typeof a.digest === "string" ? a.digest : null);
163
185
  }
164
- return { id: String(body.id ?? body.tag_name ?? tag), draft: body.draft === true, assets, ...(typeof body.upload_url === "string" ? { uploadUrl: body.upload_url } : {}) };
186
+ return {
187
+ id: String(body.id ?? body.tag_name ?? tag),
188
+ draft: body.draft === true,
189
+ prerelease: body.prerelease === true,
190
+ assets,
191
+ ...(typeof body.upload_url === "string" ? { uploadUrl: body.upload_url } : {}),
192
+ ...(typeof body.html_url === "string" ? { url: body.html_url } : {}),
193
+ ...(typeof body.body === "string" ? { body: body.body } : {}),
194
+ };
165
195
  }
166
196
  /** The published release for `tag`, or null when the forge has none. A draft is not found here. */
167
197
  async published(tag) {
@@ -173,6 +203,27 @@ class ForgeClient {
173
203
  this.fail(`reading release ${tag}`, found.status, found.text);
174
204
  return this.toRelease(found.json, tag);
175
205
  }
206
+ /** GitHub and Forgejo: the draft release for `tag`, or null (#5163). */
207
+ async draftFor(tag) {
208
+ const list = await this.call("GET", `${this.repoPath}/releases?per_page=100`);
209
+ if (list.status !== 200)
210
+ this.fail("listing releases", list.status, list.text);
211
+ const found = (Array.isArray(list.json) ? list.json : []).find((r) => r.draft === true && r.tag_name === tag);
212
+ return found ? this.toRelease(found, tag) : null;
213
+ }
214
+ /** GitHub and Forgejo: change the release `id` (#5163): `prerelease`, `draft`, GitHub's `make_latest`. */
215
+ async edit(id, tag, body) {
216
+ const res = await this.call("PATCH", `${this.repoPath}/releases/${id}`, JSON.stringify(body));
217
+ if (res.status !== 200)
218
+ this.fail(`changing release ${tag}`, res.status, res.text);
219
+ }
220
+ /** Delete the release for `tag` (#5163). Its tag and, on GitLab, its packages stay. */
221
+ async remove(rel, tag) {
222
+ const url = this.decl.forge === "gitlab" ? `${this.repoPath}/releases/${encodeURIComponent(tag)}` : `${this.repoPath}/releases/${rel.id}`;
223
+ const res = await this.call("DELETE", url);
224
+ if (res.status !== 200 && res.status !== 204 && res.status !== 404)
225
+ this.fail(`deleting release ${tag}`, res.status, res.text);
226
+ }
176
227
  /** GitHub and Forgejo: the draft release for `tag`, made at `commit` when there is none. */
177
228
  async draft(tag, commit, name, body) {
178
229
  const list = await this.call("GET", `${this.repoPath}/releases?per_page=100`);
@@ -182,7 +233,16 @@ class ForgeClient {
182
233
  const mine = drafts.find((r) => r.draft === true && r.tag_name === tag);
183
234
  if (mine) {
184
235
  this.ctx.log(`using the draft ${this.decl.forge} release for ${tag}`);
185
- return this.toRelease(mine, tag);
236
+ const rel = this.toRelease(mine, tag);
237
+ // #5153: the draft shows the notes the reveal will publish, so a draft made by an earlier stage gets them too.
238
+ if (body !== undefined && (rel.body ?? "") !== body) {
239
+ this.ctx.log(`setting the notes of the draft ${this.decl.forge} release for ${tag}`);
240
+ const edit = await this.call("PATCH", `${this.repoPath}/releases/${rel.id}`, JSON.stringify({ body }));
241
+ if (edit.status !== 200)
242
+ this.fail(`setting the notes of the draft release ${tag}`, edit.status, edit.text);
243
+ rel.body = body;
244
+ }
245
+ return rel;
186
246
  }
187
247
  this.ctx.log(`creating a draft ${this.decl.forge} release for ${tag} at ${commit.slice(0, 12)}`);
188
248
  const create = await this.call("POST", `${this.repoPath}/releases`, JSON.stringify({ tag_name: tag, target_commitish: commit, name, draft: true, ...(body !== undefined ? { body } : {}) }));
@@ -193,20 +253,44 @@ class ForgeClient {
193
253
  /**
194
254
  * GitHub and Forgejo: publish the draft `id` with its notes. GitHub gets
195
255
  * `make_latest`: the declared `latest`, else `false` for a release cut to a
196
- * channel and `true` for any other (#4658). Forgejo has no such setting and
197
- * takes the newest release that is not a prerelease, so a channel's release
198
- * is marked a prerelease there.
256
+ * channel and `true` for any other (#4658). A release whose label is a
257
+ * semver prerelease is marked a prerelease, on GitHub too, and is never
258
+ * latest. Forgejo has no latest setting and takes the newest release that
259
+ * is not a prerelease, so a channel's release is marked a prerelease there.
199
260
  */
200
261
  async publishDraft(id, tag, o) {
201
262
  const body = { draft: false, ...(o.notes !== undefined ? { body: o.notes } : {}) };
202
- if (this.decl.forge === "github")
203
- body.make_latest = String(this.decl.latest ?? !o.channel);
204
- else if (o.channel)
263
+ if (this.decl.forge === "github") {
264
+ body.make_latest = o.prerelease ? "false" : String(this.decl.latest ?? !o.channel);
265
+ if (o.prerelease)
266
+ body.prerelease = true;
267
+ }
268
+ else if (o.channel || o.prerelease)
205
269
  body.prerelease = true;
206
270
  const res = await this.call("PATCH", `${this.repoPath}/releases/${id}`, JSON.stringify(body));
207
271
  if (res.status !== 200)
208
272
  this.fail(`publishing the draft release ${tag}`, res.status, res.text);
209
273
  }
274
+ /**
275
+ * The forge's own notes for `tag` at `commit` (#5153): GitHub's
276
+ * `POST /repos/{repo}/releases/generate-notes`, since `previousTag` when
277
+ * one is known, else since the release GitHub picks; GitLab's
278
+ * `GET /projects/{id}/repository/changelog`, from the `Changelog:`
279
+ * trailers of the commits since `previousCommit`.
280
+ */
281
+ async generatedNotes(tag, commit, version, previous) {
282
+ if (this.decl.forge === "gitlab") {
283
+ const q = new URLSearchParams({ version, to: commit, ...(previous ? { from: previous.commit } : {}) });
284
+ const res = await this.call("GET", `${this.repoPath}/repository/changelog?${q.toString()}`);
285
+ if (res.status !== 200)
286
+ this.fail(`generating the changelog for ${tag}`, res.status, res.text);
287
+ return String(res.json?.notes ?? "").trim();
288
+ }
289
+ const res = await this.call("POST", `${this.repoPath}/releases/generate-notes`, JSON.stringify({ tag_name: tag, target_commitish: commit, ...(previous?.tag ? { previous_tag_name: previous.tag } : {}) }));
290
+ if (res.status !== 200)
291
+ this.fail(`generating the notes for ${tag}`, res.status, res.text);
292
+ return String(res.json?.body ?? "").trim();
293
+ }
210
294
  /** GitLab: create the release for `tag` at `commit` with a link to each asset. */
211
295
  async createWithLinks(tag, commit, name, links, notes) {
212
296
  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" })) } }));
@@ -239,6 +323,90 @@ class ForgeClient {
239
323
  return url;
240
324
  }
241
325
  }
326
+ function git(cwd, args) {
327
+ try {
328
+ return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 64 * 1024 * 1024 });
329
+ }
330
+ catch {
331
+ return null;
332
+ }
333
+ }
334
+ /**
335
+ * The member's previous release (#5153): the release of it cut from the
336
+ * nearest ancestor of this release's commit, as the cut finds it, with its
337
+ * label. Null for the member's first release. Refuses when the history the
338
+ * notes are generated from is not in the checkout.
339
+ */
340
+ export async function previousMemberRelease(ctx, forge) {
341
+ const top = git(ctx.cwd, ["rev-parse", "--show-toplevel"])?.trim();
342
+ if (!top) {
343
+ throw new PublishTargetError("publish-forge-notes-history", `the ${forge} release's notes are generated from the history since the member's previous release, and ${ctx.cwd} is not in a git checkout`, "Publish from a checkout of the release's commit.");
344
+ }
345
+ if (git(ctx.cwd, ["rev-parse", "--is-shallow-repository"])?.trim() === "true") {
346
+ throw new PublishTargetError("publish-forge-notes-history", `the ${forge} release's notes are generated from the history since the member's previous release, and this checkout is shallow`, "Check out the full history: fetch-depth: 0 on actions/checkout, GIT_DEPTH: 0 on GitLab.");
347
+ }
348
+ const { previousRelease } = await import("./release-cut.js");
349
+ const { readCuts, labelsByDigest } = await import("./release-store.js");
350
+ const prev = await previousRelease(top, ctx.release.commit, ctx.cwd);
351
+ if (!prev)
352
+ return null;
353
+ return { commit: prev.commit, label: labelsByDigest((await readCuts({ cwd: ctx.cwd })).cuts).get(prev.releaseDigest) ?? null };
354
+ }
355
+ /**
356
+ * The tag the member's previous release has (#5150): its label through
357
+ * `release.tag`. A context that does not carry the template reads it off
358
+ * this release's tag, as the label's suffix, or not at all.
359
+ */
360
+ export function previousReleaseTag(ctx, label) {
361
+ if (ctx.releaseTagOf)
362
+ return ctx.releaseTagOf(label);
363
+ return ctx.label !== null && ctx.releaseTag?.endsWith(ctx.label) ? `${ctx.releaseTag.slice(0, -ctx.label.length)}${label}` : null;
364
+ }
365
+ /** The commits in the member's directory after `from` (all of them when null) up to the release's commit, newest first, merges left out. */
366
+ export function memberCommits(ctx, from, forge) {
367
+ const range = from ? `${from}..${ctx.release.commit}` : ctx.release.commit;
368
+ const out = git(ctx.cwd, ["log", "--no-merges", "--format=%H%x00%B%x1e", range, "--", "."]);
369
+ if (out === null) {
370
+ throw new PublishTargetError("publish-forge-notes-history", `the ${forge} release's notes are generated from the commits ${range}, and git could not list them here`, "Publish from a full checkout that holds the release's commit.");
371
+ }
372
+ return out
373
+ .split("\x1e")
374
+ .map((r) => r.replace(/^\n+/, ""))
375
+ .filter((r) => r.includes("\0"))
376
+ .map((r) => {
377
+ const [sha, message] = r.split("\0");
378
+ return { sha, message: message.trim() };
379
+ });
380
+ }
381
+ /**
382
+ * Notes from the intent files the release's cuts consumed (#5159), read at
383
+ * the release's commit: their summaries, the highest level first. Empty
384
+ * when the cuts consumed none. A file the commit does not hold, or that
385
+ * can't be read, is left out.
386
+ */
387
+ export async function consumedIntentNotes(ctx) {
388
+ const { readCuts } = await import("./release-store.js");
389
+ const { parseIntent, intentNotes } = await import("./release-intents.js");
390
+ const consumed = (await readCuts({ cwd: ctx.cwd })).cuts.filter((c) => c.releaseDigest === ctx.release.releaseDigest).flatMap((c) => c.intents ?? []);
391
+ if (consumed.length === 0)
392
+ return "";
393
+ const top = git(ctx.cwd, ["rev-parse", "--show-toplevel"])?.trim();
394
+ if (!top)
395
+ return "";
396
+ const read = [];
397
+ for (const i of consumed) {
398
+ const text = git(top, ["show", `${ctx.release.commit}:${i.path}`]);
399
+ if (text === null)
400
+ continue;
401
+ try {
402
+ read.push({ bump: i.bump, summary: parseIntent(i.path, text).summary });
403
+ }
404
+ catch {
405
+ // A file that can't be read gives no note; the cut read it when it consumed it.
406
+ }
407
+ }
408
+ return intentNotes(read);
409
+ }
242
410
  /** A GitLab generic package version: the label with what GitLab refuses replaced. */
243
411
  export function gitlabPackageVersion(label) {
244
412
  return label.replace(/[^0-9A-Za-z.\-_+]/g, "-");
@@ -261,7 +429,7 @@ export function forgeTarget(decl, deps) {
261
429
  if (!token) {
262
430
  throw new PublishTargetError("publish-credentials-missing", `the ${decl.forge} target reads its token from ${tokenNames.join(" or ")}, and none is set`, `Set ${tokenNames[0]} in the job's or the shell's environment.`);
263
431
  }
264
- const assets = decl.assets.map((p) => {
432
+ const assets = expandArtifactAssets(ctx.release, decl.assets).map((p) => {
265
433
  const abs = memberFile(ctx.cwd, p);
266
434
  const bytes = new Uint8Array(readFileSync(abs));
267
435
  const digest = bytesDigest(bytes);
@@ -273,53 +441,246 @@ export function forgeTarget(decl, deps) {
273
441
  const provenance = assets.length > 0
274
442
  ? releaseProvenance(ctx, assets.map((a) => ({ name: a.name, digest: a.digest })))
275
443
  : null;
444
+ const declared = assets.map((a) => ({ name: a.name, digest: a.digest }));
276
445
  for (const a of [sbom, provenance])
277
446
  if (a)
278
447
  assets.push({ path: a.name, name: a.name, bytes: a.bytes, digest: a.digest, attachment: a.kind });
448
+ // #5164: a bundle beside each file, and SLSA provenance over the declared assets, signed in the stage.
449
+ const signing = ctx.signing;
450
+ const signatures = signing
451
+ ? [
452
+ ...assets.map((a) => ({ name: `${a.name}${SIGSTORE_BUNDLE_SUFFIX}`, attachment: "signature", signs: [{ name: a.name, digest: a.digest }], make: () => signing.signer.signBlob(a.bytes, a.name) })),
453
+ ...(declared.length > 0
454
+ ? [{ name: SLSA_BUNDLE_FILE, attachment: "attestation", signs: declared, predicateType: SLSA_PROVENANCE_PREDICATE, make: () => signing.signer.signStatement(slsaProvenanceStatement(ctx, declared)) }]
455
+ : []),
456
+ ]
457
+ : [];
279
458
  const names = new Set();
280
- for (const a of assets) {
281
- if (names.has(a.name))
282
- throw new PublishTargetError("publish-forge-asset-name-taken", `two assets are named ${a.name}, and a release holds one asset per name`);
283
- names.add(a.name);
459
+ for (const n of [...assets.map((a) => a.name), ...signatures.map((x) => x.name)]) {
460
+ if (names.has(n))
461
+ throw new PublishTargetError("publish-forge-asset-name-taken", `two assets are named ${n}, and a release holds one asset per name`);
462
+ names.add(n);
284
463
  }
285
- return { tag, api, token, assets, notes: releaseNotes(ctx, tag) };
464
+ return { tag, api, token, assets, signatures, section: notesSection(ctx, tag) };
286
465
  };
287
- // #4658: the notes are read when the target is planned, so a missing or empty section refuses before any target publishes.
288
- const releaseNotes = (ctx, tag) => {
466
+ // #4658: the file's section is read when the target is planned, so a missing or empty section refuses before any target publishes.
467
+ const notesSection = (ctx, tag) => {
289
468
  const n = decl.notes;
290
- if (!n)
469
+ if (n?.generate === "forge" && decl.forge === "forgejo") {
470
+ throw new PublishTargetError("publish-forge-notes-unsupported", "notes.generate is forge, and Forgejo has no API that generates a release's notes", 'Set notes.generate to "commits" for notes from the conventional commits since the previous release.');
471
+ }
472
+ if (!n?.file || !n.heading)
291
473
  return undefined;
292
- const label = ctx.label ?? tag;
293
- const values = { label, version: releaseVersion(ctx.label) ?? label, tag };
294
- const heading = fillNotesText(n.heading, values);
295
- let section;
474
+ const heading = fillNotesText(n.heading, notesValues(ctx, tag));
296
475
  try {
297
- section = releaseNotesSection(readFileSync(memberFile(ctx.cwd, n.file), "utf8"), heading, n.linkBase);
476
+ return releaseNotesSection(readFileSync(memberFile(ctx.cwd, n.file), "utf8"), heading, n.linkBase);
298
477
  }
299
478
  catch (err) {
300
479
  const why = err.code === "ENOENT" ? "it does not exist" : err.message;
301
480
  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.`);
302
481
  }
303
- return [...(n.before ? [fillNotesText(n.before, values), ""] : []), section, ...(n.after ? ["", fillNotesText(n.after, values)] : [])].join("\n") + "\n";
482
+ };
483
+ const notesValues = (ctx, tag) => {
484
+ const label = ctx.label ?? tag;
485
+ return { label, version: releaseVersion(ctx.label) ?? label, tag };
486
+ };
487
+ /**
488
+ * The notes: `before`, the file's section, the generated notes, then
489
+ * `after`, a blank line between each. `client` null is a plan, which asks
490
+ * the forge nothing, so the forge's own notes are named rather than
491
+ * fetched there.
492
+ */
493
+ const releaseNotes = async (ctx, tag, section, client) => {
494
+ const n = decl.notes;
495
+ if (!n)
496
+ return undefined;
497
+ const values = notesValues(ctx, tag);
498
+ let generated;
499
+ if (n.generate) {
500
+ const previous = await previousMemberRelease(ctx, decl.forge);
501
+ if (n.generate === "commits") {
502
+ // #5159: the summaries of the intent files the cut consumed come first.
503
+ generated = [await consumedIntentNotes(ctx), changelogNotes(memberCommits(ctx, previous?.commit ?? null, decl.forge), n.types)].filter((p) => p.length > 0).join("\n\n");
504
+ }
505
+ else {
506
+ // #5150: the previous release's tag is the one release.tag gives its label, as the cut made it.
507
+ const previousTag = previous && previous.label !== null && !decl.tag ? previousReleaseTag(ctx, previous.label) : null;
508
+ generated = client
509
+ ? await client.generatedNotes(tag, ctx.release.commit, values.version, previous ? { tag: previousTag, commit: previous.commit } : null)
510
+ : `(${decl.forge === "github" ? "GitHub" : "GitLab"}'s generated notes${previousTag ? ` since ${previousTag}` : ""}, made when the release stages)`;
511
+ }
512
+ }
513
+ const parts = [n.before ? fillNotesText(n.before, values) : "", section ?? "", generated ?? "", n.after ? fillNotesText(n.after, values) : ""].filter((p) => p.length > 0);
514
+ return parts.length > 0 ? `${parts.join("\n\n")}\n` : "";
304
515
  };
305
516
  const att = (a) => (a.attachment ? { attachment: a.attachment } : {});
306
517
  const where = (tag, name) => `${decl.forge} ${decl.repo} release ${tag}, asset ${name}`;
518
+ const sigItem = (ctx, tag, x, o = {}) => ({
519
+ name: x.name,
520
+ destination: o.destination ?? `${where(tag, x.name)}${o.digest === undefined && !o.present ? ", signed when staged" : ""}`,
521
+ ...(o.digest ? { digest: o.digest } : {}),
522
+ attachment: x.attachment,
523
+ signs: x.signs,
524
+ ...(x.predicateType ? { predicateType: x.predicateType } : {}),
525
+ ...(ctx.signing ? { sigstore: ctx.signing.identity } : {}),
526
+ ...(o.present ? { present: true } : {}),
527
+ });
528
+ /** Sign `x` and upload its bundle. */
529
+ const signAndUpload = async (ctx, client, rel, version, tag, x) => {
530
+ ctx.log(`signing ${x.signs.length === 1 ? x.signs[0].name : `${x.signs.length} assets`} with ${ctx.signing.signer.name}: ${x.name}`);
531
+ const bytes = await x.make();
532
+ const digest = bytesDigest(bytes);
533
+ const destination = await client.upload(rel, version, { path: x.name, name: x.name, bytes, digest });
534
+ return sigItem(ctx, tag, x, { destination: decl.forge === "gitlab" ? destination : where(tag, x.name), digest });
535
+ };
307
536
  const exists = (tag, a, theirs, before) => new PublishTargetError("publish-forge-asset-exists", `release ${tag} on ${decl.forge} ${decl.repo} already has an asset named ${a.name}${theirs ? ` with digest ${theirs}, not ${a.digest}` : ", and the forge reports no digest to compare"}${before.length > 0 ? `; ${before.map((i) => i.name).join(", ")} were staged before it` : ""}`, "Delete the asset on the forge, or cut a new release.");
537
+ /** #5165: the release's tag and a client, read without the checkout's files; null when the tag, the API root or the token is missing. */
538
+ const reader = (ctx) => {
539
+ const tag = decl.tag ?? ctx.releaseTag;
540
+ const api = forgeApi(decl, ctx.env);
541
+ const token = readCredential(ctx.env, tokenNames, ctx.redactor);
542
+ return tag && api && token ? { tag, client: new ForgeClient(decl, api, token, fetchImpl, ctx) } : null;
543
+ };
308
544
  return {
309
545
  kind: "forge",
310
546
  name: `${decl.forge} release assets ${decl.repo}`,
311
547
  destination: `${decl.forge} ${decl.repo}`,
312
548
  credentialEnv: tokenNames,
313
549
  key: publishTargetKey(decl),
550
+ /** #5165: the repository whose releases it publishes; it needs nothing a train orders by. */
551
+ async names() {
552
+ return { provides: [trainName("forge", `${decl.forge}/${decl.repo}`)], needs: [] };
553
+ },
554
+ /** #5165: whether the forge has a published release, not a draft, for the release's tag. */
555
+ async published(ctx) {
556
+ const r = reader(ctx);
557
+ if (!r)
558
+ return null;
559
+ return (await r.client.published(r.tag)) !== null;
560
+ },
561
+ /** #5165: wait until the forge serves the release for the tag as published. */
562
+ async visible(ctx) {
563
+ const r = reader(ctx);
564
+ if (!r)
565
+ return;
566
+ await waitUntilServed(ctx, deps, {
567
+ what: `${decl.forge} ${decl.repo}`,
568
+ code: "publish-forge-not-served",
569
+ check: async () => ((await r.client.published(r.tag)) === null ? [`release ${r.tag}`] : []),
570
+ });
571
+ },
572
+ /**
573
+ * #5163: a forge release has no deprecation, so deprecate does nothing
574
+ * here. A yank marks the release a prerelease, makes it a draft again, or
575
+ * deletes it (`--forge-release`), and on GitHub makes the head release
576
+ * the latest again; GitLab has neither prerelease nor draft, so it only
577
+ * deletes. A restore publishes it again: it clears the prerelease mark
578
+ * (not on Forgejo for a channel's release, which is a prerelease by
579
+ * design) or publishes the draft. A deleted release can't be restored.
580
+ */
581
+ async setStatus(ctx) {
582
+ const tag = decl.tag ?? ctx.releaseTag;
583
+ const forge = `${decl.forge} ${decl.repo}`;
584
+ if (!tag)
585
+ return [{ what: `${forge} unchanged: the release has no label, so it has no forge release`, already: true }];
586
+ if (ctx.status === "deprecated")
587
+ return [{ what: `${forge} release ${tag} unchanged: a forge release has no deprecation; yank marks it` }];
588
+ const channel = ctx.tag !== null;
589
+ // #5166: a prerelease label was published as a prerelease, never the latest, and a restore keeps it one.
590
+ const prerelease = prereleaseOf(ctx.label) !== null;
591
+ const isHead = ctx.head?.releaseDigest === ctx.release.releaseDigest;
592
+ const headTag = ctx.head && !isHead ? (decl.tag ?? ctx.head.releaseTag) : null;
593
+ const moveLatest = decl.forge === "github" && decl.latest !== false && !channel && !prerelease;
594
+ if (ctx.status === "yanked" && prerelease && ctx.forgeYank === "prerelease" && decl.forge !== "gitlab") {
595
+ return [{
596
+ what: `${forge} release ${tag} stays a prerelease`,
597
+ refused: { code: "release-status-forge-prerelease", message: `${ctx.label} is a prerelease, so its ${decl.forge} release is marked one already and marking it again withdraws nothing`, fix: "Pass --forge-release draft or --forge-release delete to withdraw it." },
598
+ }];
599
+ }
600
+ if (ctx.status === "yanked" && decl.forge === "gitlab" && ctx.forgeYank !== "delete") {
601
+ return [{
602
+ what: `${forge} release ${tag} stays published`,
603
+ refused: { code: "release-status-forge-unsupported", message: `a GitLab release has no prerelease or draft state to move release ${tag} to`, fix: "Pass --forge-release delete to delete the GitLab release; its tag and packages stay." },
604
+ }];
605
+ }
606
+ const plan = ctx.status === "yanked"
607
+ ? [
608
+ { what: ctx.forgeYank === "prerelease" ? `mark ${forge} release ${tag} a prerelease` : ctx.forgeYank === "draft" ? `make ${forge} release ${tag} a draft again` : `delete ${forge} release ${tag} (its tag stays)` },
609
+ ...(moveLatest && headTag && headTag !== tag ? [{ what: `make ${forge} release ${headTag} the latest` }] : []),
610
+ ]
611
+ : [{ what: `publish ${forge} release ${tag} again${moveLatest && isHead ? ", as the latest" : ""}` }];
612
+ if (!ctx.apply)
613
+ return plan;
614
+ const api = forgeApi(decl, ctx.env);
615
+ if (!api)
616
+ throw new PublishTargetError("publish-forge-no-api", "a Forgejo target needs its API root, and neither api nor GITHUB_API_URL is set", "Set api, such as https://forgejo.example/api/v1.");
617
+ const token = readCredential(ctx.env, tokenNames, ctx.redactor);
618
+ if (!token)
619
+ throw new PublishTargetError("publish-credentials-missing", `the ${decl.forge} target reads its token from ${tokenNames.join(" or ")}, and none is set`, `Set ${tokenNames[0]} in the job's or the shell's environment.`);
620
+ const client = new ForgeClient(decl, api, token, fetchImpl, ctx);
621
+ const rel = await client.published(tag);
622
+ const actions = [];
623
+ if (ctx.status === "yanked") {
624
+ if (!rel) {
625
+ actions.push({ what: `${forge} has no published release ${tag}; nothing to yank there`, already: true });
626
+ }
627
+ else if (ctx.forgeYank === "prerelease") {
628
+ if (rel.prerelease)
629
+ actions.push({ what: `${forge} release ${tag} is already a prerelease`, already: true });
630
+ else {
631
+ await client.edit(rel.id, tag, { prerelease: true, ...(decl.forge === "github" ? { make_latest: "false" } : {}) });
632
+ actions.push(plan[0]);
633
+ }
634
+ }
635
+ else if (ctx.forgeYank === "draft") {
636
+ await client.edit(rel.id, tag, { draft: true });
637
+ actions.push(plan[0]);
638
+ }
639
+ else {
640
+ await client.remove(rel, tag);
641
+ actions.push(plan[0]);
642
+ }
643
+ if (moveLatest && headTag && headTag !== tag) {
644
+ const head = await client.published(headTag);
645
+ if (head) {
646
+ await client.edit(head.id, headTag, { make_latest: "true" });
647
+ actions.push({ what: `make ${forge} release ${headTag} the latest` });
648
+ }
649
+ else {
650
+ actions.push({ what: `${forge} has no published release ${headTag} to make the latest`, already: true });
651
+ }
652
+ }
653
+ return actions;
654
+ }
655
+ const latest = moveLatest && isHead ? { make_latest: "true" } : {};
656
+ if (rel) {
657
+ if (rel.prerelease && !prerelease && !(decl.forge === "forgejo" && channel)) {
658
+ await client.edit(rel.id, tag, { prerelease: false, ...latest });
659
+ return [{ what: `clear the prerelease mark of ${forge} release ${tag}${moveLatest && isHead ? ", as the latest" : ""}` }];
660
+ }
661
+ return [{ what: `${forge} release ${tag} is published`, already: true }];
662
+ }
663
+ const draft = decl.forge === "gitlab" ? null : await client.draftFor(tag);
664
+ if (draft) {
665
+ await client.edit(draft.id, tag, { draft: false, ...latest });
666
+ return [{ what: `publish the draft ${forge} release ${tag}${moveLatest && isHead ? ", as the latest" : ""}` }];
667
+ }
668
+ return [{
669
+ what: `${forge} release ${tag} stays deleted`,
670
+ refused: { code: "release-status-forge-deleted", message: `${forge} has no release ${tag}, published or draft, so a yank deleted it and there is nothing to publish again`, fix: `Make the release again by hand from tag ${tag}, or cut a new release.` },
671
+ }];
672
+ },
314
673
  async plan(ctx) {
315
- const { tag, assets, notes } = setup(ctx);
674
+ const { tag, assets, signatures, section } = setup(ctx);
675
+ const notes = await releaseNotes(ctx, tag, section, null);
316
676
  return [
317
677
  ...assets.map((a) => ({ name: a.path, destination: where(tag, a.name), digest: a.digest, ...att(a) })),
318
- ...(notes !== undefined ? [{ name: decl.notes.file, destination: `${decl.forge} ${decl.repo} release ${tag}, notes`, notes }] : []),
678
+ ...signatures.map((x) => sigItem(ctx, tag, x)),
679
+ ...(notes !== undefined ? [{ name: decl.notes.file ?? "generated notes", destination: `${decl.forge} ${decl.repo} release ${tag}, notes`, notes }] : []),
319
680
  ];
320
681
  },
321
682
  async stage(ctx) {
322
- const { tag, api, token, assets, notes } = setup(ctx);
683
+ const { tag, api, token, assets, signatures, section } = setup(ctx);
323
684
  ctx.log(`using the token from ${token.from}`);
324
685
  const client = new ForgeClient(decl, api, token, fetchImpl, ctx);
325
686
  const done = (items, state) => ({ target: this.name, destination: this.destination, items, state });
@@ -336,9 +697,19 @@ export function forgeTarget(decl, deps) {
336
697
  throw exists(tag, a, theirs, items);
337
698
  items.push({ name: a.path, destination: where(tag, a.name), digest: a.digest, ...att(a), present: true });
338
699
  }
700
+ // #5164: a bundle signed by an earlier run is kept; signing again gives other bytes.
701
+ for (const x of signatures) {
702
+ if (!published.assets.has(x.name)) {
703
+ throw new PublishTargetError("publish-forge-release-published", `release ${tag} on ${decl.forge} ${decl.repo} is already published without ${x.name}, so the signatures uploaded to it would show after its assets`, "Delete the forge release so the publish makes it whole, or set release.signing: false.");
704
+ }
705
+ items.push(sigItem(ctx, tag, x, { digest: published.assets.get(x.name) ?? null, present: true }));
706
+ }
339
707
  ctx.log(`release ${tag} is already published with every asset`);
340
708
  return done(items, { published: "true" });
341
709
  }
710
+ // #5153: the notes are decided here and kept in the record, so the reveal publishes what the draft shows.
711
+ const notes = await releaseNotes(ctx, tag, section, client);
712
+ const kept = notes !== undefined ? { notes } : {};
342
713
  const version = gitlabPackageVersion(ctx.label ?? tag);
343
714
  if (decl.forge === "gitlab") {
344
715
  // No draft on GitLab: the assets go to the package registry, and the release is made at the reveal.
@@ -347,7 +718,9 @@ export function forgeTarget(decl, deps) {
347
718
  ctx.log(`uploading ${a.name} (${a.bytes.byteLength} bytes) to the generic package registry`);
348
719
  items.push({ name: a.path, destination: await client.upload(null, version, a), digest: a.digest, ...att(a) });
349
720
  }
350
- return done(items, {});
721
+ for (const x of signatures)
722
+ items.push(await signAndUpload(ctx, client, null, version, tag, x));
723
+ return done(items, kept);
351
724
  }
352
725
  const rel = await client.draft(tag, ctx.release.commit, ctx.label ?? tag, notes);
353
726
  const items = [];
@@ -363,14 +736,32 @@ export function forgeTarget(decl, deps) {
363
736
  ctx.log(`uploading ${a.name} (${a.bytes.byteLength} bytes) to the draft`);
364
737
  items.push({ name: a.path, destination: await client.upload(rel, version, a), digest: a.digest, ...att(a) });
365
738
  }
366
- return done(items, { releaseId: rel.id });
739
+ for (const x of signatures) {
740
+ if (rel.assets.has(x.name)) {
741
+ ctx.log(`${x.name} is already on the draft release ${tag}; it is not signed again`);
742
+ items.push(sigItem(ctx, tag, x, { digest: rel.assets.get(x.name) ?? null, present: true }));
743
+ continue;
744
+ }
745
+ items.push(await signAndUpload(ctx, client, rel, version, tag, x));
746
+ }
747
+ return done(items, { releaseId: rel.id, ...(rel.url ? { releaseUrl: rel.url } : {}), ...kept });
367
748
  },
368
749
  async reveal(ctx, staged) {
369
- const { tag, api, token, notes } = setup(ctx);
750
+ const { tag, api, token, section } = setup(ctx);
370
751
  const client = new ForgeClient(decl, api, token, fetchImpl, ctx);
371
- const items = staged.items.map((i) => ({ name: i.name, destination: i.destination, ...(i.digest ? { digest: i.digest } : {}), ...(i.attachment ? { attachment: i.attachment } : {}) }));
752
+ const items = staged.items.map((i) => ({
753
+ name: i.name,
754
+ destination: i.destination,
755
+ ...(i.digest ? { digest: i.digest } : {}),
756
+ ...(i.attachment ? { attachment: i.attachment } : {}),
757
+ ...(i.signs ? { signs: i.signs } : {}),
758
+ ...(i.predicateType ? { predicateType: i.predicateType } : {}),
759
+ ...(i.sigstore ? { sigstore: i.sigstore } : {}),
760
+ }));
372
761
  if (staged.state.published === "true")
373
762
  return { target: this.name, destination: this.destination, items: items.map((i) => ({ ...i, present: true })) };
763
+ // The notes the stage decided; a stage recorded before chant kept them has them decided again.
764
+ const notes = staged.state.notes ?? (await releaseNotes(ctx, tag, section, client));
374
765
  if (decl.forge === "gitlab") {
375
766
  ctx.log(`creating the gitlab release ${tag} at ${ctx.release.commit.slice(0, 12)} with ${items.length} asset link(s)`);
376
767
  await client.createWithLinks(tag, ctx.release.commit, ctx.label ?? tag, items.map((i) => ({ name: basename(i.name), url: i.destination })), notes);
@@ -380,9 +771,18 @@ export function forgeTarget(decl, deps) {
380
771
  if (!id)
381
772
  throw new PublishTargetError("publish-forge-failed", `the staged ${decl.forge} release for ${tag} has no draft id to publish`);
382
773
  const channel = ctx.tag !== null;
383
- const latest = decl.forge === "github" ? ` with make_latest ${String(decl.latest ?? !channel)}` : channel ? " as a prerelease, since it was cut to a channel" : "";
774
+ const prerelease = prereleaseOf(ctx.label) !== null;
775
+ const latest = decl.forge === "github"
776
+ ? prerelease
777
+ ? " as a prerelease, since its label is one, with make_latest false"
778
+ : ` with make_latest ${String(decl.latest ?? !channel)}`
779
+ : prerelease
780
+ ? " as a prerelease, since its label is one"
781
+ : channel
782
+ ? " as a prerelease, since it was cut to a channel"
783
+ : "";
384
784
  ctx.log(`publishing the draft ${decl.forge} release ${tag}${notes !== undefined ? " with its notes" : ""}${latest}`);
385
- await client.publishDraft(id, tag, { ...(notes !== undefined ? { notes } : {}), channel });
785
+ await client.publishDraft(id, tag, { ...(notes !== undefined ? { notes } : {}), channel, prerelease });
386
786
  }
387
787
  return { target: this.name, destination: this.destination, items };
388
788
  },
@@ -67,10 +67,25 @@ export declare class SshGitRepo {
67
67
  * the head fast-forwards a branch at that parent.
68
68
  */
69
69
  fetch(branch: string, depth?: number): Promise<string>;
70
+ /** The fetched commits of `branch` that touch `path`, newest first (#5163). Fetch the branch deep enough first. */
71
+ history(branch: string, path: string): Promise<string[]>;
70
72
  /** The bytes of `path` at a fetched commit, or null when it holds no such file. */
71
73
  file(commit: string, path: string): Promise<Buffer | null>;
74
+ /** The commit a submodule at `path` points to at a fetched commit, or null when `path` is not a submodule there (#5158). */
75
+ gitlink(commit: string, path: string): Promise<string | null>;
72
76
  /** A commit on `parent` that writes `bytes` to `path`, with `message`. Made here, not pushed. */
73
77
  commitFile(parent: string, path: string, bytes: Uint8Array, message: string): Promise<string>;
78
+ /** A commit on `parent` that writes each file, points each submodule path at its commit (#5158) and removes each `remove` path (#5163). Made here, not pushed. */
79
+ commitFiles(parent: string, changes: ReadonlyArray<{
80
+ path: string;
81
+ bytes: Uint8Array;
82
+ } | {
83
+ path: string;
84
+ gitlink: string;
85
+ } | {
86
+ path: string;
87
+ remove: true;
88
+ }>, message: string): Promise<string>;
74
89
  /**
75
90
  * Push `commit` to `branch`. `force` moves it wherever it is; without it,
76
91
  * a branch that does not fast-forward comes back `rejected`.