@intentius/chant 0.124.62 → 0.124.64

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 (262) hide show
  1. package/dist/cli/handlers/approve.d.ts +26 -0
  2. package/dist/cli/handlers/approve.d.ts.map +1 -1
  3. package/dist/cli/handlers/approve.js +167 -18
  4. package/dist/cli/handlers/plan.d.ts +10 -0
  5. package/dist/cli/handlers/plan.d.ts.map +1 -0
  6. package/dist/cli/handlers/plan.js +71 -0
  7. package/dist/cli/handlers/pr.d.ts.map +1 -1
  8. package/dist/cli/handlers/pr.js +2 -1
  9. package/dist/cli/handlers/release.d.ts +11 -7
  10. package/dist/cli/handlers/release.d.ts.map +1 -1
  11. package/dist/cli/handlers/release.js +93 -20
  12. package/dist/cli/main.d.ts.map +1 -1
  13. package/dist/cli/main.js +48 -7
  14. package/dist/cli/mcp/workspace-tools.d.ts.map +1 -1
  15. package/dist/cli/mcp/workspace-tools.js +2 -1
  16. package/dist/cli/parse-args.d.ts.map +1 -1
  17. package/dist/cli/parse-args.js +43 -0
  18. package/dist/cli/registry.d.ts +18 -2
  19. package/dist/cli/registry.d.ts.map +1 -1
  20. package/dist/config.d.ts +50 -0
  21. package/dist/config.d.ts.map +1 -1
  22. package/dist/config.js +1 -0
  23. package/dist/gate-decision.d.ts +1 -1
  24. package/dist/gate-decision.d.ts.map +1 -1
  25. package/dist/gate-decision.js +4 -2
  26. package/dist/gate-statement.schema.json +46 -0
  27. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +20 -0
  28. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
  29. package/dist/lifecycle/__fixtures__/publish-fakes.js +119 -3
  30. package/dist/lifecycle/gate-ledger.d.ts +28 -5
  31. package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
  32. package/dist/lifecycle/gate-ledger.js +6 -0
  33. package/dist/lifecycle/gate-seal.d.ts +59 -7
  34. package/dist/lifecycle/gate-seal.d.ts.map +1 -1
  35. package/dist/lifecycle/gate-seal.js +68 -15
  36. package/dist/lifecycle/gate-statement.d.ts +95 -0
  37. package/dist/lifecycle/gate-statement.d.ts.map +1 -0
  38. package/dist/lifecycle/gate-statement.js +110 -0
  39. package/dist/lifecycle/gate-webauthn.d.ts +79 -0
  40. package/dist/lifecycle/gate-webauthn.d.ts.map +1 -0
  41. package/dist/lifecycle/gate-webauthn.js +105 -0
  42. package/dist/lifecycle/git.d.ts +1 -1
  43. package/dist/lifecycle/git.d.ts.map +1 -1
  44. package/dist/lifecycle/git.js +24 -19
  45. package/dist/lifecycle/ledger-remote.d.ts +37 -0
  46. package/dist/lifecycle/ledger-remote.d.ts.map +1 -0
  47. package/dist/lifecycle/ledger-remote.js +42 -0
  48. package/dist/lifecycle/plan-stale.d.ts +76 -0
  49. package/dist/lifecycle/plan-stale.d.ts.map +1 -0
  50. package/dist/lifecycle/plan-stale.js +120 -0
  51. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  52. package/dist/lifecycle/publish-credentials.d.ts.map +1 -1
  53. package/dist/lifecycle/publish-credentials.js +2 -0
  54. package/dist/lifecycle/publish-declaration.d.ts +107 -0
  55. package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
  56. package/dist/lifecycle/publish-declaration.js +110 -1
  57. package/dist/lifecycle/publish-forge.d.ts +5 -1
  58. package/dist/lifecycle/publish-forge.d.ts.map +1 -1
  59. package/dist/lifecycle/publish-forge.js +13 -4
  60. package/dist/lifecycle/publish-git-ssh.d.ts +82 -0
  61. package/dist/lifecycle/publish-git-ssh.d.ts.map +1 -0
  62. package/dist/lifecycle/publish-git-ssh.js +180 -0
  63. package/dist/lifecycle/publish-github.d.ts +69 -0
  64. package/dist/lifecycle/publish-github.d.ts.map +1 -0
  65. package/dist/lifecycle/publish-github.js +153 -0
  66. package/dist/lifecycle/publish-homebrew.d.ts +77 -0
  67. package/dist/lifecycle/publish-homebrew.d.ts.map +1 -0
  68. package/dist/lifecycle/publish-homebrew.js +265 -0
  69. package/dist/lifecycle/publish-marketplace.d.ts +85 -0
  70. package/dist/lifecycle/publish-marketplace.d.ts.map +1 -0
  71. package/dist/lifecycle/publish-marketplace.js +398 -0
  72. package/dist/lifecycle/publish-targets.d.ts +6 -0
  73. package/dist/lifecycle/publish-targets.d.ts.map +1 -1
  74. package/dist/lifecycle/publish-targets.js +15 -0
  75. package/dist/lifecycle/publish-tauri.d.ts +61 -0
  76. package/dist/lifecycle/publish-tauri.d.ts.map +1 -0
  77. package/dist/lifecycle/publish-tauri.js +181 -0
  78. package/dist/lifecycle/release-cut.d.ts +51 -5
  79. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  80. package/dist/lifecycle/release-cut.js +165 -16
  81. package/dist/lifecycle/release-publish.d.ts +18 -2
  82. package/dist/lifecycle/release-publish.d.ts.map +1 -1
  83. package/dist/lifecycle/release-publish.js +5 -0
  84. package/dist/lifecycle/release-revocation.d.ts +4 -3
  85. package/dist/lifecycle/release-revocation.d.ts.map +1 -1
  86. package/dist/lifecycle/release-revocation.js +5 -4
  87. package/dist/lifecycle/release-store.d.ts +32 -0
  88. package/dist/lifecycle/release-store.d.ts.map +1 -1
  89. package/dist/lifecycle/release-store.js +11 -0
  90. package/dist/lifecycle/snapshot-store.d.ts.map +1 -1
  91. package/dist/lifecycle/snapshot-store.js +17 -9
  92. package/dist/lifecycle/test-passkey.d.ts +25 -0
  93. package/dist/lifecycle/test-passkey.d.ts.map +1 -0
  94. package/dist/lifecycle/test-passkey.js +39 -0
  95. package/dist/notify.d.ts +23 -3
  96. package/dist/notify.d.ts.map +1 -1
  97. package/dist/notify.js +8 -2
  98. package/dist/notify.schema.json +12 -3
  99. package/dist/op/gate.d.ts +1 -1
  100. package/dist/op/gate.d.ts.map +1 -1
  101. package/dist/op/gate.js +2 -1
  102. package/dist/pr-forge.d.ts +20 -0
  103. package/dist/pr-forge.d.ts.map +1 -1
  104. package/dist/pr-forge.js +87 -8
  105. package/dist/release-floors.d.ts +1 -1
  106. package/dist/release-floors.js +1 -1
  107. package/dist/wave-runtime.mjs +333 -331
  108. package/dist/workspace/ci-builds.d.ts +21 -0
  109. package/dist/workspace/ci-builds.d.ts.map +1 -1
  110. package/dist/workspace/ci-builds.js +14 -0
  111. package/dist/workspace/ci-green.d.ts +45 -2
  112. package/dist/workspace/ci-green.d.ts.map +1 -1
  113. package/dist/workspace/ci-green.js +123 -5
  114. package/dist/workspace/ci-quarantine-report.d.ts +80 -0
  115. package/dist/workspace/ci-quarantine-report.d.ts.map +1 -0
  116. package/dist/workspace/ci-quarantine-report.js +204 -0
  117. package/dist/workspace/ci-quarantine.d.ts +73 -0
  118. package/dist/workspace/ci-quarantine.d.ts.map +1 -0
  119. package/dist/workspace/ci-quarantine.js +170 -0
  120. package/dist/workspace/ci-serve.d.ts.map +1 -1
  121. package/dist/workspace/ci-serve.js +7 -4
  122. package/dist/workspace/class-data.d.ts +3 -1
  123. package/dist/workspace/class-data.d.ts.map +1 -1
  124. package/dist/workspace/class-data.js +4 -1
  125. package/dist/workspace/declaration.d.ts +45 -2
  126. package/dist/workspace/declaration.d.ts.map +1 -1
  127. package/dist/workspace/declaration.js +45 -2
  128. package/dist/workspace/declaration.schema.json +51 -3
  129. package/dist/workspace/forge-work.d.ts +76 -0
  130. package/dist/workspace/forge-work.d.ts.map +1 -0
  131. package/dist/workspace/forge-work.js +160 -0
  132. package/dist/workspace/identity-gate-rule.d.ts +3 -2
  133. package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
  134. package/dist/workspace/identity-gate-rule.js +5 -7
  135. package/dist/workspace/identity.d.ts +3 -2
  136. package/dist/workspace/identity.d.ts.map +1 -1
  137. package/dist/workspace/identity.js +6 -3
  138. package/dist/workspace/intent-cli.d.ts +3 -2
  139. package/dist/workspace/intent-cli.d.ts.map +1 -1
  140. package/dist/workspace/intent-cli.js +26 -5
  141. package/dist/workspace/intent-record.d.ts +3 -0
  142. package/dist/workspace/intent-record.d.ts.map +1 -1
  143. package/dist/workspace/intent-record.schema.json +32 -0
  144. package/dist/workspace/intent.d.ts +9 -0
  145. package/dist/workspace/intent.d.ts.map +1 -1
  146. package/dist/workspace/intent.js +2 -0
  147. package/dist/workspace/intent.schema.json +32 -0
  148. package/dist/workspace/kind-readers.d.ts.map +1 -1
  149. package/dist/workspace/kind-readers.js +2 -1
  150. package/dist/workspace/kinds.d.ts +6 -1
  151. package/dist/workspace/kinds.d.ts.map +1 -1
  152. package/dist/workspace/kinds.js +8 -3
  153. package/dist/workspace/plan-stale.schema.json +286 -0
  154. package/dist/workspace/release-candidates.d.ts +42 -7
  155. package/dist/workspace/release-candidates.d.ts.map +1 -1
  156. package/dist/workspace/release-candidates.js +64 -23
  157. package/dist/workspace/release-candidates.schema.json +55 -2
  158. package/dist/workspace/releases.schema.json +47 -0
  159. package/dist/workspace/trust/policy.d.ts +10 -0
  160. package/dist/workspace/trust/policy.d.ts.map +1 -1
  161. package/dist/workspace/trust/policy.js +19 -1
  162. package/dist/workspace/trust/run-commits.d.ts.map +1 -1
  163. package/dist/workspace/trust/run-commits.js +2 -1
  164. package/dist/workspace/trust/seal.d.ts.map +1 -1
  165. package/dist/workspace/trust/seal.js +34 -3
  166. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  167. package/dist/workspace/trust/trust-files.js +6 -1
  168. package/package.json +2 -1
  169. package/src/cli/handlers/approve-external-signature.test.ts +328 -0
  170. package/src/cli/handlers/approve.ts +206 -18
  171. package/src/cli/handlers/plan.ts +74 -0
  172. package/src/cli/handlers/pr.ts +2 -1
  173. package/src/cli/handlers/release.ts +84 -20
  174. package/src/cli/main.ts +48 -7
  175. package/src/cli/mcp/workspace-tools.ts +2 -1
  176. package/src/cli/parse-args.ts +33 -0
  177. package/src/cli/registry.ts +18 -2
  178. package/src/config.ts +8 -0
  179. package/src/gate-decision-bundle.test.ts +4 -2
  180. package/src/gate-decision.ts +11 -2
  181. package/src/gate-statement.schema.json +46 -0
  182. package/src/lifecycle/__fixtures__/publish-fakes.ts +125 -5
  183. package/src/lifecycle/gate-ledger.ts +34 -5
  184. package/src/lifecycle/gate-seal.ts +86 -15
  185. package/src/lifecycle/gate-statement.ts +144 -0
  186. package/src/lifecycle/gate-webauthn.test.ts +77 -0
  187. package/src/lifecycle/gate-webauthn.ts +133 -0
  188. package/src/lifecycle/git.ts +23 -19
  189. package/src/lifecycle/ledger-remote.test.ts +183 -0
  190. package/src/lifecycle/ledger-remote.ts +46 -0
  191. package/src/lifecycle/plan-stale.test.ts +149 -0
  192. package/src/lifecycle/plan-stale.ts +172 -0
  193. package/src/lifecycle/publish-credentials.ts +2 -0
  194. package/src/lifecycle/publish-declaration.ts +116 -1
  195. package/src/lifecycle/publish-forge.ts +14 -4
  196. package/src/lifecycle/publish-git-ssh.ts +202 -0
  197. package/src/lifecycle/publish-github.ts +174 -0
  198. package/src/lifecycle/publish-homebrew.test.ts +358 -0
  199. package/src/lifecycle/publish-homebrew.ts +283 -0
  200. package/src/lifecycle/publish-marketplace.test.ts +406 -0
  201. package/src/lifecycle/publish-marketplace.ts +421 -0
  202. package/src/lifecycle/publish-resume.test.ts +40 -0
  203. package/src/lifecycle/publish-target-context.test.ts +2 -2
  204. package/src/lifecycle/publish-targets.test.ts +23 -0
  205. package/src/lifecycle/publish-targets.ts +15 -0
  206. package/src/lifecycle/publish-tauri.test.ts +163 -0
  207. package/src/lifecycle/publish-tauri.ts +198 -0
  208. package/src/lifecycle/release-cut-lane.test.ts +177 -0
  209. package/src/lifecycle/release-cut-override.test.ts +213 -0
  210. package/src/lifecycle/release-cut.ts +198 -17
  211. package/src/lifecycle/release-publish.ts +23 -3
  212. package/src/lifecycle/release-revocation.ts +5 -4
  213. package/src/lifecycle/release-store.ts +44 -0
  214. package/src/lifecycle/snapshot-store.ts +16 -9
  215. package/src/lifecycle/test-passkey.ts +55 -0
  216. package/src/notify-bundle.test.ts +3 -1
  217. package/src/notify.schema.json +12 -3
  218. package/src/notify.ts +20 -3
  219. package/src/op/gate.ts +2 -1
  220. package/src/override-gate-bundle.test.ts +2 -0
  221. package/src/pr-forge-bundle.test.ts +2 -2
  222. package/src/pr-forge.test.ts +38 -0
  223. package/src/pr-forge.ts +93 -11
  224. package/src/pr-requires.test.ts +9 -0
  225. package/src/release-floors.ts +1 -1
  226. package/src/stage-hooks-bundle.test.ts +2 -0
  227. package/src/wave-runtime-bundle.test.ts +3 -2
  228. package/src/workspace/ci-builds.ts +27 -0
  229. package/src/workspace/ci-green-stale.test.ts +193 -0
  230. package/src/workspace/ci-green.ts +137 -6
  231. package/src/workspace/ci-quarantine-report.test.ts +145 -0
  232. package/src/workspace/ci-quarantine-report.ts +234 -0
  233. package/src/workspace/ci-quarantine.test.ts +160 -0
  234. package/src/workspace/ci-quarantine.ts +188 -0
  235. package/src/workspace/ci-serve.ts +7 -4
  236. package/src/workspace/class-data.ts +5 -1
  237. package/src/workspace/declaration.schema.json +51 -3
  238. package/src/workspace/declaration.test.ts +1 -0
  239. package/src/workspace/declaration.ts +88 -5
  240. package/src/workspace/forge-work.test.ts +143 -0
  241. package/src/workspace/forge-work.ts +195 -0
  242. package/src/workspace/identity-gate-rule.ts +6 -8
  243. package/src/workspace/identity.ts +6 -3
  244. package/src/workspace/intent-cli.ts +24 -5
  245. package/src/workspace/intent-record.schema.json +32 -0
  246. package/src/workspace/intent-record.ts +3 -0
  247. package/src/workspace/intent.schema.json +32 -0
  248. package/src/workspace/intent.ts +9 -0
  249. package/src/workspace/kind-readers.ts +2 -1
  250. package/src/workspace/kinds.test.ts +13 -0
  251. package/src/workspace/kinds.ts +12 -3
  252. package/src/workspace/plan-stale.schema.json +286 -0
  253. package/src/workspace/release-candidates.schema.json +55 -2
  254. package/src/workspace/release-candidates.test.ts +77 -4
  255. package/src/workspace/release-candidates.ts +80 -23
  256. package/src/workspace/releases.schema.json +47 -0
  257. package/src/workspace/trust/gate-seal.test.ts +44 -0
  258. package/src/workspace/trust/policy.ts +24 -1
  259. package/src/workspace/trust/run-commits.ts +2 -1
  260. package/src/workspace/trust/seal.ts +35 -3
  261. package/src/workspace/trust/trust-files.test.ts +5 -0
  262. package/src/workspace/trust/trust-files.ts +15 -1
@@ -0,0 +1,421 @@
1
+ /**
2
+ * The editor marketplace target (#4676): a packaged `.vsix` published to the
3
+ * VS Code Marketplace or to Open VSX.
4
+ *
5
+ * The extension's publisher, name and version are read from the
6
+ * `extension/package.json` inside the `.vsix`, and the file must match the
7
+ * digest the release records for it.
8
+ *
9
+ * A marketplace has no draft: a version is visible as soon as it is
10
+ * uploaded, and a version can't be uploaded twice. So the stage uploads
11
+ * nothing. It checks what it can without changing anything: the file and its
12
+ * digest, the token, and whether the marketplace already has the version.
13
+ * The reveal uploads. A failure of another target's stage therefore leaves
14
+ * nothing on a marketplace, and a marketplace's own failure shows only at the
15
+ * reveal, after the targets before it revealed.
16
+ *
17
+ * - Open VSX, through its REST API: the stage reads
18
+ * `GET {registry}/api/{namespace}` (a missing namespace is refused before
19
+ * anything reveals) and `GET {registry}/api/{namespace}/{name}/{version}`.
20
+ * A version already there is `present` when its download's SHA-256 is the
21
+ * file's, and refused otherwise (`publish-marketplace-version-exists`). The
22
+ * reveal sends the file with `POST {registry}/api/-/publish`, then
23
+ * downloads what Open VSX serves for the version and refuses a digest that
24
+ * differs (`publish-marketplace-digest-mismatch`).
25
+ * - The VS Code Marketplace, through `vsce`: the stage asks the gallery's
26
+ * public `extensionquery` API for the extension's versions, and a version
27
+ * already there is `present`, by version only, since the gallery reports no
28
+ * digest. The reveal runs `vsce publish --packagePath <file>` with the
29
+ * token in `VSCE_PAT`. `vsce` must be on `PATH` (`npm i -g @vscode/vsce`).
30
+ *
31
+ * The token is read from `tokenEnv`, else `VSCE_PAT` or `OVSX_PAT`, the
32
+ * variables `vsce` and `ovsx` read, and is masked in all output.
33
+ *
34
+ * Or the target authenticates with the run's identity, with no stored
35
+ * token (#4698):
36
+ *
37
+ * - `auth: "azure-credential"` (VS Code Marketplace): `vsce` runs with
38
+ * `--azure-credential`, which gets a Microsoft Entra token from the job's
39
+ * Azure sign-in, such as the one `azure/login` makes from the run's OIDC
40
+ * token. `VSCE_PAT` is taken out of vsce's environment, since vsce prefers
41
+ * a PAT it finds there. The stage runs
42
+ * `vsce verify-pat --azure-credential <publisher>`, which signs in and asks
43
+ * the marketplace for the identity's role on the publisher, and changes
44
+ * nothing.
45
+ * - `auth: "trusted-publishing"` (Open VSX): the run's OIDC ID token, from
46
+ * GitHub Actions (a job with `id-token: write`) or from `OVSX_ID_TOKEN`, is
47
+ * exchanged at `POST {registry}/api/-/trusted-publishing/token` for a
48
+ * publishing token that lasts minutes, as `ovsx publish --trusted-publishing`
49
+ * does. The stage makes the exchange to check that Open VSX takes this
50
+ * workflow as a trusted publisher of the extension, and drops the token;
51
+ * the reveal exchanges again for the upload.
52
+ *
53
+ * With `onRefusal: "warn"`, a marketplace that refuses the reveal's upload,
54
+ * or a request around it, is a warning: the reveal returns the target with
55
+ * its items `refused` and a `warning`, and the publish goes on. Every check
56
+ * the stage makes still refuses, and so does a digest that differs after an
57
+ * upload.
58
+ */
59
+
60
+ import { spawn } from "node:child_process";
61
+ import { readFileSync } from "node:fs";
62
+ import { inflateRawSync } from "node:zlib";
63
+ import { readCredential, type Credential } from "./publish-credentials";
64
+ import type { MarketplacePublishDeclaration } from "./publish-declaration";
65
+ import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets";
66
+ import {
67
+ PublishTargetError,
68
+ type PublishContext,
69
+ type PublishDeps,
70
+ type PublishedTarget,
71
+ type PublishFetch,
72
+ type PublishItem,
73
+ type PublishTarget,
74
+ type StagedTarget,
75
+ } from "./release-publish";
76
+ import { NEXT_RELEASE } from "../release-floors";
77
+
78
+ /** The first chant that publishes a `marketplace` target (#4676). */
79
+ export const PUBLISH_MARKETPLACE_FLOOR = "0.124.63";
80
+
81
+ /** The first chant that reads a marketplace target's `auth` (#4698). */
82
+ export const PUBLISH_MARKETPLACE_AUTH_FLOOR = NEXT_RELEASE;
83
+
84
+ /** The first chant that reads a marketplace target's `onRefusal` (#4698). */
85
+ export const PUBLISH_MARKETPLACE_ON_REFUSAL_FLOOR = NEXT_RELEASE;
86
+
87
+ export const OPEN_VSX_REGISTRY = "https://open-vsx.org";
88
+ export const VSCODE_GALLERY = "https://marketplace.visualstudio.com";
89
+
90
+ /** The variable an OIDC ID token for Open VSX is read from outside GitHub Actions, as `ovsx` reads it. */
91
+ export const OVSX_ID_TOKEN_ENV = "OVSX_ID_TOKEN";
92
+
93
+ export type MarketplaceAuth = NonNullable<MarketplacePublishDeclaration["auth"]>;
94
+
95
+ /** The declaration's `auth`, refused when the marketplace does not take it or when `tokenEnv` is set with another. */
96
+ export function marketplaceAuth(decl: Pick<MarketplacePublishDeclaration, "marketplace" | "auth" | "tokenEnv">): MarketplaceAuth {
97
+ const auth = decl.auth ?? "token";
98
+ const wrong =
99
+ auth === "azure-credential" && decl.marketplace !== "vscode"
100
+ ? "auth: azure-credential is the VS Code Marketplace's; Open VSX takes token or trusted-publishing"
101
+ : auth === "trusted-publishing" && decl.marketplace !== "openvsx"
102
+ ? "auth: trusted-publishing is Open VSX's; the VS Code Marketplace takes token or azure-credential"
103
+ : auth !== "token" && decl.tokenEnv !== undefined
104
+ ? `tokenEnv names a token, and auth: ${auth} reads none`
105
+ : null;
106
+ if (wrong) throw new PublishTargetError("publish-marketplace-auth-invalid", `a marketplace target for ${decl.marketplace}: ${wrong}`, "Fix the target in release.publish in chant.config.ts.");
107
+ return auth;
108
+ }
109
+
110
+ /** The variables a marketplace's credential is read from, whose values are masked. */
111
+ export function marketplaceTokenEnv(decl: Pick<MarketplacePublishDeclaration, "marketplace" | "tokenEnv" | "auth">): string[] {
112
+ const auth = decl.auth ?? "token";
113
+ // vsce's Entra sign-in reads a client secret from AZURE_CLIENT_SECRET when one is set; chant reads none.
114
+ if (auth === "azure-credential") return ["AZURE_CLIENT_SECRET"];
115
+ if (auth === "trusted-publishing") return [OVSX_ID_TOKEN_ENV];
116
+ return [decl.tokenEnv ?? (decl.marketplace === "vscode" ? "VSCE_PAT" : "OVSX_PAT")];
117
+ }
118
+
119
+ /** The codes a reveal turns into a warning under `onRefusal: "warn"`: the marketplace refused or failed a request. */
120
+ const REFUSALS = new Set(["publish-marketplace-failed", "publish-marketplace-trusted-publishing"]);
121
+
122
+ /** One file of a zip archive, or null when it holds none by that name. Reads stored and deflated entries; refuses a zip64 archive. */
123
+ export function readZipEntry(zip: Buffer, name: string): Buffer | null {
124
+ let end = -1;
125
+ for (let i = zip.length - 22; i >= Math.max(0, zip.length - 22 - 0xffff); i--) {
126
+ if (zip.readUInt32LE(i) === 0x06054b50) {
127
+ end = i;
128
+ break;
129
+ }
130
+ }
131
+ if (end < 0) throw new Error("not a zip archive: no end of central directory");
132
+ const count = zip.readUInt16LE(end + 10);
133
+ let at = zip.readUInt32LE(end + 16);
134
+ if (count === 0xffff || at === 0xffffffff) throw new Error("a zip64 archive, which chant does not read");
135
+ for (let i = 0; i < count; i++) {
136
+ if (zip.readUInt32LE(at) !== 0x02014b50) throw new Error("a malformed zip central directory");
137
+ const method = zip.readUInt16LE(at + 10);
138
+ const size = zip.readUInt32LE(at + 20);
139
+ const nameLen = zip.readUInt16LE(at + 28);
140
+ const skip = nameLen + zip.readUInt16LE(at + 30) + zip.readUInt16LE(at + 32);
141
+ const local = zip.readUInt32LE(at + 42);
142
+ if (zip.toString("utf-8", at + 46, at + 46 + nameLen) === name) {
143
+ const data = local + 30 + zip.readUInt16LE(local + 26) + zip.readUInt16LE(local + 28);
144
+ const raw = zip.subarray(data, data + size);
145
+ if (method === 0) return Buffer.from(raw);
146
+ if (method === 8) return inflateRawSync(raw);
147
+ throw new Error(`${name} is compressed with method ${method}, which chant does not read`);
148
+ }
149
+ at += 46 + skip;
150
+ }
151
+ return null;
152
+ }
153
+
154
+ /** The publisher, name and version a `.vsix` declares. */
155
+ export function vsixIdentity(bytes: Buffer, path: string): { publisher: string; name: string; version: string } {
156
+ let manifest: { publisher?: unknown; name?: unknown; version?: unknown };
157
+ try {
158
+ const entry = readZipEntry(bytes, "extension/package.json");
159
+ if (!entry) throw new Error("it holds no extension/package.json");
160
+ manifest = JSON.parse(entry.toString("utf-8")) as typeof manifest;
161
+ } catch (err) {
162
+ throw new PublishTargetError("publish-marketplace-vsix-invalid", `${path} is not a .vsix chant can read: ${err instanceof Error ? err.message : String(err)}`, "Package it with vsce package.");
163
+ }
164
+ const { publisher, name, version } = manifest;
165
+ if (typeof publisher !== "string" || typeof name !== "string" || typeof version !== "string" || !publisher || !name || !version) {
166
+ throw new PublishTargetError("publish-marketplace-vsix-invalid", `${path}'s extension/package.json needs publisher, name and version`);
167
+ }
168
+ return { publisher, name, version };
169
+ }
170
+
171
+ function run(bin: string, args: string[], ctx: PublishContext, env: NodeJS.ProcessEnv): Promise<{ code: number; output: string[] }> {
172
+ return new Promise((resolvePromise, reject) => {
173
+ const child = spawn(bin, args, { cwd: ctx.cwd, env, stdio: ["ignore", "pipe", "pipe"] });
174
+ const chunks: string[] = [];
175
+ child.stdout.on("data", (c: Buffer) => chunks.push(c.toString("utf-8")));
176
+ child.stderr.on("data", (c: Buffer) => chunks.push(c.toString("utf-8")));
177
+ child.on("error", reject);
178
+ child.on("close", (code) =>
179
+ resolvePromise({
180
+ code: code ?? 1,
181
+ output: chunks.join("").split("\n").filter((l) => l.trim() !== "").map((l) => ctx.redactor.redact(l)),
182
+ }),
183
+ );
184
+ });
185
+ }
186
+
187
+ export function marketplaceTarget(decl: MarketplacePublishDeclaration, deps: PublishDeps): PublishTarget {
188
+ const fetchImpl: PublishFetch = deps.fetch ?? ((url, init) => fetch(url, init as RequestInit));
189
+ const auth = marketplaceAuth(decl);
190
+ const tokenNames = marketplaceTokenEnv(decl);
191
+ const label = decl.marketplace === "vscode" ? "VS Code Marketplace" : "Open VSX";
192
+ const registry = (decl.registry ?? (decl.marketplace === "vscode" ? VSCODE_GALLERY : OPEN_VSX_REGISTRY)).replace(/\/+$/, "");
193
+
194
+ const setup = (ctx: PublishContext) => {
195
+ const abs = memberFile(ctx.cwd, decl.vsix);
196
+ const bytes = readFileSync(abs);
197
+ const digest = bytesDigest(new Uint8Array(bytes));
198
+ checkReleaseDigest(ctx.release, "asset", ctx.cwd, decl.vsix, [digest]);
199
+ const id = vsixIdentity(bytes, decl.vsix);
200
+ let token: Credential | null = null;
201
+ if (auth === "token") {
202
+ token = readCredential(ctx.env, tokenNames, ctx.redactor);
203
+ if (!token) {
204
+ throw new PublishTargetError("publish-credentials-missing", `the ${label} target reads its token from ${tokenNames[0]}, and it is not set`, `Set ${tokenNames[0]} in the job's or the shell's environment.`);
205
+ }
206
+ }
207
+ if (auth === "trusted-publishing" && !ctx.env[OVSX_ID_TOKEN_ENV] && !(ctx.env.ACTIONS_ID_TOKEN_REQUEST_URL && ctx.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN)) {
208
+ throw new PublishTargetError(
209
+ "publish-credentials-missing",
210
+ `the Open VSX target publishes with trusted publishing, and this run has no OIDC ID token: not a GitHub Actions job with id-token: write, and ${OVSX_ID_TOKEN_ENV} is not set`,
211
+ `In GitHub Actions, give the job permissions: id-token: write. Elsewhere, put an ID token whose audience is ${registry} in ${OVSX_ID_TOKEN_ENV}.`,
212
+ );
213
+ }
214
+ const destination =
215
+ decl.marketplace === "vscode" ? `${registry}/items?itemName=${id.publisher}.${id.name}` : `${registry}/extension/${id.publisher}/${id.name}/${id.version}`;
216
+ const item: PublishItem = { name: `${id.publisher}.${id.name}@${id.version}`, destination, digest };
217
+ return { abs, bytes, digest, id, token, item };
218
+ };
219
+
220
+ const get = async (url: string, init: { method: string; headers: Record<string, string>; body?: string } = { method: "GET", headers: {} }) => {
221
+ const res = await fetchImpl(url, { ...init, headers: { "user-agent": "chant", ...init.headers } });
222
+ return { status: res.status, text: await res.text().catch(() => "") };
223
+ };
224
+ function fail(ctx: PublishContext, what: string, status: number, text: string): never {
225
+ throw new PublishTargetError("publish-marketplace-failed", ctx.redactor.redact(`${what} on ${label} answered ${status}${text ? `: ${text.slice(0, 300)}` : ""}`));
226
+ }
227
+
228
+ /** Open VSX: the SHA-256 of what it serves for the version, or null when it has no such version. */
229
+ const openVsxServed = async (ctx: PublishContext, id: { publisher: string; name: string; version: string }): Promise<string | null> => {
230
+ const meta = await get(`${registry}/api/${encodeURIComponent(id.publisher)}/${encodeURIComponent(id.name)}/${encodeURIComponent(id.version)}`);
231
+ if (meta.status === 404) return null;
232
+ if (meta.status !== 200) fail(ctx, `reading ${id.publisher}.${id.name}@${id.version}`, meta.status, meta.text);
233
+ const download = (JSON.parse(meta.text) as { files?: { download?: unknown } }).files?.download;
234
+ if (typeof download !== "string") fail(ctx, `reading the download of ${id.publisher}.${id.name}@${id.version}`, meta.status, "no files.download");
235
+ const res = await fetchImpl(download, { method: "GET", headers: { "user-agent": "chant" } });
236
+ if (res.status !== 200) fail(ctx, `downloading ${id.publisher}.${id.name}@${id.version}`, res.status, "");
237
+ if (!res.arrayBuffer) throw new PublishTargetError("publish-marketplace-failed", "the fetch this publish runs with can't read a response's bytes, so the download's digest can't be checked");
238
+ return bytesDigest(new Uint8Array(await res.arrayBuffer()));
239
+ };
240
+
241
+ /** The run's OIDC ID token for Open VSX: `OVSX_ID_TOKEN`, else one GitHub Actions issues with the registry as its audience. */
242
+ const idToken = async (ctx: PublishContext): Promise<string> => {
243
+ const direct = readCredential(ctx.env, [OVSX_ID_TOKEN_ENV], ctx.redactor);
244
+ if (direct) return direct.value;
245
+ const url = new URL(ctx.env.ACTIONS_ID_TOKEN_REQUEST_URL ?? "");
246
+ url.searchParams.set("audience", registry);
247
+ const res = await fetchImpl(url.toString(), { method: "GET", headers: { authorization: `Bearer ${ctx.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN ?? ""}`, accept: "application/json" } });
248
+ const text = await res.text().catch(() => "");
249
+ const value = res.status === 200 ? (JSON.parse(text) as { value?: unknown }).value : undefined;
250
+ if (typeof value !== "string" || !value) {
251
+ throw new PublishTargetError("publish-marketplace-trusted-publishing", ctx.redactor.redact(`GitHub Actions gave no OIDC ID token for ${registry}: it answered ${res.status}`), "Give the job permissions: id-token: write.");
252
+ }
253
+ ctx.redactor.add(value);
254
+ return value;
255
+ };
256
+
257
+ /** Open VSX trusted publishing: a publishing token for the extension, exchanged for the run's ID token. It lasts minutes. */
258
+ const trustedToken = async (ctx: PublishContext, id: { publisher: string; name: string }): Promise<string> => {
259
+ const token = await idToken(ctx);
260
+ const res = await get(`${registry}/api/-/trusted-publishing/token`, {
261
+ method: "POST",
262
+ headers: { "content-type": "application/json" },
263
+ body: JSON.stringify({ namespace: id.publisher, extension: id.name, token }),
264
+ });
265
+ let body: { value?: unknown; error?: unknown } = {};
266
+ try {
267
+ body = JSON.parse(res.text) as typeof body;
268
+ } catch {
269
+ // An answer that is not JSON is reported by its status.
270
+ }
271
+ if (res.status < 200 || res.status > 299 || typeof body.value !== "string" || !body.value) {
272
+ const why = typeof body.error === "string" ? body.error : `it answered ${res.status}${res.text ? `: ${res.text.slice(0, 300)}` : ""}`;
273
+ throw new PublishTargetError(
274
+ "publish-marketplace-trusted-publishing",
275
+ ctx.redactor.redact(`Open VSX at ${registry} gave no trusted-publishing token for ${id.publisher}.${id.name}: ${why}`),
276
+ `Register this workflow as a trusted publisher of ${id.publisher}.${id.name} at ${registry}/user-settings/trusted-publishers.`,
277
+ );
278
+ }
279
+ ctx.redactor.add(body.value);
280
+ return body.value;
281
+ };
282
+
283
+ /** Runs vsce with the target's credential: `VSCE_PAT` for a token, `--azure-credential` and no `VSCE_PAT` for an Entra identity. */
284
+ const vsce = async (ctx: PublishContext, args: string[], token: Credential | null) => {
285
+ const env = { ...ctx.env };
286
+ if (token) env.VSCE_PAT = token.value;
287
+ else delete env.VSCE_PAT;
288
+ return run(deps.vsce ?? "vsce", token ? args : [...args, "--azure-credential"], ctx, env).catch((err: unknown) => {
289
+ throw new PublishTargetError("publish-marketplace-vsce-missing", `vsce could not be run: ${err instanceof Error ? err.message : String(err)}`, "Install it on the job's PATH: npm install -g @vscode/vsce");
290
+ });
291
+ };
292
+
293
+ /** The reveal of a target the marketplace refused, under `onRefusal: "warn"`. */
294
+ const refusedResult = (ctx: PublishContext, items: PublishItem[], err: PublishTargetError): PublishedTarget => {
295
+ const warning = ctx.redactor.redact(`${label} refused ${items[0]?.name ?? decl.vsix}: ${err.message}. onRefusal is warn, so the publish goes on without it, and the same publish run again tries it again`);
296
+ return { target: target.name, destination: target.destination, items: items.map((i) => ({ ...i, refused: true })), warning };
297
+ };
298
+
299
+ /** VS Code Marketplace: whether the gallery lists the version. */
300
+ const galleryHas = async (ctx: PublishContext, id: { publisher: string; name: string; version: string }): Promise<boolean> => {
301
+ const res = await get(`${registry}/_apis/public/gallery/extensionquery`, {
302
+ method: "POST",
303
+ headers: { "content-type": "application/json", accept: "application/json;api-version=3.0-preview.1" },
304
+ body: JSON.stringify({ filters: [{ criteria: [{ filterType: 7, value: `${id.publisher}.${id.name}` }], pageNumber: 1, pageSize: 1 }], flags: 1 }),
305
+ });
306
+ if (res.status !== 200) fail(ctx, `asking for ${id.publisher}.${id.name}`, res.status, res.text);
307
+ const body = JSON.parse(res.text) as { results?: Array<{ extensions?: Array<{ versions?: Array<{ version?: string }> }> }> };
308
+ return (body.results?.[0]?.extensions?.[0]?.versions ?? []).some((v) => v.version === id.version);
309
+ };
310
+
311
+ const target: PublishTarget = {
312
+ kind: "marketplace",
313
+ name: `${label} ${decl.vsix}`,
314
+ destination: label,
315
+ credentialEnv: tokenNames,
316
+ key: publishTargetKey(decl),
317
+ async plan(ctx) {
318
+ return [setup(ctx).item];
319
+ },
320
+ async stage(ctx) {
321
+ const { id, digest, token, item } = setup(ctx);
322
+ if (token) ctx.log(`using the token from ${token.from}`);
323
+ const done = (present: boolean): StagedTarget => ({ target: target.name, destination: target.destination, items: [{ ...item, ...(present ? { present: true } : {}) }], state: present ? { present: "true" } : {} });
324
+ if (decl.marketplace === "openvsx") {
325
+ if (auth === "trusted-publishing") {
326
+ await trustedToken(ctx, id);
327
+ ctx.log(`Open VSX takes this run as a trusted publisher of ${id.publisher}.${id.name}; the reveal asks for a new token, since one lasts minutes`);
328
+ }
329
+ const ns = await get(`${registry}/api/${encodeURIComponent(id.publisher)}`);
330
+ if (ns.status === 404) {
331
+ throw new PublishTargetError("publish-marketplace-no-namespace", `Open VSX at ${registry} has no namespace ${id.publisher}`, `Create it once with: npx ovsx create-namespace ${id.publisher}`);
332
+ }
333
+ if (ns.status !== 200) fail(ctx, `reading namespace ${id.publisher}`, ns.status, ns.text);
334
+ const served = await openVsxServed(ctx, id);
335
+ if (served === null) {
336
+ ctx.log(`${item.name} is not on Open VSX yet; it is uploaded at the reveal, since Open VSX has no draft`);
337
+ return done(false);
338
+ }
339
+ if (served !== digest) {
340
+ throw new PublishTargetError(
341
+ "publish-marketplace-version-exists",
342
+ `Open VSX already has ${item.name}, with digest ${served}, not ${digest}`,
343
+ "A marketplace version can't be replaced: cut a release with a new version.",
344
+ );
345
+ }
346
+ ctx.log(`${item.name} is already on Open VSX with the same bytes`);
347
+ return done(true);
348
+ }
349
+ if (auth === "azure-credential") {
350
+ ctx.log(`checking the job's Microsoft Entra identity may publish as ${id.publisher}: vsce verify-pat --azure-credential ${id.publisher}`);
351
+ const check = await vsce(ctx, ["verify-pat", id.publisher], null);
352
+ for (const l of check.output) ctx.log(`vsce: ${l}`);
353
+ if (check.code !== 0) {
354
+ throw new PublishTargetError(
355
+ "publish-marketplace-azure-credential",
356
+ `vsce could not sign in with a Microsoft Entra identity that has a role on publisher ${id.publisher}: vsce verify-pat exited ${check.code}${check.output.length ? `: ${check.output.slice(-3).join(" ")}` : ""}`,
357
+ `Sign in to Azure in the publish's job before it runs, such as with azure/login and the run's OIDC token, as an identity added to the publisher ${id.publisher}.`,
358
+ );
359
+ }
360
+ }
361
+ if (await galleryHas(ctx, id)) {
362
+ ctx.log(`${item.name} is already on the VS Code Marketplace; it reports no digest to compare`);
363
+ return done(true);
364
+ }
365
+ ctx.log(`${item.name} is not on the VS Code Marketplace yet; it is uploaded at the reveal, since the marketplace has no draft`);
366
+ return done(false);
367
+ },
368
+ async reveal(ctx, staged) {
369
+ const items = staged.items.map((i) => ({ name: i.name, destination: i.destination, ...(i.digest ? { digest: i.digest } : {}) }));
370
+ if (staged.state.present === "true") return { target: target.name, destination: target.destination, items: items.map((i) => ({ ...i, present: true })) };
371
+ const { abs, bytes, id, digest, token, item } = setup(ctx);
372
+ const refusable = async <T>(step: () => Promise<T>): Promise<T | PublishedTarget> => {
373
+ try {
374
+ return await step();
375
+ } catch (err) {
376
+ if (decl.onRefusal === "warn" && err instanceof PublishTargetError && REFUSALS.has(err.code)) return refusedResult(ctx, items, err);
377
+ throw err;
378
+ }
379
+ };
380
+ if (decl.marketplace === "openvsx") {
381
+ // Run again after an upload whose record was lost, the version is there: check it rather than send it twice.
382
+ const uploaded = await refusable(async () => {
383
+ const before = await openVsxServed(ctx, id);
384
+ if (before !== null) return before;
385
+ const publishToken = token ? token.value : await trustedToken(ctx, id);
386
+ ctx.log(`uploading ${item.name} (${bytes.byteLength} bytes) to Open VSX${token ? "" : " with a trusted-publishing token"}`);
387
+ const res = await fetchImpl(`${registry}/api/-/publish?token=${encodeURIComponent(publishToken)}`, {
388
+ method: "POST",
389
+ headers: { "user-agent": "chant", "content-type": "application/octet-stream" },
390
+ body: new Uint8Array(bytes),
391
+ });
392
+ if (res.status !== 201 && res.status !== 200) fail(ctx, `publishing ${item.name}`, res.status, await res.text().catch(() => ""));
393
+ return null;
394
+ });
395
+ if (uploaded !== null && typeof uploaded === "object") return uploaded;
396
+ const before = uploaded;
397
+ const served = before ?? (await openVsxServed(ctx, id));
398
+ if (served !== digest) {
399
+ throw new PublishTargetError("publish-marketplace-digest-mismatch", `Open VSX serves ${item.name} with digest ${served ?? "none"}, and the file published is ${digest}`);
400
+ }
401
+ return { target: target.name, destination: target.destination, items: before === null ? items : items.map((i) => ({ ...i, present: true })) };
402
+ }
403
+ const outcome = await refusable(async () => {
404
+ if (await galleryHas(ctx, id)) {
405
+ ctx.log(`${item.name} is already on the VS Code Marketplace`);
406
+ return true;
407
+ }
408
+ ctx.log(`running vsce publish --packagePath ${decl.vsix}${token ? "" : " --azure-credential"}`);
409
+ const result = await vsce(ctx, ["publish", "--packagePath", abs], token);
410
+ for (const l of result.output) ctx.log(`vsce: ${l}`);
411
+ if (result.code !== 0) {
412
+ throw new PublishTargetError("publish-marketplace-failed", `vsce publish of ${item.name} exited ${result.code}${result.output.length ? `: ${result.output.slice(-3).join(" ")}` : ""}`);
413
+ }
414
+ return false;
415
+ });
416
+ if (typeof outcome === "object") return outcome;
417
+ return { target: target.name, destination: target.destination, items: outcome ? items.map((i) => ({ ...i, present: true })) : items };
418
+ },
419
+ };
420
+ return target;
421
+ }
@@ -152,6 +152,46 @@ describe("a publish that fails resumes", () => {
152
152
  }
153
153
  });
154
154
 
155
+ test("a target whose reveal comes back refused with a warning is not recorded as revealed, so the same publish tries it again (#4698)", async () => {
156
+ const r = new TestRepo("publish-refused");
157
+ repos.push(r);
158
+ const rel = await release(r);
159
+ const reveals: string[] = [];
160
+ let refuse = true;
161
+ const fake = (kind: "forge" | "marketplace", name: string): PublishTarget => ({
162
+ kind,
163
+ name,
164
+ destination: name,
165
+ credentialEnv: [],
166
+ key: `${kind}:${name}`,
167
+ plan: async () => [],
168
+ stage: async () => ({ target: name, destination: name, items: [{ name, destination: name }], state: {} }),
169
+ reveal: async () => {
170
+ reveals.push(name);
171
+ return kind === "marketplace" && refuse
172
+ ? { target: name, destination: name, items: [{ name, destination: name, refused: true }], warning: "Open VSX refused it: it answered 406" }
173
+ : { target: name, destination: name, items: [{ name, destination: name }] };
174
+ },
175
+ });
176
+ const targets = [fake("forge", "assets"), fake("marketplace", "openvsx")];
177
+ const lines: string[] = [];
178
+ const redactor = createRedactor({});
179
+ const ctx: PublishContext = { release: rel, label: "v2", releaseTag: "release/v2", provenance: NO_OIDC, cwd: r.dir, tag: null, env: {}, redactor, log: () => undefined };
180
+ const run = () => runPublish({ cwd: r.dir, release: rel, label: "v2", targets, ctx, say: (l) => lines.push(l) });
181
+ const records = () => parsePublishRecords(r.git(["show", `chant/lifecycle:_releases/${PUBLISHES_FILE}`])).records;
182
+
183
+ const first = await run();
184
+ expect(first.published.map((p) => p.warning ?? null)).toEqual([null, "Open VSX refused it: it answered 406"]);
185
+ expect(lines).toContain(" warning: openvsx: Open VSX refused it: it answered 406");
186
+ expect(records().filter((x) => x.step === "revealed").map((x) => x.target)).toEqual(["forge:assets"]);
187
+
188
+ refuse = false;
189
+ reveals.length = 0;
190
+ await run();
191
+ expect(reveals).toEqual(["openvsx"]);
192
+ expect(records().filter((x) => x.step === "revealed").map((x) => x.target)).toEqual(["forge:assets", "marketplace:openvsx"]);
193
+ });
194
+
155
195
  test("a target's key names its declaration, so a resume finds it, and holds no credential", async () => {
156
196
  const [a, b, c] = await createPublishTargets(
157
197
  [
@@ -65,9 +65,9 @@ describe("publish target context (#4602)", () => {
65
65
  expectTypeOf<ToyModuleContext>().toMatchTypeOf<PublishContextBase>();
66
66
  });
67
67
 
68
- test("the release targets keep the default context and their three kinds", () => {
68
+ test("the release targets keep the default context and their kinds", () => {
69
69
  expectTypeOf<PublishTarget["kind"]>().toEqualTypeOf<ReleasePublishKind>();
70
- expectTypeOf<ReleasePublishKind>().toEqualTypeOf<"npm" | "oci" | "forge">();
70
+ expectTypeOf<ReleasePublishKind>().toEqualTypeOf<"npm" | "oci" | "forge" | "homebrew" | "marketplace" | "tauri-updater">();
71
71
  expectTypeOf<Parameters<PublishTarget["plan"]>[0]>().toEqualTypeOf<PublishContext>();
72
72
  expectTypeOf<PublishContext>().toMatchTypeOf<PublishContextBase>();
73
73
  expectTypeOf<Awaited<ReturnType<typeof createPublishTargets>>>().toEqualTypeOf<PublishTarget[]>();
@@ -395,6 +395,29 @@ describe("forge release assets", () => {
395
395
  expect((await refused(t2!.stage(ctx))).code).toBe("publish-forge-asset-exists");
396
396
  });
397
397
 
398
+ test("GitHub: latest is sent as make_latest when the reveal publishes the draft, and is refused on a forge that has no such setting (#4676)", async () => {
399
+ const dir = assetDir();
400
+ const api = "https://api.github.test";
401
+ const ctx = context(dir, { env: { GITHUB_TOKEN: "ghs_tokentoken" } });
402
+ for (const [latest, sent] of [[false, "false"], [true, "true"], ["legacy", "legacy"]] as const) {
403
+ const forge = startFakeForge("github", api, "acme/api");
404
+ const [target] = await createPublishTargets([decl({ type: "forge", forge: "github", repo: "acme/api", api, assets: ASSETS, latest })], { fetch: forge.fetch });
405
+ const staged = await target!.stage(ctx);
406
+ // Staging creates the draft without it: a draft is never latest.
407
+ expect(forge.calls.filter((c) => c.method === "POST" && c.url === `${api}/repos/acme/api/releases`).map((c) => JSON.parse(c.body as string))).toEqual([
408
+ { tag_name: "release/v1.4.0", target_commitish: ctx.release.commit, name: "v1.4.0", draft: true },
409
+ ]);
410
+ await target!.reveal(ctx, staged);
411
+ expect(forge.calls.at(-1)).toMatchObject({ method: "PATCH", url: `${api}/repos/acme/api/releases/100`, body: JSON.stringify({ draft: false, make_latest: sent }) });
412
+ }
413
+ expect(() => decl({ type: "forge", forge: "github", repo: "acme/api", assets: ASSETS, latest: "true" })).toThrow();
414
+
415
+ const gitlab = startFakeForge("gitlab", "https://gitlab.test/api/v4", "acme/api");
416
+ const [t] = await createPublishTargets([decl({ type: "forge", forge: "gitlab", repo: "acme/api", assets: ASSETS, latest: false })], { fetch: gitlab.fetch });
417
+ expect((await refused(t!.plan(context(dir, { env: { GITLAB_TOKEN: "glpat-token" } })))).code).toBe("publish-forge-latest-unsupported");
418
+ expect(gitlab.calls).toEqual([]);
419
+ });
420
+
398
421
  test("GitLab: assets go to the generic package registry with a CI job token, and the release is made with its links only at the reveal", async () => {
399
422
  const dir = assetDir();
400
423
  const api = "https://gitlab.test/api/v4";
@@ -9,6 +9,12 @@
9
9
  * as GHCR or Docker Hub over the registry HTTP API, by digest, then tagged.
10
10
  * - `forge` (./publish-forge.ts): files attached to the GitHub, GitLab or
11
11
  * Forgejo release named by the release's tag.
12
+ * - `homebrew` (./publish-homebrew.ts): a formula in a tap repository on
13
+ * GitHub, rendered from a template with each asset's URL and SHA-256.
14
+ * - `marketplace` (./publish-marketplace.ts): a `.vsix` on the VS Code
15
+ * Marketplace (through `vsce`) or Open VSX (through its REST API).
16
+ * - `tauri-updater` (./publish-tauri.ts): a Tauri updater manifest and the
17
+ * app's bundles on a rolling GitHub release, replaced on each publish.
12
18
  *
13
19
  * A file a target reads that the release records as an artifact at the same
14
20
  * path is checked against the release's digest, and a file that differs is
@@ -38,6 +44,15 @@ export async function createPublishTargets(decls: readonly PublishDeclaration[],
38
44
  case "forge":
39
45
  out.push((await import("./publish-forge")).forgeTarget(d, deps));
40
46
  break;
47
+ case "homebrew":
48
+ out.push((await import("./publish-homebrew")).homebrewTarget(d, deps));
49
+ break;
50
+ case "marketplace":
51
+ out.push((await import("./publish-marketplace")).marketplaceTarget(d, deps));
52
+ break;
53
+ case "tauri-updater":
54
+ out.push((await import("./publish-tauri")).tauriUpdaterTarget(d, deps));
55
+ break;
41
56
  }
42
57
  }
43
58
  return out;