@intentius/chant 0.124.61 → 0.124.63

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 (234) hide show
  1. package/dist/cli/handlers/approve.d.ts +18 -0
  2. package/dist/cli/handlers/approve.d.ts.map +1 -1
  3. package/dist/cli/handlers/approve.js +142 -16
  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/release.d.ts +6 -4
  8. package/dist/cli/handlers/release.d.ts.map +1 -1
  9. package/dist/cli/handlers/release.js +13 -7
  10. package/dist/cli/main.d.ts.map +1 -1
  11. package/dist/cli/main.js +34 -5
  12. package/dist/cli/mcp/workspace-tools.d.ts.map +1 -1
  13. package/dist/cli/mcp/workspace-tools.js +2 -1
  14. package/dist/cli/parse-args.d.ts.map +1 -1
  15. package/dist/cli/parse-args.js +31 -0
  16. package/dist/cli/registry.d.ts +13 -1
  17. package/dist/cli/registry.d.ts.map +1 -1
  18. package/dist/config.d.ts +32 -0
  19. package/dist/config.d.ts.map +1 -1
  20. package/dist/gate-decision.d.ts +1 -1
  21. package/dist/gate-decision.d.ts.map +1 -1
  22. package/dist/gate-decision.js +4 -2
  23. package/dist/gate-statement.schema.json +44 -0
  24. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +20 -0
  25. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
  26. package/dist/lifecycle/__fixtures__/publish-fakes.js +119 -3
  27. package/dist/lifecycle/gate-ledger.d.ts +17 -3
  28. package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
  29. package/dist/lifecycle/gate-seal.d.ts +39 -3
  30. package/dist/lifecycle/gate-seal.d.ts.map +1 -1
  31. package/dist/lifecycle/gate-seal.js +50 -10
  32. package/dist/lifecycle/gate-statement.d.ts +70 -0
  33. package/dist/lifecycle/gate-statement.d.ts.map +1 -0
  34. package/dist/lifecycle/gate-statement.js +74 -0
  35. package/dist/lifecycle/gate-webauthn.d.ts +79 -0
  36. package/dist/lifecycle/gate-webauthn.d.ts.map +1 -0
  37. package/dist/lifecycle/gate-webauthn.js +105 -0
  38. package/dist/lifecycle/git.d.ts +1 -1
  39. package/dist/lifecycle/git.d.ts.map +1 -1
  40. package/dist/lifecycle/git.js +24 -19
  41. package/dist/lifecycle/ledger-remote.d.ts +37 -0
  42. package/dist/lifecycle/ledger-remote.d.ts.map +1 -0
  43. package/dist/lifecycle/ledger-remote.js +42 -0
  44. package/dist/lifecycle/plan-stale.d.ts +76 -0
  45. package/dist/lifecycle/plan-stale.d.ts.map +1 -0
  46. package/dist/lifecycle/plan-stale.js +121 -0
  47. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  48. package/dist/lifecycle/publish-credentials.d.ts.map +1 -1
  49. package/dist/lifecycle/publish-credentials.js +2 -0
  50. package/dist/lifecycle/publish-declaration.d.ts +87 -0
  51. package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
  52. package/dist/lifecycle/publish-declaration.js +87 -1
  53. package/dist/lifecycle/publish-forge.d.ts +5 -1
  54. package/dist/lifecycle/publish-forge.d.ts.map +1 -1
  55. package/dist/lifecycle/publish-forge.js +14 -4
  56. package/dist/lifecycle/publish-github.d.ts +69 -0
  57. package/dist/lifecycle/publish-github.d.ts.map +1 -0
  58. package/dist/lifecycle/publish-github.js +153 -0
  59. package/dist/lifecycle/publish-homebrew.d.ts +66 -0
  60. package/dist/lifecycle/publish-homebrew.d.ts.map +1 -0
  61. package/dist/lifecycle/publish-homebrew.js +173 -0
  62. package/dist/lifecycle/publish-marketplace.d.ts +51 -0
  63. package/dist/lifecycle/publish-marketplace.d.ts.map +1 -0
  64. package/dist/lifecycle/publish-marketplace.js +254 -0
  65. package/dist/lifecycle/publish-targets.d.ts +6 -0
  66. package/dist/lifecycle/publish-targets.d.ts.map +1 -1
  67. package/dist/lifecycle/publish-targets.js +15 -0
  68. package/dist/lifecycle/publish-tauri.d.ts +61 -0
  69. package/dist/lifecycle/publish-tauri.d.ts.map +1 -0
  70. package/dist/lifecycle/publish-tauri.js +182 -0
  71. package/dist/lifecycle/release-publish.d.ts +5 -2
  72. package/dist/lifecycle/release-publish.d.ts.map +1 -1
  73. package/dist/lifecycle/snapshot-store.d.ts.map +1 -1
  74. package/dist/lifecycle/snapshot-store.js +17 -9
  75. package/dist/lifecycle/test-passkey.d.ts +25 -0
  76. package/dist/lifecycle/test-passkey.d.ts.map +1 -0
  77. package/dist/lifecycle/test-passkey.js +39 -0
  78. package/dist/notify.d.ts +23 -3
  79. package/dist/notify.d.ts.map +1 -1
  80. package/dist/notify.js +8 -2
  81. package/dist/notify.schema.json +12 -3
  82. package/dist/op/activities/activity-contracts.d.ts +4 -4
  83. package/dist/pr-forge.d.ts +20 -0
  84. package/dist/pr-forge.d.ts.map +1 -1
  85. package/dist/pr-forge.js +61 -2
  86. package/dist/release-floors.d.ts +1 -1
  87. package/dist/release-floors.js +1 -1
  88. package/dist/wave-runtime.mjs +331 -330
  89. package/dist/workspace/ci-builds.d.ts +21 -0
  90. package/dist/workspace/ci-builds.d.ts.map +1 -1
  91. package/dist/workspace/ci-builds.js +14 -0
  92. package/dist/workspace/ci-green-workflow.d.ts +2 -0
  93. package/dist/workspace/ci-green-workflow.d.ts.map +1 -1
  94. package/dist/workspace/ci-green-workflow.js +9 -0
  95. package/dist/workspace/ci-green.d.ts +45 -2
  96. package/dist/workspace/ci-green.d.ts.map +1 -1
  97. package/dist/workspace/ci-green.js +127 -9
  98. package/dist/workspace/ci-quarantine-report.d.ts +80 -0
  99. package/dist/workspace/ci-quarantine-report.d.ts.map +1 -0
  100. package/dist/workspace/ci-quarantine-report.js +205 -0
  101. package/dist/workspace/ci-quarantine.d.ts +73 -0
  102. package/dist/workspace/ci-quarantine.d.ts.map +1 -0
  103. package/dist/workspace/ci-quarantine.js +171 -0
  104. package/dist/workspace/ci-serve.d.ts.map +1 -1
  105. package/dist/workspace/ci-serve.js +7 -4
  106. package/dist/workspace/class-data.d.ts +3 -1
  107. package/dist/workspace/class-data.d.ts.map +1 -1
  108. package/dist/workspace/class-data.js +4 -1
  109. package/dist/workspace/declaration.d.ts +45 -2
  110. package/dist/workspace/declaration.d.ts.map +1 -1
  111. package/dist/workspace/declaration.js +45 -2
  112. package/dist/workspace/declaration.schema.json +51 -3
  113. package/dist/workspace/forge-work.d.ts +76 -0
  114. package/dist/workspace/forge-work.d.ts.map +1 -0
  115. package/dist/workspace/forge-work.js +160 -0
  116. package/dist/workspace/identity-gate-rule.d.ts +3 -2
  117. package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
  118. package/dist/workspace/identity-gate-rule.js +5 -7
  119. package/dist/workspace/identity.d.ts +3 -2
  120. package/dist/workspace/identity.d.ts.map +1 -1
  121. package/dist/workspace/identity.js +6 -3
  122. package/dist/workspace/intent-cli.d.ts +3 -2
  123. package/dist/workspace/intent-cli.d.ts.map +1 -1
  124. package/dist/workspace/intent-cli.js +26 -5
  125. package/dist/workspace/intent-record.d.ts +3 -0
  126. package/dist/workspace/intent-record.d.ts.map +1 -1
  127. package/dist/workspace/intent-record.schema.json +32 -0
  128. package/dist/workspace/intent.d.ts +9 -0
  129. package/dist/workspace/intent.d.ts.map +1 -1
  130. package/dist/workspace/intent.js +3 -0
  131. package/dist/workspace/intent.schema.json +32 -0
  132. package/dist/workspace/kind-readers.d.ts.map +1 -1
  133. package/dist/workspace/kind-readers.js +2 -1
  134. package/dist/workspace/kinds.d.ts +6 -1
  135. package/dist/workspace/kinds.d.ts.map +1 -1
  136. package/dist/workspace/kinds.js +8 -3
  137. package/dist/workspace/plan-stale.schema.json +286 -0
  138. package/dist/workspace/release-candidates.d.ts +33 -6
  139. package/dist/workspace/release-candidates.d.ts.map +1 -1
  140. package/dist/workspace/release-candidates.js +49 -20
  141. package/dist/workspace/release-candidates.schema.json +48 -2
  142. package/dist/workspace/trust/policy.d.ts +10 -0
  143. package/dist/workspace/trust/policy.d.ts.map +1 -1
  144. package/dist/workspace/trust/policy.js +19 -1
  145. package/dist/workspace/trust/run-commits.d.ts.map +1 -1
  146. package/dist/workspace/trust/run-commits.js +2 -1
  147. package/dist/workspace/trust/seal.d.ts.map +1 -1
  148. package/dist/workspace/trust/seal.js +34 -3
  149. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  150. package/dist/workspace/trust/trust-files.js +6 -1
  151. package/package.json +2 -1
  152. package/src/cli/handlers/approve-external-signature.test.ts +226 -0
  153. package/src/cli/handlers/approve.ts +174 -16
  154. package/src/cli/handlers/plan.ts +74 -0
  155. package/src/cli/handlers/release.ts +12 -7
  156. package/src/cli/main.ts +34 -5
  157. package/src/cli/mcp/workspace-tools.ts +2 -1
  158. package/src/cli/parse-args.ts +24 -0
  159. package/src/cli/registry.ts +13 -1
  160. package/src/gate-decision-bundle.test.ts +4 -2
  161. package/src/gate-decision.ts +11 -2
  162. package/src/gate-statement.schema.json +44 -0
  163. package/src/lifecycle/__fixtures__/publish-fakes.ts +125 -5
  164. package/src/lifecycle/gate-ledger.ts +17 -3
  165. package/src/lifecycle/gate-seal.ts +62 -9
  166. package/src/lifecycle/gate-statement.ts +107 -0
  167. package/src/lifecycle/gate-webauthn.test.ts +77 -0
  168. package/src/lifecycle/gate-webauthn.ts +133 -0
  169. package/src/lifecycle/git.ts +23 -19
  170. package/src/lifecycle/ledger-remote.test.ts +183 -0
  171. package/src/lifecycle/ledger-remote.ts +46 -0
  172. package/src/lifecycle/plan-stale.test.ts +150 -0
  173. package/src/lifecycle/plan-stale.ts +173 -0
  174. package/src/lifecycle/publish-credentials.ts +2 -0
  175. package/src/lifecycle/publish-declaration.ts +93 -1
  176. package/src/lifecycle/publish-forge.ts +15 -4
  177. package/src/lifecycle/publish-github.ts +174 -0
  178. package/src/lifecycle/publish-homebrew.test.ts +179 -0
  179. package/src/lifecycle/publish-homebrew.ts +187 -0
  180. package/src/lifecycle/publish-marketplace.test.ts +254 -0
  181. package/src/lifecycle/publish-marketplace.ts +259 -0
  182. package/src/lifecycle/publish-target-context.test.ts +2 -2
  183. package/src/lifecycle/publish-targets.test.ts +23 -0
  184. package/src/lifecycle/publish-targets.ts +15 -0
  185. package/src/lifecycle/publish-tauri.test.ts +163 -0
  186. package/src/lifecycle/publish-tauri.ts +199 -0
  187. package/src/lifecycle/release-publish.ts +5 -3
  188. package/src/lifecycle/snapshot-store.ts +16 -9
  189. package/src/lifecycle/test-passkey.ts +55 -0
  190. package/src/notify-bundle.test.ts +3 -1
  191. package/src/notify.schema.json +12 -3
  192. package/src/notify.ts +20 -3
  193. package/src/override-gate-bundle.test.ts +2 -0
  194. package/src/pr-forge-bundle.test.ts +2 -2
  195. package/src/pr-forge.test.ts +38 -0
  196. package/src/pr-forge.ts +68 -5
  197. package/src/release-floors.ts +1 -1
  198. package/src/stage-hooks-bundle.test.ts +2 -0
  199. package/src/wave-runtime-bundle.test.ts +3 -2
  200. package/src/workspace/ci-builds.ts +27 -0
  201. package/src/workspace/ci-green-stale.test.ts +193 -0
  202. package/src/workspace/ci-green-workflow.test.ts +9 -0
  203. package/src/workspace/ci-green-workflow.ts +9 -0
  204. package/src/workspace/ci-green.ts +141 -10
  205. package/src/workspace/ci-quarantine-report.test.ts +146 -0
  206. package/src/workspace/ci-quarantine-report.ts +235 -0
  207. package/src/workspace/ci-quarantine.test.ts +161 -0
  208. package/src/workspace/ci-quarantine.ts +189 -0
  209. package/src/workspace/ci-serve.ts +7 -4
  210. package/src/workspace/class-data.ts +5 -1
  211. package/src/workspace/declaration.schema.json +51 -3
  212. package/src/workspace/declaration.test.ts +1 -0
  213. package/src/workspace/declaration.ts +88 -5
  214. package/src/workspace/forge-work.test.ts +143 -0
  215. package/src/workspace/forge-work.ts +195 -0
  216. package/src/workspace/identity-gate-rule.ts +6 -8
  217. package/src/workspace/identity.ts +6 -3
  218. package/src/workspace/intent-cli.ts +24 -5
  219. package/src/workspace/intent-record.schema.json +32 -0
  220. package/src/workspace/intent-record.ts +3 -0
  221. package/src/workspace/intent.schema.json +32 -0
  222. package/src/workspace/intent.ts +10 -0
  223. package/src/workspace/kind-readers.ts +2 -1
  224. package/src/workspace/kinds.test.ts +13 -0
  225. package/src/workspace/kinds.ts +12 -3
  226. package/src/workspace/plan-stale.schema.json +286 -0
  227. package/src/workspace/release-candidates.schema.json +48 -2
  228. package/src/workspace/release-candidates.test.ts +77 -4
  229. package/src/workspace/release-candidates.ts +62 -20
  230. package/src/workspace/trust/policy.ts +24 -1
  231. package/src/workspace/trust/run-commits.ts +2 -1
  232. package/src/workspace/trust/seal.ts +35 -3
  233. package/src/workspace/trust/trust-files.test.ts +5 -0
  234. package/src/workspace/trust/trust-files.ts +15 -1
@@ -16,7 +16,9 @@
16
16
  * GitHub uploads each asset to the draft's `upload_url`, Forgejo with a
17
17
  * multipart `POST /repos/{repo}/releases/{id}/assets`. The reveal publishes
18
18
  * the draft, `PATCH /repos/{repo}/releases/{id}` with `draft: false`, and
19
- * the forge creates the tag then if it was not pushed.
19
+ * the forge creates the tag then if it was not pushed. On GitHub, a
20
+ * declared `latest` goes in the same request as `make_latest` (#4676), so
21
+ * the release becomes the repository's latest, or doesn't, as it appears.
20
22
  * - GitLab has no draft release, so its stage puts each asset in the
21
23
  * project's generic package registry (package `release`, version the
22
24
  * label) and makes no release. The reveal creates the release at the
@@ -43,6 +45,8 @@
43
45
  */
44
46
  import type { ForgePublishDeclaration } from "./publish-declaration.js";
45
47
  import { type PublishDeps, type PublishTarget } from "./release-publish.js";
48
+ /** The first chant that reads `latest` on a forge target and sends it as GitHub's `make_latest` (#4676). */
49
+ export declare const PUBLISH_FORGE_LATEST_FLOOR = "0.124.63";
46
50
  /** The variables a forge's token is read from, in order. */
47
51
  export declare function forgeTokenEnv(decl: Pick<ForgePublishDeclaration, "forge" | "tokenEnv">): string[];
48
52
  /** The API root a forge is reached at. */
@@ -1 +1 @@
1
- {"version":3,"file":"publish-forge.d.ts","sourceRoot":"","sources":["../../src/lifecycle/publish-forge.ts"],"names":[],"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E,OAAO,GAAG,KAAK,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,GAAG,IAAI,CAGpH;AAuID,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,uBAAuB,EAAE,IAAI,EAAE,WAAW,GAAG,aAAa,CA6H3F"}
@@ -16,7 +16,9 @@
16
16
  * GitHub uploads each asset to the draft's `upload_url`, Forgejo with a
17
17
  * multipart `POST /repos/{repo}/releases/{id}/assets`. The reveal publishes
18
18
  * the draft, `PATCH /repos/{repo}/releases/{id}` with `draft: false`, and
19
- * the forge creates the tag then if it was not pushed.
19
+ * the forge creates the tag then if it was not pushed. On GitHub, a
20
+ * declared `latest` goes in the same request as `make_latest` (#4676), so
21
+ * the release becomes the repository's latest, or doesn't, as it appears.
20
22
  * - GitLab has no draft release, so its stage puts each asset in the
21
23
  * project's generic package registry (package `release`, version the
22
24
  * label) and makes no release. The reveal creates the release at the
@@ -47,6 +49,9 @@ import { memberSbom, releaseProvenance } from "./publish-attachments.js";
47
49
  import { readCredential } from "./publish-credentials.js";
48
50
  import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets.js";
49
51
  import { PublishTargetError } from "./release-publish.js";
52
+ import { NEXT_RELEASE } from "../release-floors.js";
53
+ /** The first chant that reads `latest` on a forge target and sends it as GitHub's `make_latest` (#4676). */
54
+ export const PUBLISH_FORGE_LATEST_FLOOR = NEXT_RELEASE;
50
55
  /** The variables a forge's token is read from, in order. */
51
56
  export function forgeTokenEnv(decl) {
52
57
  if (decl.tokenEnv)
@@ -137,9 +142,11 @@ class ForgeClient {
137
142
  this.fail(`creating a draft release ${tag}`, create.status, create.text);
138
143
  return this.toRelease(create.json, tag);
139
144
  }
140
- /** GitHub and Forgejo: publish the draft `id`. */
145
+ /** GitHub and Forgejo: publish the draft `id`, with GitHub's `make_latest` when `latest` is declared. */
141
146
  async publishDraft(id, tag) {
142
- const res = await this.call("PATCH", `${this.repoPath}/releases/${id}`, JSON.stringify({ draft: false }));
147
+ const latest = this.decl.latest;
148
+ const body = latest === undefined ? { draft: false } : { draft: false, make_latest: String(latest) };
149
+ const res = await this.call("PATCH", `${this.repoPath}/releases/${id}`, JSON.stringify(body));
143
150
  if (res.status !== 200)
144
151
  this.fail(`publishing the draft release ${tag}`, res.status, res.text);
145
152
  }
@@ -187,6 +194,9 @@ export function forgeTarget(decl, deps) {
187
194
  if (!tag) {
188
195
  throw new PublishTargetError("publish-forge-no-tag", `a ${decl.forge} release is named by a tag, and release ${ctx.release.releaseDigest} has no label`, "Cut the release with a label, or set tag in the declaration.");
189
196
  }
197
+ if (decl.latest !== undefined && decl.forge !== "github") {
198
+ throw new PublishTargetError("publish-forge-latest-unsupported", `latest is GitHub's make_latest, and ${decl.forge} has no setting for which release is latest`, "Remove latest from the declaration.");
199
+ }
190
200
  const api = forgeApi(decl, ctx.env);
191
201
  if (!api)
192
202
  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.");
@@ -289,7 +299,7 @@ export function forgeTarget(decl, deps) {
289
299
  const id = staged.state.releaseId;
290
300
  if (!id)
291
301
  throw new PublishTargetError("publish-forge-failed", `the staged ${decl.forge} release for ${tag} has no draft id to publish`);
292
- ctx.log(`publishing the draft ${decl.forge} release ${tag}`);
302
+ ctx.log(`publishing the draft ${decl.forge} release ${tag}${decl.latest === undefined ? "" : ` with make_latest ${String(decl.latest)}`}`);
293
303
  await client.publishDraft(id, tag);
294
304
  }
295
305
  return { target: this.name, destination: this.destination, items };
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The GitHub REST calls the targets that write to a repository other than the
3
+ * release's use (#4676): the Homebrew tap's formula, and the Tauri updater's
4
+ * rolling release. Requests go through the injectable `fetch`, with the token
5
+ * as a bearer, and every failure is redacted before it is thrown.
6
+ */
7
+ import type { Credential } from "./publish-credentials.js";
8
+ import { type PublishContextBase, type PublishFetch } from "./release-publish.js";
9
+ /** The API root of GitHub: `api`, else `$GITHUB_API_URL`, else `https://api.github.com`. */
10
+ export declare function githubApi(api: string | undefined, env: NodeJS.ProcessEnv): string;
11
+ export interface GitHubAnswer {
12
+ status: number;
13
+ json: unknown;
14
+ text: string;
15
+ }
16
+ /** One repository on GitHub, reached with one token. */
17
+ export declare class GitHubRepo {
18
+ readonly api: string;
19
+ readonly repo: string;
20
+ private readonly token;
21
+ private readonly fetchImpl;
22
+ private readonly ctx;
23
+ /** The code a failed request throws. */
24
+ private readonly code;
25
+ constructor(api: string, repo: string, token: Credential, fetchImpl: PublishFetch, ctx: PublishContextBase,
26
+ /** The code a failed request throws. */
27
+ code: string);
28
+ get root(): string;
29
+ call(method: string, url: string, body?: Uint8Array | string, extra?: Record<string, string>): Promise<GitHubAnswer>;
30
+ fail(what: string, res: GitHubAnswer): never;
31
+ /** The repository's default branch. */
32
+ defaultBranch(): Promise<string>;
33
+ /** The commit `refs/heads/<branch>` points at, or null when there is no such branch. */
34
+ branchHead(branch: string): Promise<string | null>;
35
+ /** A file's bytes and blob sha at `ref`, or null when it has none. */
36
+ file(path: string, ref: string): Promise<{
37
+ bytes: Buffer;
38
+ sha: string;
39
+ } | null>;
40
+ /** Commit `bytes` as `path` on `branch`, replacing the blob `sha` when the file is there. Returns the commit. */
41
+ putFile(path: string, branch: string, bytes: Uint8Array, message: string, sha: string | null): Promise<string>;
42
+ /** Make `refs/heads/<branch>` at `sha`. */
43
+ createBranch(branch: string, sha: string): Promise<void>;
44
+ /** Move `refs/<ref>` to `sha`. Without `force`, a move that is not a fast-forward answers false. */
45
+ moveRef(ref: string, sha: string, force: boolean): Promise<boolean>;
46
+ /** The published release for `tag`, or null. A draft is not found here. */
47
+ publishedRelease(tag: string): Promise<GitHubRelease | null>;
48
+ /** The draft release for `tag` named `name`, or null. */
49
+ draftRelease(tag: string, name: string): Promise<GitHubRelease | null>;
50
+ /** A new draft release for `tag` named `name`, at `commit`. */
51
+ createDraft(tag: string, commit: string, name: string): Promise<GitHubRelease>;
52
+ /** Upload `bytes` as the asset `name` of `release`. */
53
+ uploadAsset(release: GitHubRelease, name: string, bytes: Uint8Array): Promise<void>;
54
+ /** Publish the draft `id`, with `make_latest` when it is given. */
55
+ publishDraft(id: string, makeLatest: string | undefined): Promise<GitHubAnswer>;
56
+ /** Delete the release `id`. Its tag stays. */
57
+ deleteRelease(id: string): Promise<void>;
58
+ /** Delete `refs/<ref>`. One that is not there is already gone. */
59
+ deleteRef(ref: string): Promise<void>;
60
+ }
61
+ /** A GitHub release as the targets read it. */
62
+ export interface GitHubRelease {
63
+ id: string;
64
+ draft: boolean;
65
+ /** Asset names, with the digest GitHub reports. */
66
+ assets: Map<string, string | null>;
67
+ uploadUrl?: string;
68
+ }
69
+ //# sourceMappingURL=publish-github.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-github.d.ts","sourceRoot":"","sources":["../../src/lifecycle/publish-github.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAsB,KAAK,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEnG,4FAA4F;AAC5F,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAEjF;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wDAAwD;AACxD,qBAAa,UAAU;IAEnB,QAAQ,CAAC,GAAG,EAAE,MAAM;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CA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(#4676): the Homebrew tap's formula, and the Tauri updater's
4
+ * rolling release. Requests go through the injectable `fetch`, with the token
5
+ * as a bearer, and every failure is redacted before it is thrown.
6
+ */
7
+ import { PublishTargetError } from "./release-publish.js";
8
+ /** The API root of GitHub: `api`, else `$GITHUB_API_URL`, else `https://api.github.com`. */
9
+ export function githubApi(api, env) {
10
+ return (api ?? env.GITHUB_API_URL ?? "https://api.github.com").replace(/\/+$/, "");
11
+ }
12
+ /** One repository on GitHub, reached with one token. */
13
+ export class GitHubRepo {
14
+ constructor(api, repo, token, fetchImpl, ctx,
15
+ /** The code a failed request throws. */
16
+ code) {
17
+ this.api = api;
18
+ this.repo = repo;
19
+ this.token = token;
20
+ this.fetchImpl = fetchImpl;
21
+ this.ctx = ctx;
22
+ this.code = code;
23
+ }
24
+ get root() {
25
+ return `${this.api}/repos/${this.repo}`;
26
+ }
27
+ async call(method, url, body, extra = {}) {
28
+ const headers = {
29
+ authorization: `Bearer ${this.token.value}`,
30
+ accept: "application/vnd.github+json",
31
+ "user-agent": "chant",
32
+ ...(typeof body === "string" ? { "content-type": "application/json" } : {}),
33
+ ...extra,
34
+ };
35
+ const res = await this.fetchImpl(url.startsWith("http") ? url : `${this.root}${url}`, { method, headers, ...(body !== undefined ? { body } : {}) });
36
+ const text = await res.text();
37
+ let json = null;
38
+ try {
39
+ json = text ? JSON.parse(text) : null;
40
+ }
41
+ catch {
42
+ json = null;
43
+ }
44
+ return { status: res.status, json, text };
45
+ }
46
+ fail(what, res) {
47
+ throw new PublishTargetError(this.code, this.ctx.redactor.redact(`${what} on github ${this.repo} answered ${res.status}${res.text ? `: ${res.text.slice(0, 300)}` : ""}`));
48
+ }
49
+ /** The repository's default branch. */
50
+ async defaultBranch() {
51
+ const res = await this.call("GET", "");
52
+ const branch = res.json?.default_branch;
53
+ if (res.status !== 200 || typeof branch !== "string")
54
+ this.fail("reading the repository", res);
55
+ return branch;
56
+ }
57
+ /** The commit `refs/heads/<branch>` points at, or null when there is no such branch. */
58
+ async branchHead(branch) {
59
+ const res = await this.call("GET", `/git/ref/heads/${branch}`);
60
+ if (res.status === 404)
61
+ return null;
62
+ const sha = res.json?.object?.sha;
63
+ if (res.status !== 200 || typeof sha !== "string")
64
+ this.fail(`reading branch ${branch}`, res);
65
+ return sha;
66
+ }
67
+ /** A file's bytes and blob sha at `ref`, or null when it has none. */
68
+ async file(path, ref) {
69
+ const res = await this.call("GET", `/contents/${path.split("/").map(encodeURIComponent).join("/")}?ref=${encodeURIComponent(ref)}`);
70
+ if (res.status === 404)
71
+ return null;
72
+ const body = res.json;
73
+ if (res.status !== 200 || typeof body?.sha !== "string" || typeof body.content !== "string")
74
+ this.fail(`reading ${path} at ${ref}`, res);
75
+ return { bytes: body.encoding === "base64" ? Buffer.from(body.content, "base64") : Buffer.from(body.content), sha: body.sha };
76
+ }
77
+ /** Commit `bytes` as `path` on `branch`, replacing the blob `sha` when the file is there. Returns the commit. */
78
+ async putFile(path, branch, bytes, message, sha) {
79
+ const res = await this.call("PUT", `/contents/${path.split("/").map(encodeURIComponent).join("/")}`, JSON.stringify({ message, content: Buffer.from(bytes).toString("base64"), branch, ...(sha ? { sha } : {}) }));
80
+ const commit = res.json?.commit?.sha;
81
+ if ((res.status !== 200 && res.status !== 201) || typeof commit !== "string")
82
+ this.fail(`committing ${path} to ${branch}`, res);
83
+ return commit;
84
+ }
85
+ /** Make `refs/heads/<branch>` at `sha`. */
86
+ async createBranch(branch, sha) {
87
+ const res = await this.call("POST", "/git/refs", JSON.stringify({ ref: `refs/heads/${branch}`, sha }));
88
+ if (res.status !== 201)
89
+ this.fail(`creating branch ${branch}`, res);
90
+ }
91
+ /** Move `refs/<ref>` to `sha`. Without `force`, a move that is not a fast-forward answers false. */
92
+ async moveRef(ref, sha, force) {
93
+ const res = await this.call("PATCH", `/git/refs/${ref}`, JSON.stringify({ sha, force }));
94
+ if (res.status === 200)
95
+ return true;
96
+ if (res.status === 422 && !force)
97
+ return false;
98
+ this.fail(`moving ${ref} to ${sha.slice(0, 12)}`, res);
99
+ }
100
+ /** The published release for `tag`, or null. A draft is not found here. */
101
+ async publishedRelease(tag) {
102
+ const res = await this.call("GET", `/releases/tags/${encodeURIComponent(tag)}`);
103
+ if (res.status === 404)
104
+ return null;
105
+ if (res.status !== 200 || !res.json)
106
+ this.fail(`reading release ${tag}`, res);
107
+ return toRelease(res.json);
108
+ }
109
+ /** The draft release for `tag` named `name`, or null. */
110
+ async draftRelease(tag, name) {
111
+ const res = await this.call("GET", "/releases?per_page=100");
112
+ if (res.status !== 200)
113
+ this.fail("listing releases", res);
114
+ const found = (Array.isArray(res.json) ? res.json : []).find((r) => r.draft === true && r.tag_name === tag && r.name === name);
115
+ return found ? toRelease(found) : null;
116
+ }
117
+ /** A new draft release for `tag` named `name`, at `commit`. */
118
+ async createDraft(tag, commit, name) {
119
+ const res = await this.call("POST", "/releases", JSON.stringify({ tag_name: tag, target_commitish: commit, name, draft: true }));
120
+ if (res.status !== 201 || !res.json)
121
+ this.fail(`creating a draft release ${tag}`, res);
122
+ return toRelease(res.json);
123
+ }
124
+ /** Upload `bytes` as the asset `name` of `release`. */
125
+ async uploadAsset(release, name, bytes) {
126
+ const base = (release.uploadUrl ?? `${this.root}/releases/${release.id}/assets`).replace(/\{[^}]*\}$/, "");
127
+ const res = await this.call("POST", `${base}?name=${encodeURIComponent(name)}`, bytes, { "content-type": "application/octet-stream" });
128
+ if (res.status !== 201)
129
+ this.fail(`uploading ${name}`, res);
130
+ }
131
+ /** Publish the draft `id`, with `make_latest` when it is given. */
132
+ async publishDraft(id, makeLatest) {
133
+ return this.call("PATCH", `/releases/${id}`, JSON.stringify(makeLatest === undefined ? { draft: false } : { draft: false, make_latest: makeLatest }));
134
+ }
135
+ /** Delete the release `id`. Its tag stays. */
136
+ async deleteRelease(id) {
137
+ const res = await this.call("DELETE", `/releases/${id}`);
138
+ if (res.status !== 204 && res.status !== 404)
139
+ this.fail(`deleting release ${id}`, res);
140
+ }
141
+ /** Delete `refs/<ref>`. One that is not there is already gone. */
142
+ async deleteRef(ref) {
143
+ const res = await this.call("DELETE", `/git/refs/${ref}`);
144
+ if (res.status !== 204 && res.status !== 404 && res.status !== 422)
145
+ this.fail(`deleting ${ref}`, res);
146
+ }
147
+ }
148
+ function toRelease(body) {
149
+ const assets = new Map();
150
+ for (const a of body.assets ?? [])
151
+ assets.set(a.name, typeof a.digest === "string" ? a.digest : null);
152
+ return { id: String(body.id), draft: body.draft === true, assets, ...(typeof body.upload_url === "string" ? { uploadUrl: body.upload_url } : {}) };
153
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The Homebrew tap target (#4676): a formula in a tap repository on GitHub,
3
+ * rendered from a template in the member with the release's version and each
4
+ * asset's URL and SHA-256, and committed through GitHub's REST API with the
5
+ * token from `tokenEnv` (default `HOMEBREW_TAP_TOKEN`).
6
+ *
7
+ * The template is the formula as the tap holds it, with placeholders where a
8
+ * release changes it:
9
+ *
10
+ * - `{{version}}`: the release's version, its label from the first digit on
11
+ * (`v1.4.0` and `app-v1.4.0` are both `1.4.0`);
12
+ * - `{{url:<name>}}` and `{{sha256:<name>}}`: the URL and the SHA-256 in hex
13
+ * of the declared asset whose file name is `<name>`;
14
+ * - `{{label}}` and `{{tag}}`: the release's label and the tag the cut made.
15
+ *
16
+ * A placeholder chant does not know, or an asset name no declared asset has,
17
+ * is refused (`publish-homebrew-template`). Everything else is copied as it
18
+ * is, so `on_macos`, `on_linux`, `on_arm` and `on_intel` blocks each name
19
+ * their own asset and the formula's Ruby stays the member's. Each SHA-256 is
20
+ * of the file in the checkout, which must match the digest the release
21
+ * records for it.
22
+ *
23
+ * A tap is a branch people install from, with no draft, so the two steps are
24
+ * a branch and a fast-forward (#4048):
25
+ *
26
+ * - The stage commits the rendered formula to `chant-publish/<formula>-<version>`,
27
+ * a branch it makes at the tap branch's head (or moves there, when an
28
+ * earlier stage left it elsewhere). `brew` reads only the tap branch, so
29
+ * nothing is visible. A tap branch that already holds the formula as
30
+ * rendered stages nothing, and a staging branch that already holds it is
31
+ * not committed to again.
32
+ * - The reveal fast-forwards the tap branch to the staged commit, then
33
+ * deletes the staging branch. When the tap branch moved since the stage,
34
+ * the reveal commits the formula onto it instead, one commit either way,
35
+ * unless it already holds the formula as rendered.
36
+ *
37
+ * The asset URLs are the declaration's `url` pattern, so the files must be
38
+ * downloadable there by the time the formula is: declare the `forge` target
39
+ * that attaches them before this one, and its reveal runs first.
40
+ */
41
+ import type { HomebrewPublishDeclaration } from "./publish-declaration.js";
42
+ import { type PublishDeps, type PublishTarget } from "./release-publish.js";
43
+ /** The first chant that publishes a `homebrew` target (#4676). */
44
+ export declare const PUBLISH_HOMEBREW_FLOOR = "0.124.63";
45
+ /** The variable the tap token is read from when the declaration names none. */
46
+ export declare const HOMEBREW_TOKEN_ENV = "HOMEBREW_TAP_TOKEN";
47
+ /** A release's version for a package manager: its label from the first digit on, or null when the label has no digit. */
48
+ export declare function releaseVersion(label: string | null): string | null;
49
+ /** `pattern` with `{tag}`, `{label}`, `{version}` and `{name}` filled in, each URL-encoded except the tag's slashes. */
50
+ export declare function fillUrl(pattern: string, values: {
51
+ tag: string;
52
+ label: string;
53
+ version: string;
54
+ name: string;
55
+ }): string;
56
+ /** Render a formula template, or name what it can't fill. */
57
+ export declare function renderFormula(template: string, values: {
58
+ version: string;
59
+ label: string;
60
+ tag: string;
61
+ }, assets: ReadonlyMap<string, {
62
+ url: string;
63
+ sha256: string;
64
+ }>): string;
65
+ export declare function homebrewTarget(decl: HomebrewPublishDeclaration, deps: PublishDeps): PublishTarget;
66
+ //# sourceMappingURL=publish-homebrew.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-homebrew.d.ts","sourceRoot":"","sources":["../../src/lifecycle/publish-homebrew.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAKH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAGxE,OAAO,EAA2C,KAAK,WAAW,EAAuC,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvJ,kEAAkE;AAClE,eAAO,MAAM,sBAAsB,aAAe,CAAC;AAEnD,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AAEvD,yHAAyH;AACzH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAGlE;AAED,wHAAwH;AACxH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAItH;AAED,6DAA6D;AAC7D,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACvD,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,GAC3D,MAAM,CAYR;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,0BAA0B,EAAE,IAAI,EAAE,WAAW,GAAG,aAAa,CAkGjG"}
@@ -0,0 +1,173 @@
1
+ /**
2
+ * The Homebrew tap target (#4676): a formula in a tap repository on GitHub,
3
+ * rendered from a template in the member with the release's version and each
4
+ * asset's URL and SHA-256, and committed through GitHub's REST API with the
5
+ * token from `tokenEnv` (default `HOMEBREW_TAP_TOKEN`).
6
+ *
7
+ * The template is the formula as the tap holds it, with placeholders where a
8
+ * release changes it:
9
+ *
10
+ * - `{{version}}`: the release's version, its label from the first digit on
11
+ * (`v1.4.0` and `app-v1.4.0` are both `1.4.0`);
12
+ * - `{{url:<name>}}` and `{{sha256:<name>}}`: the URL and the SHA-256 in hex
13
+ * of the declared asset whose file name is `<name>`;
14
+ * - `{{label}}` and `{{tag}}`: the release's label and the tag the cut made.
15
+ *
16
+ * A placeholder chant does not know, or an asset name no declared asset has,
17
+ * is refused (`publish-homebrew-template`). Everything else is copied as it
18
+ * is, so `on_macos`, `on_linux`, `on_arm` and `on_intel` blocks each name
19
+ * their own asset and the formula's Ruby stays the member's. Each SHA-256 is
20
+ * of the file in the checkout, which must match the digest the release
21
+ * records for it.
22
+ *
23
+ * A tap is a branch people install from, with no draft, so the two steps are
24
+ * a branch and a fast-forward (#4048):
25
+ *
26
+ * - The stage commits the rendered formula to `chant-publish/<formula>-<version>`,
27
+ * a branch it makes at the tap branch's head (or moves there, when an
28
+ * earlier stage left it elsewhere). `brew` reads only the tap branch, so
29
+ * nothing is visible. A tap branch that already holds the formula as
30
+ * rendered stages nothing, and a staging branch that already holds it is
31
+ * not committed to again.
32
+ * - The reveal fast-forwards the tap branch to the staged commit, then
33
+ * deletes the staging branch. When the tap branch moved since the stage,
34
+ * the reveal commits the formula onto it instead, one commit either way,
35
+ * unless it already holds the formula as rendered.
36
+ *
37
+ * The asset URLs are the declaration's `url` pattern, so the files must be
38
+ * downloadable there by the time the formula is: declare the `forge` target
39
+ * that attaches them before this one, and its reveal runs first.
40
+ */
41
+ import { readFileSync } from "node:fs";
42
+ import { basename } from "node:path";
43
+ import { readCredential } from "./publish-credentials.js";
44
+ import { GitHubRepo, githubApi } from "./publish-github.js";
45
+ import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets.js";
46
+ import { PublishTargetError } from "./release-publish.js";
47
+ import { NEXT_RELEASE } from "../release-floors.js";
48
+ /** The first chant that publishes a `homebrew` target (#4676). */
49
+ export const PUBLISH_HOMEBREW_FLOOR = NEXT_RELEASE;
50
+ /** The variable the tap token is read from when the declaration names none. */
51
+ export const HOMEBREW_TOKEN_ENV = "HOMEBREW_TAP_TOKEN";
52
+ /** A release's version for a package manager: its label from the first digit on, or null when the label has no digit. */
53
+ export function releaseVersion(label) {
54
+ const at = label?.search(/\d/) ?? -1;
55
+ return label && at >= 0 ? label.slice(at) : null;
56
+ }
57
+ /** `pattern` with `{tag}`, `{label}`, `{version}` and `{name}` filled in, each URL-encoded except the tag's slashes. */
58
+ export function fillUrl(pattern, values) {
59
+ return pattern.replace(/\{(tag|label|version|name)\}/g, (_, k) => k === "tag" ? values.tag.split("/").map(encodeURIComponent).join("/") : encodeURIComponent(values[k]));
60
+ }
61
+ /** Render a formula template, or name what it can't fill. */
62
+ export function renderFormula(template, values, assets) {
63
+ return template.replace(/\{\{\s*([^}]*?)\s*\}\}/g, (whole, inner) => {
64
+ if (inner === "version" || inner === "label" || inner === "tag")
65
+ return values[inner];
66
+ const m = /^(url|sha256):(.+)$/.exec(inner);
67
+ const asset = m ? assets.get(m[2].trim()) : undefined;
68
+ if (m && asset)
69
+ return m[1] === "url" ? asset.url : asset.sha256;
70
+ throw new PublishTargetError("publish-homebrew-template", m ? `the formula template names ${whole}, and no declared asset is named ${m[2].trim()}` : `the formula template has ${whole}, which chant does not fill`, `The placeholders are {{version}}, {{label}}, {{tag}}, and {{url:<name>}} and {{sha256:<name>}} for an asset in assets: ${[...assets.keys()].join(", ")}.`);
71
+ });
72
+ }
73
+ export function homebrewTarget(decl, deps) {
74
+ const fetchImpl = deps.fetch ?? ((url, init) => fetch(url, init));
75
+ const tokenNames = [decl.tokenEnv ?? HOMEBREW_TOKEN_ENV];
76
+ const formulaName = basename(decl.formula).replace(/\.rb$/, "");
77
+ const setup = (ctx) => {
78
+ const version = releaseVersion(ctx.label);
79
+ if (!version || !ctx.label || !ctx.releaseTag) {
80
+ throw new PublishTargetError("publish-homebrew-no-version", `a formula's version is the release's label from its first digit, and release ${ctx.release.releaseDigest} has ${ctx.label ? `the label ${ctx.label}, which has no digit` : "no label"}`, "Cut the release with a label such as v1.4.0.");
81
+ }
82
+ const token = readCredential(ctx.env, tokenNames, ctx.redactor);
83
+ if (!token) {
84
+ throw new PublishTargetError("publish-credentials-missing", `the homebrew target reads its token from ${tokenNames[0]}, and it is not set`, `Set ${tokenNames[0]} to a token that may push to ${decl.tap}.`);
85
+ }
86
+ const assets = new Map();
87
+ for (const p of decl.assets) {
88
+ const abs = memberFile(ctx.cwd, p);
89
+ const digest = bytesDigest(new Uint8Array(readFileSync(abs)));
90
+ checkReleaseDigest(ctx.release, "asset", ctx.cwd, p, [digest]);
91
+ const name = basename(p);
92
+ if (assets.has(name))
93
+ throw new PublishTargetError("publish-homebrew-asset-name-taken", `two assets are named ${name}, and the template names an asset by its file name`);
94
+ const url = fillUrl(decl.url, { tag: ctx.releaseTag, label: ctx.label, version, name });
95
+ assets.set(name, { url, sha256: digest.slice("sha256:".length) });
96
+ }
97
+ const template = readFileSync(memberFile(ctx.cwd, decl.template), "utf-8");
98
+ const bytes = new Uint8Array(Buffer.from(renderFormula(template, { version, label: ctx.label, tag: ctx.releaseTag }, assets), "utf-8"));
99
+ return { version, token, assets, bytes, digest: bytesDigest(bytes) };
100
+ };
101
+ const where = (branch) => `${decl.tap}@${branch}:${decl.formula}`;
102
+ const target = {
103
+ kind: "homebrew",
104
+ name: `homebrew formula ${formulaName} in ${decl.tap}`,
105
+ destination: `github ${decl.tap}`,
106
+ credentialEnv: tokenNames,
107
+ key: publishTargetKey(decl),
108
+ async plan(ctx) {
109
+ const { digest } = setup(ctx);
110
+ return [{ name: decl.formula, destination: where(decl.branch ?? "the default branch"), digest }];
111
+ },
112
+ async stage(ctx) {
113
+ const { version, token, assets, bytes, digest } = setup(ctx);
114
+ ctx.log(`using the token from ${token.from}`);
115
+ for (const [name, a] of assets)
116
+ ctx.log(`${name}: ${a.url} sha256 ${a.sha256}`);
117
+ const tap = new GitHubRepo(githubApi(decl.api, ctx.env), decl.tap, token, fetchImpl, ctx, "publish-homebrew-failed");
118
+ const branch = decl.branch ?? (await tap.defaultBranch());
119
+ const head = await tap.branchHead(branch);
120
+ if (!head)
121
+ throw new PublishTargetError("publish-homebrew-failed", `${decl.tap} has no branch ${branch}`, "Set branch to the branch brew installs from.");
122
+ const item = { name: decl.formula, destination: where(branch), digest };
123
+ const done = (state, present) => ({ target: target.name, destination: target.destination, items: [{ ...item, ...(present ? { present: true } : {}) }], state: { branch, ...state } });
124
+ const onTap = await tap.file(decl.formula, branch);
125
+ if (onTap && onTap.bytes.equals(Buffer.from(bytes))) {
126
+ ctx.log(`${branch} already has ${decl.formula} for ${version}`);
127
+ return done({ present: "true" }, true);
128
+ }
129
+ const staging = `chant-publish/${formulaName}-${version}`;
130
+ const stagingHead = await tap.branchHead(staging);
131
+ if (stagingHead) {
132
+ const onStaging = await tap.file(decl.formula, staging);
133
+ if (onStaging && onStaging.bytes.equals(Buffer.from(bytes))) {
134
+ ctx.log(`${staging} already has ${decl.formula} for ${version}`);
135
+ return done({ staging, commit: stagingHead }, true);
136
+ }
137
+ await tap.moveRef(`heads/${staging}`, head, true);
138
+ }
139
+ else {
140
+ await tap.createBranch(staging, head);
141
+ }
142
+ ctx.log(`committing ${decl.formula} for ${version} to ${staging}, at ${branch}'s head ${head.slice(0, 12)}`);
143
+ const commit = await tap.putFile(decl.formula, staging, bytes, `${formulaName} ${version}`, onTap?.sha ?? null);
144
+ return done({ staging, commit }, false);
145
+ },
146
+ async reveal(ctx, staged) {
147
+ const items = staged.items.map((i) => ({ name: i.name, destination: i.destination, ...(i.digest ? { digest: i.digest } : {}) }));
148
+ const published = { target: target.name, destination: target.destination, items };
149
+ if (staged.state.present === "true")
150
+ return { ...published, items: items.map((i) => ({ ...i, present: true })) };
151
+ const { version, token, bytes } = setup(ctx);
152
+ const { branch, staging, commit } = staged.state;
153
+ if (!branch || !staging || !commit)
154
+ throw new PublishTargetError("publish-homebrew-failed", `the staged formula for ${decl.tap} has no staging commit to reveal`);
155
+ const tap = new GitHubRepo(githubApi(decl.api, ctx.env), decl.tap, token, fetchImpl, ctx, "publish-homebrew-failed");
156
+ ctx.log(`fast-forwarding ${branch} to ${commit.slice(0, 12)}`);
157
+ if (!(await tap.moveRef(`heads/${branch}`, commit, false))) {
158
+ // The tap moved since the stage: one commit of the formula onto it, unless it already holds it.
159
+ const onTap = await tap.file(decl.formula, branch);
160
+ if (onTap && onTap.bytes.equals(Buffer.from(bytes))) {
161
+ ctx.log(`${branch} moved since the stage and already has ${decl.formula} for ${version}`);
162
+ }
163
+ else {
164
+ ctx.log(`${branch} moved since the stage; committing ${decl.formula} for ${version} onto it`);
165
+ await tap.putFile(decl.formula, branch, bytes, `${formulaName} ${version}`, onTap?.sha ?? null);
166
+ }
167
+ }
168
+ await tap.deleteRef(`heads/${staging}`);
169
+ return published;
170
+ },
171
+ };
172
+ return target;
173
+ }
@@ -0,0 +1,51 @@
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
+ import type { MarketplacePublishDeclaration } from "./publish-declaration.js";
35
+ import { type PublishDeps, type PublishTarget } from "./release-publish.js";
36
+ /** The first chant that publishes a `marketplace` target (#4676). */
37
+ export declare const PUBLISH_MARKETPLACE_FLOOR = "0.124.63";
38
+ export declare const OPEN_VSX_REGISTRY = "https://open-vsx.org";
39
+ export declare const VSCODE_GALLERY = "https://marketplace.visualstudio.com";
40
+ /** The variables a marketplace's token is read from. */
41
+ export declare function marketplaceTokenEnv(decl: Pick<MarketplacePublishDeclaration, "marketplace" | "tokenEnv">): string[];
42
+ /** One file of a zip archive, or null when it holds none by that name. Reads stored and deflated entries; refuses a zip64 archive. */
43
+ export declare function readZipEntry(zip: Buffer, name: string): Buffer | null;
44
+ /** The publisher, name and version a `.vsix` declares. */
45
+ export declare function vsixIdentity(bytes: Buffer, path: string): {
46
+ publisher: string;
47
+ name: string;
48
+ version: string;
49
+ };
50
+ export declare function marketplaceTarget(decl: MarketplacePublishDeclaration, deps: PublishDeps): PublishTarget;
51
+ //# sourceMappingURL=publish-marketplace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-marketplace.d.ts","sourceRoot":"","sources":["../../src/lifecycle/publish-marketplace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAMH,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAE3E,OAAO,EAA2C,KAAK,WAAW,EAAuC,KAAK,aAAa,EAAqB,MAAM,mBAAmB,CAAC;AAG1K,qEAAqE;AACrE,eAAO,MAAM,yBAAyB,aAAe,CAAC;AAEtD,eAAO,MAAM,iBAAiB,yBAAyB,CAAC;AACxD,eAAO,MAAM,cAAc,yCAAyC,CAAC;AAErE,wDAAwD;AACxD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,6BAA6B,EAAE,aAAa,GAAG,UAAU,CAAC,GAAG,MAAM,EAAE,CAEnH;AAED,sIAAsI;AACtI,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA6BrE;AAED,0DAA0D;AAC1D,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAc9G;AAkBD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,6BAA6B,EAAE,IAAI,EAAE,WAAW,GAAG,aAAa,CAsIvG"}