@intentius/chant 0.124.62 → 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 (229) 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.d.ts +45 -2
  93. package/dist/workspace/ci-green.d.ts.map +1 -1
  94. package/dist/workspace/ci-green.js +124 -5
  95. package/dist/workspace/ci-quarantine-report.d.ts +80 -0
  96. package/dist/workspace/ci-quarantine-report.d.ts.map +1 -0
  97. package/dist/workspace/ci-quarantine-report.js +205 -0
  98. package/dist/workspace/ci-quarantine.d.ts +73 -0
  99. package/dist/workspace/ci-quarantine.d.ts.map +1 -0
  100. package/dist/workspace/ci-quarantine.js +171 -0
  101. package/dist/workspace/ci-serve.d.ts.map +1 -1
  102. package/dist/workspace/ci-serve.js +7 -4
  103. package/dist/workspace/class-data.d.ts +3 -1
  104. package/dist/workspace/class-data.d.ts.map +1 -1
  105. package/dist/workspace/class-data.js +4 -1
  106. package/dist/workspace/declaration.d.ts +45 -2
  107. package/dist/workspace/declaration.d.ts.map +1 -1
  108. package/dist/workspace/declaration.js +45 -2
  109. package/dist/workspace/declaration.schema.json +51 -3
  110. package/dist/workspace/forge-work.d.ts +76 -0
  111. package/dist/workspace/forge-work.d.ts.map +1 -0
  112. package/dist/workspace/forge-work.js +160 -0
  113. package/dist/workspace/identity-gate-rule.d.ts +3 -2
  114. package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
  115. package/dist/workspace/identity-gate-rule.js +5 -7
  116. package/dist/workspace/identity.d.ts +3 -2
  117. package/dist/workspace/identity.d.ts.map +1 -1
  118. package/dist/workspace/identity.js +6 -3
  119. package/dist/workspace/intent-cli.d.ts +3 -2
  120. package/dist/workspace/intent-cli.d.ts.map +1 -1
  121. package/dist/workspace/intent-cli.js +26 -5
  122. package/dist/workspace/intent-record.d.ts +3 -0
  123. package/dist/workspace/intent-record.d.ts.map +1 -1
  124. package/dist/workspace/intent-record.schema.json +32 -0
  125. package/dist/workspace/intent.d.ts +9 -0
  126. package/dist/workspace/intent.d.ts.map +1 -1
  127. package/dist/workspace/intent.js +3 -0
  128. package/dist/workspace/intent.schema.json +32 -0
  129. package/dist/workspace/kind-readers.d.ts.map +1 -1
  130. package/dist/workspace/kind-readers.js +2 -1
  131. package/dist/workspace/kinds.d.ts +6 -1
  132. package/dist/workspace/kinds.d.ts.map +1 -1
  133. package/dist/workspace/kinds.js +8 -3
  134. package/dist/workspace/plan-stale.schema.json +286 -0
  135. package/dist/workspace/release-candidates.d.ts +33 -6
  136. package/dist/workspace/release-candidates.d.ts.map +1 -1
  137. package/dist/workspace/release-candidates.js +49 -20
  138. package/dist/workspace/release-candidates.schema.json +48 -2
  139. package/dist/workspace/trust/policy.d.ts +10 -0
  140. package/dist/workspace/trust/policy.d.ts.map +1 -1
  141. package/dist/workspace/trust/policy.js +19 -1
  142. package/dist/workspace/trust/run-commits.d.ts.map +1 -1
  143. package/dist/workspace/trust/run-commits.js +2 -1
  144. package/dist/workspace/trust/seal.d.ts.map +1 -1
  145. package/dist/workspace/trust/seal.js +34 -3
  146. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  147. package/dist/workspace/trust/trust-files.js +6 -1
  148. package/package.json +2 -1
  149. package/src/cli/handlers/approve-external-signature.test.ts +226 -0
  150. package/src/cli/handlers/approve.ts +174 -16
  151. package/src/cli/handlers/plan.ts +74 -0
  152. package/src/cli/handlers/release.ts +12 -7
  153. package/src/cli/main.ts +34 -5
  154. package/src/cli/mcp/workspace-tools.ts +2 -1
  155. package/src/cli/parse-args.ts +24 -0
  156. package/src/cli/registry.ts +13 -1
  157. package/src/gate-decision-bundle.test.ts +4 -2
  158. package/src/gate-decision.ts +11 -2
  159. package/src/gate-statement.schema.json +44 -0
  160. package/src/lifecycle/__fixtures__/publish-fakes.ts +125 -5
  161. package/src/lifecycle/gate-ledger.ts +17 -3
  162. package/src/lifecycle/gate-seal.ts +62 -9
  163. package/src/lifecycle/gate-statement.ts +107 -0
  164. package/src/lifecycle/gate-webauthn.test.ts +77 -0
  165. package/src/lifecycle/gate-webauthn.ts +133 -0
  166. package/src/lifecycle/git.ts +23 -19
  167. package/src/lifecycle/ledger-remote.test.ts +183 -0
  168. package/src/lifecycle/ledger-remote.ts +46 -0
  169. package/src/lifecycle/plan-stale.test.ts +150 -0
  170. package/src/lifecycle/plan-stale.ts +173 -0
  171. package/src/lifecycle/publish-credentials.ts +2 -0
  172. package/src/lifecycle/publish-declaration.ts +93 -1
  173. package/src/lifecycle/publish-forge.ts +15 -4
  174. package/src/lifecycle/publish-github.ts +174 -0
  175. package/src/lifecycle/publish-homebrew.test.ts +179 -0
  176. package/src/lifecycle/publish-homebrew.ts +187 -0
  177. package/src/lifecycle/publish-marketplace.test.ts +254 -0
  178. package/src/lifecycle/publish-marketplace.ts +259 -0
  179. package/src/lifecycle/publish-target-context.test.ts +2 -2
  180. package/src/lifecycle/publish-targets.test.ts +23 -0
  181. package/src/lifecycle/publish-targets.ts +15 -0
  182. package/src/lifecycle/publish-tauri.test.ts +163 -0
  183. package/src/lifecycle/publish-tauri.ts +199 -0
  184. package/src/lifecycle/release-publish.ts +5 -3
  185. package/src/lifecycle/snapshot-store.ts +16 -9
  186. package/src/lifecycle/test-passkey.ts +55 -0
  187. package/src/notify-bundle.test.ts +3 -1
  188. package/src/notify.schema.json +12 -3
  189. package/src/notify.ts +20 -3
  190. package/src/override-gate-bundle.test.ts +2 -0
  191. package/src/pr-forge-bundle.test.ts +2 -2
  192. package/src/pr-forge.test.ts +38 -0
  193. package/src/pr-forge.ts +68 -5
  194. package/src/release-floors.ts +1 -1
  195. package/src/stage-hooks-bundle.test.ts +2 -0
  196. package/src/wave-runtime-bundle.test.ts +3 -2
  197. package/src/workspace/ci-builds.ts +27 -0
  198. package/src/workspace/ci-green-stale.test.ts +193 -0
  199. package/src/workspace/ci-green.ts +138 -6
  200. package/src/workspace/ci-quarantine-report.test.ts +146 -0
  201. package/src/workspace/ci-quarantine-report.ts +235 -0
  202. package/src/workspace/ci-quarantine.test.ts +161 -0
  203. package/src/workspace/ci-quarantine.ts +189 -0
  204. package/src/workspace/ci-serve.ts +7 -4
  205. package/src/workspace/class-data.ts +5 -1
  206. package/src/workspace/declaration.schema.json +51 -3
  207. package/src/workspace/declaration.test.ts +1 -0
  208. package/src/workspace/declaration.ts +88 -5
  209. package/src/workspace/forge-work.test.ts +143 -0
  210. package/src/workspace/forge-work.ts +195 -0
  211. package/src/workspace/identity-gate-rule.ts +6 -8
  212. package/src/workspace/identity.ts +6 -3
  213. package/src/workspace/intent-cli.ts +24 -5
  214. package/src/workspace/intent-record.schema.json +32 -0
  215. package/src/workspace/intent-record.ts +3 -0
  216. package/src/workspace/intent.schema.json +32 -0
  217. package/src/workspace/intent.ts +10 -0
  218. package/src/workspace/kind-readers.ts +2 -1
  219. package/src/workspace/kinds.test.ts +13 -0
  220. package/src/workspace/kinds.ts +12 -3
  221. package/src/workspace/plan-stale.schema.json +286 -0
  222. package/src/workspace/release-candidates.schema.json +48 -2
  223. package/src/workspace/release-candidates.test.ts +77 -4
  224. package/src/workspace/release-candidates.ts +62 -20
  225. package/src/workspace/trust/policy.ts +24 -1
  226. package/src/workspace/trust/run-commits.ts +2 -1
  227. package/src/workspace/trust/seal.ts +35 -3
  228. package/src/workspace/trust/trust-files.test.ts +5 -0
  229. package/src/workspace/trust/trust-files.ts +15 -1
@@ -10,6 +10,9 @@
10
10
  * { type: "npm", packages: ["packages/core", "packages/cli"] },
11
11
  * { type: "oci", image: "dist/api.oci.tar", repository: "ghcr.io/acme/api", tags: ["{label}"], usernameEnv: "GITHUB_ACTOR", passwordEnv: "GITHUB_TOKEN" },
12
12
  * { type: "forge", forge: "github", repo: "acme/api", assets: ["dist/api-linux-amd64.tar.gz"] },
13
+ * { type: "marketplace", marketplace: "openvsx", vsix: "dist/acme.vsix" },
14
+ * { type: "tauri-updater", repo: "acme/app", tag: "app-latest", platforms: { "darwin-aarch64": "dist/Acme_aarch64.app.tar.gz" } },
15
+ * { type: "homebrew", tap: "acme/homebrew-tap", formula: "Formula/api.rb", template: "packaging/api.rb", assets: ["dist/api-linux-amd64.tar.gz"], url: "https://github.com/acme/api/releases/download/{tag}/{name}" },
13
16
  * ],
14
17
  * },
15
18
  * };
@@ -106,12 +109,101 @@ export const ForgePublishSchema = z
106
109
  tokenEnv: envName.optional(),
107
110
  /** The SBOM attached to the release (#4049), relative to the member. Default: one written from the member's lockfile. `false` publishes without one. */
108
111
  sbom: sbomField.optional(),
112
+ /**
113
+ * GitHub only (#4676): whether the release becomes the repository's
114
+ * latest when the reveal publishes it, sent as GitHub's `make_latest`.
115
+ * `"legacy"` lets GitHub pick by creation date and semantic version.
116
+ * Unset, nothing is sent and GitHub makes it latest.
117
+ */
118
+ latest: z.union([z.boolean(), z.literal("legacy")]).optional(),
119
+ })
120
+ .strict();
121
+
122
+ /**
123
+ * A Homebrew formula in a tap repository on GitHub (#4676), rendered from a
124
+ * template in the member with the release's version and each asset's URL and
125
+ * SHA-256 (./publish-homebrew.ts).
126
+ */
127
+ export const HomebrewPublishSchema = z
128
+ .object({
129
+ type: z.literal("homebrew"),
130
+ /** The tap's repository, `owner/name`, such as `acme/homebrew-tap`. */
131
+ tap: z.string().regex(/^[^/\s]+\/[^/\s]+$/, "owner/name"),
132
+ /** The formula's path in the tap, such as `Formula/api.rb`. */
133
+ formula: z.string().min(1),
134
+ /** The formula with placeholders, relative to the member: `{{version}}`, `{{label}}`, `{{tag}}`, `{{url:<asset name>}}`, `{{sha256:<asset name>}}`. */
135
+ template: z.string().min(1),
136
+ /** The files the formula downloads, relative to the member. Each is named in the template by its file name. */
137
+ assets: z.array(z.string().min(1)).min(1),
138
+ /** Where each asset is downloaded from: `{tag}`, `{label}`, `{version}` and `{name}` (its file name) are filled in. */
139
+ url: z.string().min(1),
140
+ /** The tap's branch that brew installs from. Default: the repository's default branch. */
141
+ branch: z.string().min(1).optional(),
142
+ /** The GitHub API root. Default `$GITHUB_API_URL`, else `https://api.github.com`. */
143
+ api: z.string().url().optional(),
144
+ /** The variable holding a token that may push to the tap. Default `HOMEBREW_TAP_TOKEN`. */
145
+ tokenEnv: envName.optional(),
146
+ })
147
+ .strict();
148
+
149
+ /**
150
+ * A packaged `.vsix` on the VS Code Marketplace or Open VSX (#4676), uploaded
151
+ * at the reveal, since a marketplace has no draft (./publish-marketplace.ts).
152
+ */
153
+ export const MarketplacePublishSchema = z
154
+ .object({
155
+ type: z.literal("marketplace"),
156
+ marketplace: z.enum(["vscode", "openvsx"]),
157
+ /** The `.vsix` that `vsce package` wrote, relative to the member. Its publisher, name and version are read from it. */
158
+ vsix: z.string().min(1),
159
+ /** Open VSX's root, default `https://open-vsx.org`; the VS Code Marketplace's gallery, default `https://marketplace.visualstudio.com`. */
160
+ registry: z.string().url().optional(),
161
+ /** The variable holding the token. Default `VSCE_PAT` for the VS Code Marketplace, `OVSX_PAT` for Open VSX. */
162
+ tokenEnv: envName.optional(),
163
+ })
164
+ .strict();
165
+
166
+ /**
167
+ * A Tauri v2 updater manifest and the rolling GitHub release that holds it
168
+ * with the app's bundles (#4676), replaced on each publish
169
+ * (./publish-tauri.ts).
170
+ */
171
+ export const TauriUpdaterPublishSchema = z
172
+ .object({
173
+ type: z.literal("tauri-updater"),
174
+ /** The GitHub repository, `owner/name`. */
175
+ repo: z.string().regex(/^[^/\s]+\/[^/\s]+$/, "owner/name"),
176
+ /** The rolling release's tag, such as `app-latest`. */
177
+ tag: z.string().min(1),
178
+ /**
179
+ * Each updater platform, such as `darwin-aarch64`, `linux-x86_64` or
180
+ * `windows-x86_64-nsis`, and its updater bundle, relative to the member.
181
+ * Its signature is the `.sig` file beside it that the Tauri build wrote.
182
+ */
183
+ platforms: z.record(z.string().regex(/^(darwin|linux|windows)-[a-z0-9_]+(-[a-z0-9]+)?$/, "<os>-<arch> or <os>-<arch>-<installer>"), z.string().min(1)).refine((p) => Object.keys(p).length > 0, "at least one platform"),
184
+ /** More files the rolling release holds, such as installers for the site's download links, relative to the member. */
185
+ assets: z.array(z.string().min(1)).optional(),
186
+ /** A file whose text is the manifest's `notes`, relative to the member. */
187
+ notes: z.string().min(1).optional(),
188
+ /** Each platform's URL in the manifest: `{tag}` (the rolling tag), `{label}`, `{version}` and `{name}` are filled in. Default: the bundle's download URL on the rolling release on github.com. */
189
+ url: z.string().min(1).optional(),
190
+ /** The manifest's asset name. Default `latest.json`. */
191
+ manifest: z.string().regex(/^[^/\\]+$/, "a file name").optional(),
192
+ /** GitHub's `make_latest` for the rolling release. Default `false`. */
193
+ latest: z.union([z.boolean(), z.literal("legacy")]).optional(),
194
+ /** The GitHub API root. Default `$GITHUB_API_URL`, else `https://api.github.com`. */
195
+ api: z.string().url().optional(),
196
+ /** The variable holding the token. Default `GITHUB_TOKEN`. */
197
+ tokenEnv: envName.optional(),
109
198
  })
110
199
  .strict();
111
200
 
112
- export const PublishDeclarationSchema = z.discriminatedUnion("type", [NpmPublishSchema, OciPublishSchema, ForgePublishSchema]);
201
+ export const PublishDeclarationSchema = z.discriminatedUnion("type", [NpmPublishSchema, OciPublishSchema, ForgePublishSchema, HomebrewPublishSchema, MarketplacePublishSchema, TauriUpdaterPublishSchema]);
113
202
 
114
203
  export type NpmPublishDeclaration = z.infer<typeof NpmPublishSchema>;
115
204
  export type OciPublishDeclaration = z.infer<typeof OciPublishSchema>;
116
205
  export type ForgePublishDeclaration = z.infer<typeof ForgePublishSchema>;
206
+ export type HomebrewPublishDeclaration = z.infer<typeof HomebrewPublishSchema>;
207
+ export type MarketplacePublishDeclaration = z.infer<typeof MarketplacePublishSchema>;
208
+ export type TauriUpdaterPublishDeclaration = z.infer<typeof TauriUpdaterPublishSchema>;
117
209
  export type PublishDeclaration = z.infer<typeof PublishDeclarationSchema>;
@@ -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
@@ -49,6 +51,10 @@ import { readCredential, type Credential } from "./publish-credentials";
49
51
  import type { ForgePublishDeclaration } from "./publish-declaration";
50
52
  import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets";
51
53
  import { PublishTargetError, type PublishContext, type PublishDeps, type PublishFetch, type PublishItem, type PublishTarget, type StagedTarget } from "./release-publish";
54
+ import { NEXT_RELEASE } from "../release-floors";
55
+
56
+ /** The first chant that reads `latest` on a forge target and sends it as GitHub's `make_latest` (#4676). */
57
+ export const PUBLISH_FORGE_LATEST_FLOOR = NEXT_RELEASE;
52
58
 
53
59
  /** The variables a forge's token is read from, in order. */
54
60
  export function forgeTokenEnv(decl: Pick<ForgePublishDeclaration, "forge" | "tokenEnv">): string[] {
@@ -155,9 +161,11 @@ class ForgeClient {
155
161
  return this.toRelease(create.json as Record<string, unknown>, tag);
156
162
  }
157
163
 
158
- /** GitHub and Forgejo: publish the draft `id`. */
164
+ /** GitHub and Forgejo: publish the draft `id`, with GitHub's `make_latest` when `latest` is declared. */
159
165
  async publishDraft(id: string, tag: string): Promise<void> {
160
- const res = await this.call("PATCH", `${this.repoPath}/releases/${id}`, JSON.stringify({ draft: false }));
166
+ const latest = this.decl.latest;
167
+ const body = latest === undefined ? { draft: false } : { draft: false, make_latest: String(latest) };
168
+ const res = await this.call("PATCH", `${this.repoPath}/releases/${id}`, JSON.stringify(body));
161
169
  if (res.status !== 200) this.fail(`publishing the draft release ${tag}`, res.status, res.text);
162
170
  }
163
171
 
@@ -208,6 +216,9 @@ export function forgeTarget(decl: ForgePublishDeclaration, deps: PublishDeps): P
208
216
  if (!tag) {
209
217
  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.");
210
218
  }
219
+ if (decl.latest !== undefined && decl.forge !== "github") {
220
+ 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.");
221
+ }
211
222
  const api = forgeApi(decl, ctx.env);
212
223
  if (!api) 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.");
213
224
  const token = readCredential(ctx.env, tokenNames, ctx.redactor);
@@ -316,7 +327,7 @@ export function forgeTarget(decl: ForgePublishDeclaration, deps: PublishDeps): P
316
327
  } else {
317
328
  const id = staged.state.releaseId;
318
329
  if (!id) throw new PublishTargetError("publish-forge-failed", `the staged ${decl.forge} release for ${tag} has no draft id to publish`);
319
- ctx.log(`publishing the draft ${decl.forge} release ${tag}`);
330
+ ctx.log(`publishing the draft ${decl.forge} release ${tag}${decl.latest === undefined ? "" : ` with make_latest ${String(decl.latest)}`}`);
320
331
  await client.publishDraft(id, tag);
321
332
  }
322
333
  return { target: this.name, destination: this.destination, items };
@@ -0,0 +1,174 @@
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
+
8
+ import type { Credential } from "./publish-credentials";
9
+ import { PublishTargetError, type PublishContextBase, type PublishFetch } from "./release-publish";
10
+
11
+ /** The API root of GitHub: `api`, else `$GITHUB_API_URL`, else `https://api.github.com`. */
12
+ export function githubApi(api: string | undefined, env: NodeJS.ProcessEnv): string {
13
+ return (api ?? env.GITHUB_API_URL ?? "https://api.github.com").replace(/\/+$/, "");
14
+ }
15
+
16
+ export interface GitHubAnswer {
17
+ status: number;
18
+ json: unknown;
19
+ text: string;
20
+ }
21
+
22
+ /** One repository on GitHub, reached with one token. */
23
+ export class GitHubRepo {
24
+ constructor(
25
+ readonly api: string,
26
+ readonly repo: string,
27
+ private readonly token: Credential,
28
+ private readonly fetchImpl: PublishFetch,
29
+ private readonly ctx: PublishContextBase,
30
+ /** The code a failed request throws. */
31
+ private readonly code: string,
32
+ ) {}
33
+
34
+ get root(): string {
35
+ return `${this.api}/repos/${this.repo}`;
36
+ }
37
+
38
+ async call(method: string, url: string, body?: Uint8Array | string, extra: Record<string, string> = {}): Promise<GitHubAnswer> {
39
+ const headers = {
40
+ authorization: `Bearer ${this.token.value}`,
41
+ accept: "application/vnd.github+json",
42
+ "user-agent": "chant",
43
+ ...(typeof body === "string" ? { "content-type": "application/json" } : {}),
44
+ ...extra,
45
+ };
46
+ const res = await this.fetchImpl(url.startsWith("http") ? url : `${this.root}${url}`, { method, headers, ...(body !== undefined ? { body } : {}) });
47
+ const text = await res.text();
48
+ let json: unknown = null;
49
+ try {
50
+ json = text ? JSON.parse(text) : null;
51
+ } catch {
52
+ json = null;
53
+ }
54
+ return { status: res.status, json, text };
55
+ }
56
+
57
+ fail(what: string, res: GitHubAnswer): never {
58
+ throw new PublishTargetError(this.code, this.ctx.redactor.redact(`${what} on github ${this.repo} answered ${res.status}${res.text ? `: ${res.text.slice(0, 300)}` : ""}`));
59
+ }
60
+
61
+ /** The repository's default branch. */
62
+ async defaultBranch(): Promise<string> {
63
+ const res = await this.call("GET", "");
64
+ const branch = (res.json as { default_branch?: unknown } | null)?.default_branch;
65
+ if (res.status !== 200 || typeof branch !== "string") this.fail("reading the repository", res);
66
+ return branch;
67
+ }
68
+
69
+ /** The commit `refs/heads/<branch>` points at, or null when there is no such branch. */
70
+ async branchHead(branch: string): Promise<string | null> {
71
+ const res = await this.call("GET", `/git/ref/heads/${branch}`);
72
+ if (res.status === 404) return null;
73
+ const sha = (res.json as { object?: { sha?: unknown } } | null)?.object?.sha;
74
+ if (res.status !== 200 || typeof sha !== "string") this.fail(`reading branch ${branch}`, res);
75
+ return sha;
76
+ }
77
+
78
+ /** A file's bytes and blob sha at `ref`, or null when it has none. */
79
+ async file(path: string, ref: string): Promise<{ bytes: Buffer; sha: string } | null> {
80
+ const res = await this.call("GET", `/contents/${path.split("/").map(encodeURIComponent).join("/")}?ref=${encodeURIComponent(ref)}`);
81
+ if (res.status === 404) return null;
82
+ const body = res.json as { content?: unknown; sha?: unknown; encoding?: unknown } | null;
83
+ if (res.status !== 200 || typeof body?.sha !== "string" || typeof body.content !== "string") this.fail(`reading ${path} at ${ref}`, res);
84
+ return { bytes: body.encoding === "base64" ? Buffer.from(body.content, "base64") : Buffer.from(body.content), sha: body.sha };
85
+ }
86
+
87
+ /** Commit `bytes` as `path` on `branch`, replacing the blob `sha` when the file is there. Returns the commit. */
88
+ async putFile(path: string, branch: string, bytes: Uint8Array, message: string, sha: string | null): Promise<string> {
89
+ const res = await this.call(
90
+ "PUT",
91
+ `/contents/${path.split("/").map(encodeURIComponent).join("/")}`,
92
+ JSON.stringify({ message, content: Buffer.from(bytes).toString("base64"), branch, ...(sha ? { sha } : {}) }),
93
+ );
94
+ const commit = (res.json as { commit?: { sha?: unknown } } | null)?.commit?.sha;
95
+ if ((res.status !== 200 && res.status !== 201) || typeof commit !== "string") this.fail(`committing ${path} to ${branch}`, res);
96
+ return commit;
97
+ }
98
+
99
+ /** Make `refs/heads/<branch>` at `sha`. */
100
+ async createBranch(branch: string, sha: string): Promise<void> {
101
+ const res = await this.call("POST", "/git/refs", JSON.stringify({ ref: `refs/heads/${branch}`, sha }));
102
+ if (res.status !== 201) this.fail(`creating branch ${branch}`, res);
103
+ }
104
+
105
+ /** Move `refs/<ref>` to `sha`. Without `force`, a move that is not a fast-forward answers false. */
106
+ async moveRef(ref: string, sha: string, force: boolean): Promise<boolean> {
107
+ const res = await this.call("PATCH", `/git/refs/${ref}`, JSON.stringify({ sha, force }));
108
+ if (res.status === 200) return true;
109
+ if (res.status === 422 && !force) return false;
110
+ this.fail(`moving ${ref} to ${sha.slice(0, 12)}`, res);
111
+ }
112
+
113
+ /** The published release for `tag`, or null. A draft is not found here. */
114
+ async publishedRelease(tag: string): Promise<GitHubRelease | null> {
115
+ const res = await this.call("GET", `/releases/tags/${encodeURIComponent(tag)}`);
116
+ if (res.status === 404) return null;
117
+ if (res.status !== 200 || !res.json) this.fail(`reading release ${tag}`, res);
118
+ return toRelease(res.json as Record<string, unknown>);
119
+ }
120
+
121
+ /** The draft release for `tag` named `name`, or null. */
122
+ async draftRelease(tag: string, name: string): Promise<GitHubRelease | null> {
123
+ const res = await this.call("GET", "/releases?per_page=100");
124
+ if (res.status !== 200) this.fail("listing releases", res);
125
+ const found = (Array.isArray(res.json) ? (res.json as Array<Record<string, unknown>>) : []).find((r) => r.draft === true && r.tag_name === tag && r.name === name);
126
+ return found ? toRelease(found) : null;
127
+ }
128
+
129
+ /** A new draft release for `tag` named `name`, at `commit`. */
130
+ async createDraft(tag: string, commit: string, name: string): Promise<GitHubRelease> {
131
+ const res = await this.call("POST", "/releases", JSON.stringify({ tag_name: tag, target_commitish: commit, name, draft: true }));
132
+ if (res.status !== 201 || !res.json) this.fail(`creating a draft release ${tag}`, res);
133
+ return toRelease(res.json as Record<string, unknown>);
134
+ }
135
+
136
+ /** Upload `bytes` as the asset `name` of `release`. */
137
+ async uploadAsset(release: GitHubRelease, name: string, bytes: Uint8Array): Promise<void> {
138
+ const base = (release.uploadUrl ?? `${this.root}/releases/${release.id}/assets`).replace(/\{[^}]*\}$/, "");
139
+ const res = await this.call("POST", `${base}?name=${encodeURIComponent(name)}`, bytes, { "content-type": "application/octet-stream" });
140
+ if (res.status !== 201) this.fail(`uploading ${name}`, res);
141
+ }
142
+
143
+ /** Publish the draft `id`, with `make_latest` when it is given. */
144
+ async publishDraft(id: string, makeLatest: string | undefined): Promise<GitHubAnswer> {
145
+ return this.call("PATCH", `/releases/${id}`, JSON.stringify(makeLatest === undefined ? { draft: false } : { draft: false, make_latest: makeLatest }));
146
+ }
147
+
148
+ /** Delete the release `id`. Its tag stays. */
149
+ async deleteRelease(id: string): Promise<void> {
150
+ const res = await this.call("DELETE", `/releases/${id}`);
151
+ if (res.status !== 204 && res.status !== 404) this.fail(`deleting release ${id}`, res);
152
+ }
153
+
154
+ /** Delete `refs/<ref>`. One that is not there is already gone. */
155
+ async deleteRef(ref: string): Promise<void> {
156
+ const res = await this.call("DELETE", `/git/refs/${ref}`);
157
+ if (res.status !== 204 && res.status !== 404 && res.status !== 422) this.fail(`deleting ${ref}`, res);
158
+ }
159
+ }
160
+
161
+ /** A GitHub release as the targets read it. */
162
+ export interface GitHubRelease {
163
+ id: string;
164
+ draft: boolean;
165
+ /** Asset names, with the digest GitHub reports. */
166
+ assets: Map<string, string | null>;
167
+ uploadUrl?: string;
168
+ }
169
+
170
+ function toRelease(body: Record<string, unknown>): GitHubRelease {
171
+ const assets = new Map<string, string | null>();
172
+ for (const a of (body.assets as Array<{ name: string; digest?: string | null }> | undefined) ?? []) assets.set(a.name, typeof a.digest === "string" ? a.digest : null);
173
+ return { id: String(body.id), draft: body.draft === true, assets, ...(typeof body.upload_url === "string" ? { uploadUrl: body.upload_url } : {}) };
174
+ }
@@ -0,0 +1,179 @@
1
+ /**
2
+ * #4676: the Homebrew tap target against a GitHub repository fake. The stage
3
+ * commits the rendered formula to a staging branch that brew does not read,
4
+ * and the tap branch moves only at the reveal. Nothing reaches a network.
5
+ */
6
+
7
+ import { afterAll, describe, expect, test } from "vitest";
8
+ import { createHash } from "node:crypto";
9
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
10
+ import { tmpdir } from "node:os";
11
+ import { join } from "node:path";
12
+ import { createRedactor } from "./publish-credentials";
13
+ import { PublishDeclarationSchema } from "./publish-declaration";
14
+ import { fillUrl, releaseVersion, renderFormula } from "./publish-homebrew";
15
+ import { createPublishTargets } from "./publish-targets";
16
+ import { PublishTargetError, type PublishContext } from "./release-publish";
17
+ import { makeRelease, type ReleaseArtifact } from "./release-store";
18
+ import { startFakeGitHubRepo } from "./__fixtures__/publish-fakes";
19
+
20
+ const dirs: string[] = [];
21
+ afterAll(() => {
22
+ for (const d of dirs) rmSync(d, { recursive: true, force: true });
23
+ });
24
+
25
+ function context(cwd: string, over: Partial<PublishContext> & { artifacts?: ReleaseArtifact[] } = {}): PublishContext & { lines: string[] } {
26
+ const env = over.env ?? { HOMEBREW_TAP_TOKEN: "ghp_taptokentap" };
27
+ const redactor = createRedactor(env);
28
+ const lines: string[] = [];
29
+ const release = makeRelease({ member: null, commit: "c0ffee".padEnd(40, "0"), artifactDigests: over.artifacts ?? [], targets: [{ env: "dev", params: [], templates: [] }] });
30
+ return { release, label: "v1.4.0", releaseTag: "release/v1.4.0", provenance: { oidc: false, ci: null, reason: "" }, cwd, tag: null, env, redactor, log: (l) => lines.push(redactor.redact(l)), ...over, lines };
31
+ }
32
+
33
+ async function refused(p: Promise<unknown>): Promise<PublishTargetError> {
34
+ try {
35
+ await p;
36
+ } catch (err) {
37
+ if (err instanceof PublishTargetError) return err;
38
+ throw err;
39
+ }
40
+ throw new Error("expected a PublishTargetError");
41
+ }
42
+
43
+ const sha = (text: string) => createHash("sha256").update(text).digest("hex");
44
+ const API = "https://api.github.test";
45
+ const FILES = { "arugula-darwin-arm64.tar.gz": "mac arm", "arugula-darwin-amd64.tar.gz": "mac intel", "arugula-linux-arm64.tar.gz": "linux arm", "arugula-linux-amd64.tar.gz": "linux intel" };
46
+ const TEMPLATE = `class Arugula < Formula
47
+ desc "Arugula daemon"
48
+ homepage "https://arugula.example"
49
+ version "{{version}}"
50
+
51
+ on_macos do
52
+ on_arm do
53
+ url "{{url:arugula-darwin-arm64.tar.gz}}"
54
+ sha256 "{{sha256:arugula-darwin-arm64.tar.gz}}"
55
+ end
56
+ on_intel do
57
+ url "{{url:arugula-darwin-amd64.tar.gz}}"
58
+ sha256 "{{sha256:arugula-darwin-amd64.tar.gz}}"
59
+ end
60
+ end
61
+
62
+ on_linux do
63
+ on_arm do
64
+ url "{{url:arugula-linux-arm64.tar.gz}}"
65
+ sha256 "{{sha256:arugula-linux-arm64.tar.gz}}"
66
+ end
67
+ on_intel do
68
+ url "{{url:arugula-linux-amd64.tar.gz}}"
69
+ sha256 "{{sha256:arugula-linux-amd64.tar.gz}}"
70
+ end
71
+ end
72
+
73
+ def install
74
+ bin.install "arugula"
75
+ end
76
+ end
77
+ `;
78
+
79
+ function member(template = TEMPLATE): string {
80
+ const dir = mkdtempSync(join(tmpdir(), "chant-publish-homebrew-"));
81
+ dirs.push(dir);
82
+ mkdirSync(join(dir, "dist"));
83
+ mkdirSync(join(dir, "packaging"));
84
+ for (const [name, bytes] of Object.entries(FILES)) writeFileSync(join(dir, "dist", name), bytes);
85
+ writeFileSync(join(dir, "packaging", "arugula.rb"), template);
86
+ return dir;
87
+ }
88
+
89
+ const declaration = (over: Record<string, unknown> = {}) =>
90
+ PublishDeclarationSchema.parse({
91
+ type: "homebrew",
92
+ tap: "arugula-salad/homebrew-tap",
93
+ formula: "Formula/arugula.rb",
94
+ template: "packaging/arugula.rb",
95
+ assets: Object.keys(FILES).map((n) => `dist/${n}`),
96
+ url: "https://github.com/arugula-salad/arugula/releases/download/{tag}/{name}",
97
+ api: API,
98
+ ...over,
99
+ });
100
+
101
+ describe("homebrew tap (#4676)", () => {
102
+ test("renders the formula per platform, commits it to a staging branch brew does not read, and fast-forwards the tap branch only at the reveal", async () => {
103
+ const dir = member();
104
+ const tap = startFakeGitHubRepo(API, "arugula-salad/homebrew-tap", "main", { "Formula/arugula.rb": "old formula\n", "README.md": "tap\n" });
105
+ const [target] = await createPublishTargets([declaration()], { fetch: tap.fetch });
106
+ const ctx = context(dir);
107
+ const formula = TEMPLATE.replace("{{version}}", "1.4.0").replace(/\{\{(url|sha256):([^}]+)\}\}/g, (_, k: string, name: string) =>
108
+ k === "url" ? `https://github.com/arugula-salad/arugula/releases/download/release/v1.4.0/${name}` : sha(FILES[name as keyof typeof FILES]),
109
+ );
110
+ const digest = `sha256:${sha(formula)}`;
111
+ expect(await target!.plan(ctx)).toEqual([{ name: "Formula/arugula.rb", destination: "arugula-salad/homebrew-tap@the default branch:Formula/arugula.rb", digest }]);
112
+ expect(tap.calls).toEqual([]);
113
+
114
+ const main = tap.branches.get("main");
115
+ const staged = await target!.stage(ctx);
116
+ expect(staged.items).toEqual([{ name: "Formula/arugula.rb", destination: "arugula-salad/homebrew-tap@main:Formula/arugula.rb", digest }]);
117
+ expect(staged.state).toMatchObject({ branch: "main", staging: "chant-publish/arugula-1.4.0" });
118
+ expect(tap.branches.get("main")).toBe(main);
119
+ expect(tap.read("main", "Formula/arugula.rb")).toBe("old formula\n");
120
+ expect(tap.read("chant-publish/arugula-1.4.0", "Formula/arugula.rb")).toBe(formula);
121
+ expect(tap.calls[0]!.headers).toMatchObject({ authorization: "Bearer ghp_taptokentap" });
122
+
123
+ // A stage run again finds the staging branch holding the formula and commits nothing.
124
+ const n = tap.calls.length;
125
+ const again = await target!.stage(ctx);
126
+ expect(again.state).toEqual(staged.state);
127
+ expect(tap.calls.slice(n).map((c) => c.method)).toEqual(["GET", "GET", "GET", "GET", "GET"]);
128
+
129
+ await target!.reveal(ctx, staged);
130
+ expect(tap.read("main", "Formula/arugula.rb")).toBe(formula);
131
+ expect(tap.read("main", "README.md")).toBe("tap\n");
132
+ expect(tap.log("main")).toEqual(["init", "arugula 1.4.0"]);
133
+ expect(tap.branches.has("chant-publish/arugula-1.4.0")).toBe(false);
134
+ expect(ctx.lines.join("\n")).not.toContain("ghp_taptokentap");
135
+
136
+ // Revealed: a stage finds the tap holding the formula and stages nothing.
137
+ const done = await target!.stage(ctx);
138
+ expect(done.state).toEqual({ branch: "main", present: "true" });
139
+ expect(done.items[0]!.present).toBe(true);
140
+ expect(await target!.reveal(ctx, done)).toMatchObject({ items: [{ present: true }] });
141
+ expect(tap.log("main")).toEqual(["init", "arugula 1.4.0"]);
142
+ });
143
+
144
+ test("a tap branch that moved since the stage gets the formula as one commit on top", async () => {
145
+ const dir = member();
146
+ const tap = startFakeGitHubRepo(API, "arugula-salad/homebrew-tap", "main", { "Formula/arugula.rb": "old formula\n" });
147
+ const [target] = await createPublishTargets([declaration({ branch: "main" })], { fetch: tap.fetch });
148
+ const ctx = context(dir);
149
+ const staged = await target!.stage(ctx);
150
+ tap.push("main", { "Formula/other.rb": "other\n" });
151
+ await target!.reveal(ctx, staged);
152
+ expect(tap.log("main")).toEqual(["init", "someone else", "arugula 1.4.0"]);
153
+ expect(tap.read("main", "Formula/other.rb")).toBe("other\n");
154
+ expect(tap.read("main", "Formula/arugula.rb")).toContain('version "1.4.0"');
155
+ expect(tap.branches.has("chant-publish/arugula-1.4.0")).toBe(false);
156
+ });
157
+
158
+ test("refuses an asset that is not the release's, a placeholder it can't fill, a release with no version, and a missing token, before any request", async () => {
159
+ const tap = startFakeGitHubRepo(API, "arugula-salad/homebrew-tap", "main", {});
160
+ const make = async (over: Record<string, unknown> = {}) => (await createPublishTargets([declaration(over)], { fetch: tap.fetch }))[0]!;
161
+ const artifacts: ReleaseArtifact[] = [{ component: "daemon", kind: "asset", path: "dist/arugula-linux-amd64.tar.gz", digest: `sha256:${"0".repeat(64)}` }];
162
+ expect((await refused((await make()).plan(context(member(), { artifacts })))).code).toBe("publish-artifact-digest-mismatch");
163
+ expect((await refused((await make()).plan(context(member(TEMPLATE.replace("{{version}}", "{{revision}}")))))).code).toBe("publish-homebrew-template");
164
+ expect((await refused((await make()).plan(context(member(`url "{{url:arugula-windows.zip}}"`))))).message).toContain("no declared asset is named arugula-windows.zip");
165
+ expect((await refused((await make()).plan(context(member(), { label: null, releaseTag: null })))).code).toBe("publish-homebrew-no-version");
166
+ expect((await refused((await make({ tokenEnv: "TAP_PAT" })).plan(context(member())))).code).toBe("publish-credentials-missing");
167
+ expect(tap.calls).toEqual([]);
168
+ expect(() => declaration({ tap: "no-slash" })).toThrow();
169
+ expect(() => declaration({ token: "ghp_x" })).toThrow();
170
+ });
171
+
172
+ test("the version, URL and template helpers", () => {
173
+ expect(releaseVersion("v1.4.0")).toBe("1.4.0");
174
+ expect(releaseVersion("app-v2.0.0-rc.1")).toBe("2.0.0-rc.1");
175
+ expect(releaseVersion("latest")).toBeNull();
176
+ expect(fillUrl("https://x.test/{tag}/{name}?v={version}", { tag: "release/v1 0", label: "v1", version: "1", name: "a b.tgz" })).toBe("https://x.test/release/v1%200/a%20b.tgz?v=1");
177
+ expect(renderFormula('version "{{ version }}" # #{bin}', { version: "1.0", label: "v1.0", tag: "t" }, new Map())).toBe('version "1.0" # #{bin}');
178
+ });
179
+ });