@intentius/chant 0.124.99 → 0.124.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/bin/chant +3 -3
  2. package/dist/action-pins.d.ts +2 -0
  3. package/dist/action-pins.js +3 -0
  4. package/dist/ci-detect.d.ts +13 -0
  5. package/dist/ci-detect.js +12 -0
  6. package/dist/ci-system.d.ts +66 -0
  7. package/dist/ci-system.js +61 -0
  8. package/dist/cli/commands/carve-emit.js +2 -2
  9. package/dist/cli/commands/check-lexicon-plugin.d.ts +2 -2
  10. package/dist/cli/commands/check-lexicon-plugin.js +3 -3
  11. package/dist/cli/commands/check-lexicon.js +4 -4
  12. package/dist/cli/commands/init-lexicon/templates/project.d.ts +1 -1
  13. package/dist/cli/commands/init-lexicon/templates/project.js +4 -4
  14. package/dist/cli/commands/init.d.ts +13 -0
  15. package/dist/cli/commands/init.js +30 -2
  16. package/dist/cli/handlers/build.js +27 -0
  17. package/dist/cli/handlers/release-doctor.d.ts +12 -0
  18. package/dist/cli/handlers/release-doctor.js +118 -0
  19. package/dist/cli/handlers/release-init.d.ts +10 -0
  20. package/dist/cli/handlers/release-init.js +342 -0
  21. package/dist/cli/handlers/release.d.ts +50 -1
  22. package/dist/cli/handlers/release.js +688 -30
  23. package/dist/cli/handlers/run-generate.js +11 -0
  24. package/dist/cli/main.d.ts +2 -0
  25. package/dist/cli/main.js +45 -97
  26. package/dist/cli/parse-args.js +55 -0
  27. package/dist/cli/registry.d.ts +18 -0
  28. package/dist/cli/release-commands/artifacts.d.ts +3 -0
  29. package/dist/cli/release-commands/artifacts.js +14 -0
  30. package/dist/cli/release-commands/candidates.d.ts +3 -0
  31. package/dist/cli/release-commands/candidates.js +16 -0
  32. package/dist/cli/release-commands/changed.d.ts +3 -0
  33. package/dist/cli/release-commands/changed.js +14 -0
  34. package/dist/cli/release-commands/compose.d.ts +3 -0
  35. package/dist/cli/release-commands/compose.js +16 -0
  36. package/dist/cli/release-commands/cut.d.ts +3 -0
  37. package/dist/cli/release-commands/cut.js +49 -0
  38. package/dist/cli/release-commands/doctor.d.ts +3 -0
  39. package/dist/cli/release-commands/doctor.js +14 -0
  40. package/dist/cli/release-commands/export.d.ts +3 -0
  41. package/dist/cli/release-commands/export.js +12 -0
  42. package/dist/cli/release-commands/images.d.ts +3 -0
  43. package/dist/cli/release-commands/images.js +13 -0
  44. package/dist/cli/release-commands/index.d.ts +8 -0
  45. package/dist/cli/release-commands/index.js +52 -0
  46. package/dist/cli/release-commands/init.d.ts +3 -0
  47. package/dist/cli/release-commands/init.js +16 -0
  48. package/dist/cli/release-commands/list.d.ts +3 -0
  49. package/dist/cli/release-commands/list.js +10 -0
  50. package/dist/cli/release-commands/next.d.ts +3 -0
  51. package/dist/cli/release-commands/next.js +13 -0
  52. package/dist/cli/release-commands/publish.d.ts +3 -0
  53. package/dist/cli/release-commands/publish.js +22 -0
  54. package/dist/cli/release-commands/stamp.d.ts +3 -0
  55. package/dist/cli/release-commands/stamp.js +15 -0
  56. package/dist/cli/release-commands/status.d.ts +3 -0
  57. package/dist/cli/release-commands/status.js +17 -0
  58. package/dist/cli/release-commands/tag.d.ts +3 -0
  59. package/dist/cli/release-commands/tag.js +12 -0
  60. package/dist/cli/release-commands/types.d.ts +20 -0
  61. package/dist/cli/release-commands/types.js +1 -0
  62. package/dist/cli/release-commands/verify.d.ts +3 -0
  63. package/dist/cli/release-commands/verify.js +15 -0
  64. package/dist/cli/release-commands/workflow.d.ts +3 -0
  65. package/dist/cli/release-commands/workflow.js +13 -0
  66. package/dist/codegen/pinned-upgrade.js +1 -1
  67. package/dist/components/capability-plugin.d.ts +1 -1
  68. package/dist/components/capability-plugin.js +1 -1
  69. package/dist/components/cli-support.d.ts +1 -1
  70. package/dist/components/cli-support.js +1 -1
  71. package/dist/config-environments.d.ts +8 -1
  72. package/dist/config-environments.js +2 -0
  73. package/dist/config.d.ts +299 -6
  74. package/dist/config.js +102 -5
  75. package/dist/dead-guards.d.ts +5 -1
  76. package/dist/dead-guards.js +34 -23
  77. package/dist/discovery/sandbox/driver.js +1 -1
  78. package/dist/discovery/specifier-resolve.js +1 -1
  79. package/dist/floor-table.d.ts +3 -1
  80. package/dist/floor-table.data.js +23 -3
  81. package/dist/floor-table.js +4 -3
  82. package/dist/forge-remote.d.ts +13 -0
  83. package/dist/forge-remote.js +15 -0
  84. package/dist/lexicon.d.ts +41 -2
  85. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +62 -0
  86. package/dist/lifecycle/__fixtures__/publish-fakes.js +270 -3
  87. package/dist/lifecycle/publish-attachments.d.ts +2 -1
  88. package/dist/lifecycle/publish-attachments.js +19 -2
  89. package/dist/lifecycle/publish-cargo.d.ts +99 -0
  90. package/dist/lifecycle/publish-cargo.js +412 -0
  91. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  92. package/dist/lifecycle/publish-credentials.js +8 -0
  93. package/dist/lifecycle/publish-declaration.d.ts +199 -4
  94. package/dist/lifecycle/publish-declaration.js +200 -9
  95. package/dist/lifecycle/publish-forge.d.ts +45 -2
  96. package/dist/lifecycle/publish-forge.js +434 -34
  97. package/dist/lifecycle/publish-git-ssh.d.ts +15 -0
  98. package/dist/lifecycle/publish-git-ssh.js +30 -4
  99. package/dist/lifecycle/publish-github.d.ts +40 -2
  100. package/dist/lifecycle/publish-github.js +100 -3
  101. package/dist/lifecycle/publish-homebrew.d.ts +7 -9
  102. package/dist/lifecycle/publish-homebrew.js +34 -197
  103. package/dist/lifecycle/publish-index.d.ts +141 -0
  104. package/dist/lifecycle/publish-index.js +719 -0
  105. package/dist/lifecycle/publish-marketplace.js +77 -0
  106. package/dist/lifecycle/publish-mcp-registry.d.ts +66 -0
  107. package/dist/lifecycle/publish-mcp-registry.js +306 -0
  108. package/dist/lifecycle/publish-npm.js +165 -2
  109. package/dist/lifecycle/publish-oci.d.ts +34 -1
  110. package/dist/lifecycle/publish-oci.js +246 -7
  111. package/dist/lifecycle/publish-pypi.d.ts +136 -0
  112. package/dist/lifecycle/publish-pypi.js +657 -0
  113. package/dist/lifecycle/publish-record.d.ts +6 -3
  114. package/dist/lifecycle/publish-record.js +6 -3
  115. package/dist/lifecycle/publish-signing.d.ts +147 -0
  116. package/dist/lifecycle/publish-signing.js +257 -0
  117. package/dist/lifecycle/publish-targets.d.ts +27 -1
  118. package/dist/lifecycle/publish-targets.js +80 -0
  119. package/dist/lifecycle/publish-tauri.js +43 -0
  120. package/dist/lifecycle/publish-train-names.d.ts +54 -0
  121. package/dist/lifecycle/publish-train-names.js +118 -0
  122. package/dist/lifecycle/publish-verify.d.ts +121 -0
  123. package/dist/lifecycle/publish-verify.js +130 -0
  124. package/dist/lifecycle/query.js +8 -0
  125. package/dist/lifecycle/release-artifacts.d.ts +212 -0
  126. package/dist/lifecycle/release-artifacts.js +571 -0
  127. package/dist/lifecycle/release-changelog.d.ts +13 -1
  128. package/dist/lifecycle/release-changelog.js +35 -2
  129. package/dist/lifecycle/release-cut.d.ts +58 -3
  130. package/dist/lifecycle/release-cut.js +132 -34
  131. package/dist/lifecycle/release-doctor.d.ts +113 -0
  132. package/dist/lifecycle/release-doctor.js +996 -0
  133. package/dist/lifecycle/release-green.d.ts +86 -0
  134. package/dist/lifecycle/release-green.js +286 -0
  135. package/dist/lifecycle/release-init.d.ts +255 -0
  136. package/dist/lifecycle/release-init.js +859 -0
  137. package/dist/lifecycle/release-intents.d.ts +73 -0
  138. package/dist/lifecycle/release-intents.js +128 -0
  139. package/dist/lifecycle/release-next.d.ts +111 -0
  140. package/dist/lifecycle/release-next.js +252 -0
  141. package/dist/lifecycle/release-prerelease.d.ts +19 -0
  142. package/dist/lifecycle/release-prerelease.js +30 -0
  143. package/dist/lifecycle/release-publish.d.ts +256 -10
  144. package/dist/lifecycle/release-publish.js +246 -34
  145. package/dist/lifecycle/release-status-change.d.ts +226 -0
  146. package/dist/lifecycle/release-status-change.js +478 -0
  147. package/dist/lifecycle/release-status.d.ts +11 -0
  148. package/dist/lifecycle/release-status.js +1 -1
  149. package/dist/lifecycle/release-store.d.ts +73 -2
  150. package/dist/lifecycle/release-store.js +32 -1
  151. package/dist/lifecycle/release-tag.d.ts +142 -0
  152. package/dist/lifecycle/release-tag.js +323 -0
  153. package/dist/lifecycle/release-verify.d.ts +73 -1
  154. package/dist/lifecycle/release-verify.js +117 -2
  155. package/dist/lifecycle/release-version-formats.d.ts +73 -0
  156. package/dist/lifecycle/release-version-formats.js +570 -0
  157. package/dist/lifecycle/release-version.d.ts +58 -10
  158. package/dist/lifecycle/release-version.js +164 -36
  159. package/dist/lifecycle/release-workstation.d.ts +3 -2
  160. package/dist/lifecycle/release-workstation.js +3 -2
  161. package/dist/module-source.d.ts +2 -2
  162. package/dist/module-source.js +8 -8
  163. package/dist/op/generate-pipeline.js +1 -1
  164. package/dist/pr-forge-base.js +4 -2
  165. package/dist/pr-forge.d.ts +20 -2
  166. package/dist/pr-forge.js +46 -10
  167. package/dist/release-floors.d.ts +10 -1
  168. package/dist/release-floors.js +10 -1
  169. package/dist/tool-pins.d.ts +38 -0
  170. package/dist/tool-pins.js +54 -0
  171. package/dist/ts-loader.d.ts +1 -1
  172. package/dist/ts-loader.js +6 -6
  173. package/dist/wave-runtime.mjs +337 -334
  174. package/dist/workspace/ci-forge.d.ts +17 -0
  175. package/dist/workspace/ci-forge.js +17 -0
  176. package/dist/workspace/ci-init.js +1 -1
  177. package/dist/workspace/composites.schema.json +1 -0
  178. package/dist/workspace/declaration.d.ts +8 -0
  179. package/dist/workspace/declaration.js +12 -0
  180. package/dist/workspace/declaration.schema.json +8 -0
  181. package/dist/workspace/environments.d.ts +2 -0
  182. package/dist/workspace/environments.js +1 -1
  183. package/dist/workspace/identity-gate-rule.d.ts +61 -5
  184. package/dist/workspace/identity-gate-rule.js +81 -12
  185. package/dist/workspace/member-pipeline.d.ts +2 -1
  186. package/dist/workspace/member-pipeline.js +5 -2
  187. package/dist/workspace/reason-codes.d.ts +6 -0
  188. package/dist/workspace/reason-codes.js +8 -1
  189. package/dist/workspace/release-changed.d.ts +179 -0
  190. package/dist/workspace/release-changed.js +625 -0
  191. package/dist/workspace/release-changed.schema.json +206 -0
  192. package/dist/workspace/release-steps/artifacts.d.ts +7 -0
  193. package/dist/workspace/release-steps/artifacts.js +45 -0
  194. package/dist/workspace/release-steps/builds.d.ts +12 -0
  195. package/dist/workspace/release-steps/builds.js +38 -0
  196. package/dist/workspace/release-steps/doctor.d.ts +8 -0
  197. package/dist/workspace/release-steps/doctor.js +14 -0
  198. package/dist/workspace/release-steps/goreleaser.d.ts +16 -0
  199. package/dist/workspace/release-steps/goreleaser.js +36 -0
  200. package/dist/workspace/release-steps/green.d.ts +3 -0
  201. package/dist/workspace/release-steps/green.js +6 -0
  202. package/dist/workspace/release-steps/images.d.ts +22 -0
  203. package/dist/workspace/release-steps/images.js +59 -0
  204. package/dist/workspace/release-steps/index.d.ts +9 -0
  205. package/dist/workspace/release-steps/index.js +46 -0
  206. package/dist/workspace/release-steps/pypi.d.ts +15 -0
  207. package/dist/workspace/release-steps/pypi.js +21 -0
  208. package/dist/workspace/release-steps/qemu.d.ts +21 -0
  209. package/dist/workspace/release-steps/qemu.js +35 -0
  210. package/dist/workspace/release-steps/signing.d.ts +18 -0
  211. package/dist/workspace/release-steps/signing.js +30 -0
  212. package/dist/workspace/release-steps/stamp.d.ts +3 -0
  213. package/dist/workspace/release-steps/stamp.js +4 -0
  214. package/dist/workspace/release-steps/targets.d.ts +31 -0
  215. package/dist/workspace/release-steps/targets.js +40 -0
  216. package/dist/workspace/release-steps/types.d.ts +104 -0
  217. package/dist/workspace/release-steps/types.js +2 -0
  218. package/dist/workspace/release-steps/verify.d.ts +3 -0
  219. package/dist/workspace/release-steps/verify.js +4 -0
  220. package/dist/workspace/release-toolchains.d.ts +59 -0
  221. package/dist/workspace/release-toolchains.js +133 -0
  222. package/dist/workspace/release-train-workflow.d.ts +29 -0
  223. package/dist/workspace/release-train-workflow.js +85 -0
  224. package/dist/workspace/release-train.d.ts +3 -1
  225. package/dist/workspace/release-train.js +20 -3
  226. package/dist/workspace/release-workflow.d.ts +160 -61
  227. package/dist/workspace/release-workflow.js +539 -193
  228. package/dist/workspace/releases.schema.json +70 -1
  229. package/dist/workspace/search-contract.d.ts +1 -1
  230. package/dist/workspace/security.js +9 -2
  231. package/dist/workspace/train-cut.d.ts +182 -0
  232. package/dist/workspace/train-cut.js +482 -0
  233. package/dist/workspace/train-prepare.d.ts +61 -0
  234. package/dist/workspace/train-prepare.js +267 -0
  235. package/dist/workspace/train-publish.d.ts +177 -0
  236. package/dist/workspace/train-publish.js +575 -0
  237. package/dist/workspace/train-range-labels.d.ts +33 -0
  238. package/dist/workspace/train-range-labels.js +109 -0
  239. package/dist/workspace/trust/seal.d.ts +13 -3
  240. package/dist/workspace/trust/seal.js +14 -4
  241. package/dist/workspace/work-cli.d.ts +3 -2
  242. package/dist/workspace/work-cli.js +3 -2
  243. package/dist/workspace/workspace-ledger.d.ts +14 -1
  244. package/dist/workspace/workspace-ledger.js +33 -7
  245. package/package.json +26 -26
@@ -0,0 +1,412 @@
1
+ /**
2
+ * The cargo target (#5167): Rust crates published to crates.io or another
3
+ * Cargo registry with `cargo publish`, one crate at a time, each after the
4
+ * workspace crates it depends on.
5
+ *
6
+ * The crates and their versions come from `cargo metadata --no-deps` on the
7
+ * declared manifest: the ones `crates` names, else every workspace member
8
+ * whose `publish` allows the registry. The version published is the one in
9
+ * each `Cargo.toml`, which `release.version` can stamp with the release's
10
+ * label. A crate's dependency on another workspace crate needs a version
11
+ * beside its path, or cargo refuses to publish it, so the plan refuses it
12
+ * first (`publish-cargo-dependency-version`).
13
+ *
14
+ * A registry has no draft: a crate version is visible as soon as it is
15
+ * published, and a version can never be published twice. So the stage
16
+ * publishes nothing. It reads the registry's sparse index for each crate,
17
+ * and a version already there is `present`. The reveal reads the index
18
+ * again before each crate, so a reveal run again after a failure part way
19
+ * publishes only the crates that are not there yet, and then runs
20
+ *
21
+ * cargo publish -p <crate> --manifest-path <manifest> --no-verify --allow-dirty [--registry <name>]
22
+ *
23
+ * in dependency order. `--no-verify` because a publish never builds: the
24
+ * build belongs to the cut. `--allow-dirty` because the checkout carries the
25
+ * stamped versions, which the publish's own checkout check already allows.
26
+ * cargo waits until the registry's index serves each crate before it
27
+ * returns, so the next crate resolves it. Nothing is out between the stage
28
+ * and the reveal, so a check of what staged can't see this target.
29
+ *
30
+ * Credentials:
31
+ *
32
+ * - `auth: "token"`: a token from `tokenEnv` (default `CARGO_REGISTRY_TOKEN`,
33
+ * or `CARGO_REGISTRIES_<NAME>_TOKEN` with `registry`), handed to cargo in
34
+ * the variable it reads.
35
+ * - `auth: "trusted-publishing"`, crates.io only: the run's OIDC ID token
36
+ * (audience `crates.io`, from GitHub Actions or `CRATES_IO_ID_TOKEN`) is
37
+ * exchanged at `POST {api}/api/v1/trusted_publishing/tokens` for a token
38
+ * that lasts minutes, and revoked with a `DELETE` when the step ends. The
39
+ * stage exchanges and revokes one to check that crates.io takes this
40
+ * workflow as a trusted publisher.
41
+ *
42
+ * Unset, `auth` is a token when the token's variable is set, else trusted
43
+ * publishing when the run has an OIDC ID token.
44
+ *
45
+ * A status change (#5163): `chant release yank` runs `cargo yank --version
46
+ * <version> <crate>` for each crate the release published, and `restore`
47
+ * runs it with `--undo`. A yanked version stays downloadable for lockfiles
48
+ * that name it, and new resolutions skip it. A registry has no deprecation,
49
+ * so `deprecate` changes nothing. A yank needs a token, from the same
50
+ * variable as a publish, that may yank the crates.
51
+ *
52
+ * A registry keeps no file beside a crate, so nothing is attached. Under the
53
+ * `supply-chain` group the target is refused (`publish-sbom-missing`) unless
54
+ * `sbom` is `false`.
55
+ */
56
+ import { spawn } from "node:child_process";
57
+ import { resolve } from "node:path";
58
+ import { readCredential } from "./publish-credentials.js";
59
+ import { hasIdToken, memberFile, publishTargetKey, runIdToken } from "./publish-targets.js";
60
+ import { releaseVersion } from "./publish-index.js";
61
+ import { trainName, waitUntilServed } from "./publish-train-names.js";
62
+ import { PublishTargetError } from "./release-publish.js";
63
+ /** The first chant that publishes a `cargo` target (#5167). */
64
+ export const PUBLISH_CARGO_FLOOR = "0.124.101";
65
+ export const CRATES_IO_INDEX = "https://index.crates.io/";
66
+ export const CRATES_IO_API = "https://crates.io";
67
+ /** The variable an OIDC ID token for crates.io is read from outside GitHub Actions. */
68
+ export const CRATES_IO_ID_TOKEN_ENV = "CRATES_IO_ID_TOKEN";
69
+ /** The audience crates.io takes an OIDC ID token for. */
70
+ export const CRATES_IO_AUDIENCE = "crates.io";
71
+ /** The variable cargo reads a registry's token from. */
72
+ export function cargoRegistryTokenVar(registry) {
73
+ return registry ? `CARGO_REGISTRIES_${registry.toUpperCase().replace(/-/g, "_")}_TOKEN` : "CARGO_REGISTRY_TOKEN";
74
+ }
75
+ /** The variable the declaration's token is read from. */
76
+ export function cargoTokenEnv(decl) {
77
+ return decl.tokenEnv ?? cargoRegistryTokenVar(decl.registry);
78
+ }
79
+ /** How the target authenticates in `env`. */
80
+ export function cargoAuth(decl, env) {
81
+ if (decl.auth)
82
+ return decl.auth;
83
+ if (env[cargoTokenEnv(decl)])
84
+ return "token";
85
+ return decl.registry === undefined && hasIdToken(env, CRATES_IO_ID_TOKEN_ENV) ? "trusted-publishing" : "token";
86
+ }
87
+ /** A crate's file in a sparse index, by Cargo's layout. */
88
+ export function sparseIndexPath(name) {
89
+ const n = name.toLowerCase();
90
+ if (n.length <= 2)
91
+ return `${n.length}/${n}`;
92
+ if (n.length === 3)
93
+ return `3/${n[0]}/${n}`;
94
+ return `${n.slice(0, 2)}/${n.slice(2, 4)}/${n}`;
95
+ }
96
+ /**
97
+ * The crates to publish, each after the selected crates it depends on (ties
98
+ * in name order). A dev-dependency with no version is left out of the order,
99
+ * since cargo drops it from what it publishes.
100
+ */
101
+ export function cargoPublishOrder(all, decl) {
102
+ const registryName = decl.registry ?? "crates-io";
103
+ const byName = new Map(all.map((c) => [c.name, c]));
104
+ let chosen;
105
+ if (decl.crates) {
106
+ chosen = decl.crates.map((n) => {
107
+ const c = byName.get(n);
108
+ if (!c)
109
+ throw new PublishTargetError("publish-cargo-unknown-crate", `crates names ${n}, and the workspace has no such crate: it has ${[...byName.keys()].sort().join(", ") || "none"}`, "Name the crates by their package name in Cargo.toml.");
110
+ if (c.publish !== null && !c.publish.includes(registryName)) {
111
+ throw new PublishTargetError("publish-cargo-unpublishable", `${n}'s Cargo.toml has publish = ${JSON.stringify(c.publish)}, which leaves out ${registryName}`, `Take ${n} out of crates, or allow ${registryName} in its publish field.`);
112
+ }
113
+ return c;
114
+ });
115
+ }
116
+ else {
117
+ chosen = all.filter((c) => c.publish === null || c.publish.includes(registryName));
118
+ if (chosen.length === 0)
119
+ throw new PublishTargetError("publish-cargo-no-crates", `no crate of the workspace may be published to ${registryName}: each has publish = false or names other registries`);
120
+ }
121
+ const names = new Set(chosen.map((c) => c.name));
122
+ const workspace = new Set(all.map((c) => c.name));
123
+ for (const c of chosen) {
124
+ for (const d of c.dependencies) {
125
+ if (d.path !== undefined && workspace.has(d.name) && d.req === "*" && d.kind !== "dev") {
126
+ throw new PublishTargetError("publish-cargo-dependency-version", `${c.name} depends on ${d.name} by path with no version, and cargo publishes no crate whose dependency has none`, `Give the dependency a version beside its path, such as ${d.name} = { path = "...", version = "${byName.get(d.name)?.version ?? "x.y.z"}" }; release.version can stamp it with the label.`);
127
+ }
128
+ }
129
+ }
130
+ const needs = new Map(chosen.map((c) => [c.name, new Set(c.dependencies.filter((d) => d.path !== undefined && names.has(d.name) && d.name !== c.name && !(d.kind === "dev" && d.req === "*")).map((d) => d.name))]));
131
+ const out = [];
132
+ const left = new Set(names);
133
+ while (left.size > 0) {
134
+ const ready = [...left].filter((n) => [...needs.get(n)].every((d) => !left.has(d))).sort();
135
+ if (ready.length === 0)
136
+ throw new PublishTargetError("publish-cargo-cycle", `the crates ${[...left].sort().join(", ")} depend on each other, so none can be published first`, "Break the cycle: a dev-dependency with no version is not part of the order.");
137
+ for (const n of ready) {
138
+ out.push(byName.get(n));
139
+ left.delete(n);
140
+ }
141
+ }
142
+ return out;
143
+ }
144
+ function run(bin, args, cwd, env) {
145
+ return new Promise((done, reject) => {
146
+ let stdout = "";
147
+ let stderr = "";
148
+ const child = spawn(bin, args, { cwd, env, stdio: ["ignore", "pipe", "pipe"] });
149
+ child.stdout.on("data", (c) => (stdout += c.toString("utf-8")));
150
+ child.stderr.on("data", (c) => (stderr += c.toString("utf-8")));
151
+ child.on("error", reject);
152
+ child.on("close", (code) => done({ code: code ?? 1, stdout, stderr }));
153
+ });
154
+ }
155
+ /** The workspace's crates, from `cargo metadata --no-deps`. */
156
+ export async function cargoWorkspace(cargo, manifest, cwd, env, runner = run) {
157
+ const r = await runner(cargo, ["metadata", "--no-deps", "--format-version", "1", "--manifest-path", manifest], cwd, env).catch((err) => {
158
+ throw new PublishTargetError("publish-cargo-missing", `cargo could not be run: ${err instanceof Error ? err.message : String(err)}`, "Install a Rust toolchain on the job's PATH, such as with rustup.");
159
+ });
160
+ if (r.code === 127)
161
+ throw new PublishTargetError("publish-cargo-missing", `cargo could not be run: ${r.stderr.trim()}`, "Install a Rust toolchain on the job's PATH, such as with rustup.");
162
+ if (r.code !== 0)
163
+ throw new PublishTargetError("publish-cargo-metadata", `cargo metadata on ${manifest} exited ${r.code}: ${r.stderr.trim().split("\n").slice(-3).join(" ")}`);
164
+ const meta = JSON.parse(r.stdout);
165
+ return (meta.packages ?? []).map((p) => ({ name: p.name, version: p.version, publish: p.publish ?? null, dependencies: (p.dependencies ?? []).map((d) => ({ name: d.name, req: d.req, kind: d.kind ?? null, ...(d.path ? { path: d.path } : {}) })) }));
166
+ }
167
+ export function cargoTarget(decl, deps) {
168
+ const fetchImpl = deps.fetch ?? ((url, init) => fetch(url, init));
169
+ const cargo = deps.cargo ?? "cargo";
170
+ const label = decl.registry ? `Cargo registry ${decl.registry}` : "crates.io";
171
+ const index = (decl.index ?? CRATES_IO_INDEX).replace(/^sparse\+/, "").replace(/\/*$/, "/");
172
+ const api = (decl.api ?? CRATES_IO_API).replace(/\/+$/, "");
173
+ const tokenName = cargoTokenEnv(decl);
174
+ const cargoVar = cargoRegistryTokenVar(decl.registry);
175
+ const setup = async (ctx) => {
176
+ if (ctx.requireSbom && decl.sbom !== false) {
177
+ throw new PublishTargetError("publish-sbom-missing", `${label} keeps no file beside a crate, so the crates this target publishes carry no SBOM`, "Attach the SBOM to the release elsewhere, such as with a forge target, and set sbom: false on this target.");
178
+ }
179
+ const manifest = memberFile(ctx.cwd, decl.manifest ?? "Cargo.toml");
180
+ const crates = cargoPublishOrder(await cargoWorkspace(cargo, manifest, ctx.cwd, ctx.env), decl);
181
+ const auth = cargoAuth(decl, ctx.env);
182
+ let token = null;
183
+ if (auth === "token") {
184
+ const cred = readCredential(ctx.env, [tokenName], ctx.redactor);
185
+ if (!cred) {
186
+ throw new PublishTargetError("publish-credentials-missing", `the ${label} target reads its token from ${tokenName}, and it is not set${decl.registry ? "" : ", and this run has no OIDC ID token for trusted publishing"}`, decl.registry ? `Set ${tokenName} to a token of the registry.` : `Set ${tokenName} to a crates.io API token with the publish-update scope (publish-new for a new crate), or publish from a GitHub Actions job with id-token: write and a trusted publisher on each crate.`);
187
+ }
188
+ token = cred.value;
189
+ }
190
+ else if (!hasIdToken(ctx.env, CRATES_IO_ID_TOKEN_ENV)) {
191
+ throw new PublishTargetError("publish-credentials-missing", `the crates.io target publishes with trusted publishing, and this run has no OIDC ID token: not a GitHub Actions job with id-token: write, and ${CRATES_IO_ID_TOKEN_ENV} is not set`, "In GitHub Actions, give the job permissions: id-token: write.");
192
+ }
193
+ const items = crates.map((c) => ({ name: `${c.name}@${c.version}`, destination: decl.registry ? `${index}${sparseIndexPath(c.name)}` : `${CRATES_IO_API}/crates/${c.name}/${c.version}` }));
194
+ return { manifest, crates, auth, token, items };
195
+ };
196
+ /** The checksum the index records for the crate's version, null when it has no such version. */
197
+ const indexed = async (ctx, c, token) => (await indexEntry(ctx, c, token))?.cksum ?? null;
198
+ /** The index's line for the crate's version: its checksum and whether it is yanked; null when it has no such version. */
199
+ const indexEntry = async (ctx, c, token) => {
200
+ const url = `${index}${sparseIndexPath(c.name)}`;
201
+ const res = await fetchImpl(url, { method: "GET", headers: { "user-agent": "chant", ...(decl.registry && token ? { authorization: token } : {}) } });
202
+ const text = await res.text().catch(() => "");
203
+ if (res.status === 404 || res.status === 410)
204
+ return null;
205
+ if (res.status !== 200)
206
+ throw new PublishTargetError("publish-cargo-failed", ctx.redactor.redact(`reading ${url} on ${label} answered ${res.status}${text ? `: ${text.slice(0, 200)}` : ""}`));
207
+ for (const line of text.split("\n")) {
208
+ if (!line.trim())
209
+ continue;
210
+ try {
211
+ const v = JSON.parse(line);
212
+ if (v.vers === c.version)
213
+ return { cksum: typeof v.cksum === "string" ? v.cksum : "", yanked: v.yanked === true };
214
+ }
215
+ catch {
216
+ // A line that is not JSON names no version.
217
+ }
218
+ }
219
+ return null;
220
+ };
221
+ /** Trusted publishing: a crates.io token for this run, and how to revoke it. */
222
+ const exchange = async (ctx) => {
223
+ const jwt = await runIdToken(ctx, fetchImpl, CRATES_IO_AUDIENCE, CRATES_IO_ID_TOKEN_ENV, "publish-cargo-trusted-publishing");
224
+ const url = `${api}/api/v1/trusted_publishing/tokens`;
225
+ const res = await fetchImpl(url, { method: "POST", headers: { "user-agent": "chant", "content-type": "application/json", accept: "application/json" }, body: JSON.stringify({ jwt }) });
226
+ const text = await res.text().catch(() => "");
227
+ let body = {};
228
+ try {
229
+ body = JSON.parse(text);
230
+ }
231
+ catch {
232
+ // Reported by its status.
233
+ }
234
+ if (res.status < 200 || res.status > 299 || typeof body.token !== "string" || !body.token) {
235
+ const why = (body.errors ?? []).map((e) => (typeof e.detail === "string" ? e.detail : "")).filter(Boolean).join("; ");
236
+ throw new PublishTargetError("publish-cargo-trusted-publishing", ctx.redactor.redact(`crates.io gave no token for this run's OIDC ID token: it answered ${res.status}${why ? `: ${why}` : ""}`), "Add this repository and workflow as a trusted publisher in each crate's settings on crates.io. A crate's first version can't be published this way; publish it once with a token.");
237
+ }
238
+ const token = body.token;
239
+ ctx.redactor.add(token);
240
+ return {
241
+ token,
242
+ revoke: async () => {
243
+ const r = await fetchImpl(url, { method: "DELETE", headers: { "user-agent": "chant", authorization: `Bearer ${token}` } }).catch(() => null);
244
+ if (r && r.status >= 300)
245
+ ctx.log(`crates.io answered ${r.status} to revoking the trusted-publishing token; it expires on its own`);
246
+ },
247
+ };
248
+ };
249
+ const target = {
250
+ kind: "cargo",
251
+ name: decl.crates ? `${label} ${decl.crates.join(", ")}` : `${label} ${decl.manifest ?? "Cargo.toml"}`,
252
+ destination: label,
253
+ credentialEnv: [tokenName, CRATES_IO_ID_TOKEN_ENV],
254
+ key: publishTargetKey(decl),
255
+ uploadsAtReveal: true,
256
+ /** #5165: the crates it publishes, and every crate they depend on outside dev-dependencies, from `cargo metadata`. */
257
+ async names(ctx) {
258
+ const all = await cargoWorkspace(cargo, memberFile(ctx.cwd, decl.manifest ?? "Cargo.toml"), ctx.cwd, ctx.env);
259
+ const crates = cargoPublishOrder(all, decl);
260
+ const provides = crates.map((c) => trainName("cargo", c.name));
261
+ const needs = new Set(crates.flatMap((c) => c.dependencies.filter((d) => d.kind !== "dev").map((d) => trainName("cargo", d.name))));
262
+ return { provides, needs: [...needs].filter((n) => !provides.includes(n)) };
263
+ },
264
+ /**
265
+ * #5165: whether the index holds each crate at the release's version. A
266
+ * crate whose Cargo.toml here has another version, and that the index
267
+ * does not hold at the release's, can't say.
268
+ */
269
+ async published(ctx) {
270
+ const version = releaseVersion(ctx.label);
271
+ if (!version)
272
+ return null;
273
+ const crates = cargoPublishOrder(await cargoWorkspace(cargo, memberFile(ctx.cwd, decl.manifest ?? "Cargo.toml"), ctx.cwd, ctx.env), decl);
274
+ const token = readCredential(ctx.env, [tokenName], ctx.redactor)?.value ?? null;
275
+ for (const c of crates) {
276
+ if ((await indexEntry(ctx, { name: c.name, version }, token)) !== null)
277
+ continue;
278
+ return c.version === version ? false : null;
279
+ }
280
+ return true;
281
+ },
282
+ /** #5165: wait until the index serves each crate version the reveal published. */
283
+ async visible(ctx, published) {
284
+ const crates = published.items.map((i) => /^(.+)@([^@]+)$/.exec(i.name)).filter((m) => m !== null).map((m) => ({ name: m[1], version: m[2] }));
285
+ if (crates.length === 0)
286
+ return;
287
+ const token = readCredential(ctx.env, [tokenName], ctx.redactor)?.value ?? null;
288
+ await waitUntilServed(ctx, deps, {
289
+ what: label,
290
+ code: "publish-cargo-not-served",
291
+ check: async () => {
292
+ const missing = [];
293
+ for (const c of crates)
294
+ if ((await indexEntry(ctx, c, token)) === null)
295
+ missing.push(`${c.name}@${c.version}`);
296
+ return missing;
297
+ },
298
+ });
299
+ },
300
+ async plan(ctx) {
301
+ return (await setup(ctx)).items;
302
+ },
303
+ async stage(ctx) {
304
+ const { crates, auth, token, items } = await setup(ctx);
305
+ if (auth === "trusted-publishing") {
306
+ const t = await exchange(ctx);
307
+ await t.revoke();
308
+ ctx.log("crates.io takes this run as a trusted publisher; the reveal asks for a new token, since one lasts minutes");
309
+ }
310
+ else {
311
+ ctx.log(`using the token from ${tokenName}; ${label} has no read-only check of a token, so whether it may publish shows at the reveal`);
312
+ }
313
+ const out = [];
314
+ for (const [i, c] of crates.entries()) {
315
+ const cksum = await indexed(ctx, c, token);
316
+ out.push(cksum === null ? items[i] : { ...items[i], present: true, ...(cksum ? { digest: `sha256:${cksum}` } : {}) });
317
+ }
318
+ const waiting = out.filter((i) => !i.present).map((i) => i.name);
319
+ ctx.log(waiting.length === 0 ? `${label} already has every crate at its version` : `${waiting.join(", ")} ${waiting.length === 1 ? "is" : "are"} published at the reveal, in this order, since ${label} has no draft`);
320
+ const staged = { target: target.name, destination: target.destination, items: out, state: waiting.length === 0 ? { present: "true" } : {} };
321
+ return staged;
322
+ },
323
+ async reveal(ctx, staged) {
324
+ if (staged.state.present === "true")
325
+ return { target: target.name, destination: target.destination, items: staged.items.map((i) => ({ ...i, present: true })) };
326
+ const { manifest, crates, auth, token, items } = await setup(ctx);
327
+ let publishToken = token;
328
+ let revoke = null;
329
+ const done = [];
330
+ const out = [];
331
+ try {
332
+ for (const [i, c] of crates.entries()) {
333
+ // Read again before each crate: one an earlier reveal published is not published twice.
334
+ const before = await indexed(ctx, c, publishToken);
335
+ if (before !== null) {
336
+ out.push({ ...items[i], present: true, ...(before ? { digest: `sha256:${before}` } : {}) });
337
+ continue;
338
+ }
339
+ if (publishToken === null) {
340
+ const t = await exchange(ctx);
341
+ publishToken = t.token;
342
+ revoke = t.revoke;
343
+ }
344
+ const args = ["publish", "-p", c.name, "--manifest-path", resolve(manifest), "--no-verify", "--allow-dirty", ...(decl.registry ? ["--registry", decl.registry] : [])];
345
+ ctx.log(`running cargo ${args.join(" ")}`);
346
+ const r = await run(cargo, args, ctx.cwd, { ...ctx.env, [cargoVar]: publishToken }).catch((err) => {
347
+ throw new PublishTargetError("publish-cargo-missing", `cargo could not be run: ${err instanceof Error ? err.message : String(err)}`, "Install a Rust toolchain on the job's PATH.");
348
+ });
349
+ for (const l of `${r.stdout}\n${r.stderr}`.split("\n").filter((x) => x.trim()))
350
+ ctx.log(`cargo: ${ctx.redactor.redact(l)}`);
351
+ if (r.code !== 0) {
352
+ const tail = ctx.redactor.redact(r.stderr.trim().split("\n").slice(-3).join(" "));
353
+ throw new PublishTargetError("publish-cargo-failed", `cargo publish of ${c.name}@${c.version} exited ${r.code}${tail ? `: ${tail}` : ""}${done.length ? `. Published before it: ${done.join(", ")}; the same publish run again publishes only the rest` : ""}`);
354
+ }
355
+ done.push(`${c.name}@${c.version}`);
356
+ const after = await indexed(ctx, c, publishToken).catch(() => null);
357
+ out.push({ ...items[i], ...(after ? { digest: `sha256:${after}` } : {}) });
358
+ }
359
+ }
360
+ finally {
361
+ if (revoke)
362
+ await revoke();
363
+ }
364
+ return { target: target.name, destination: target.destination, items: out };
365
+ },
366
+ /**
367
+ * #5163: yank each crate version the release published, or undo the yank
368
+ * on a restore. A version the index already shows so is left.
369
+ */
370
+ async setStatus(ctx) {
371
+ if (ctx.status === "deprecated")
372
+ return [{ what: `${label} unchanged: a crate version has no deprecation; yank stops new resolutions picking it`, already: true }];
373
+ const undo = ctx.status === "active";
374
+ const crates = ctx.revealed
375
+ .filter((i) => i.attachment === undefined && !i.refused && i.name.lastIndexOf("@") > 0)
376
+ .map((i) => ({ name: i.name.slice(0, i.name.lastIndexOf("@")), version: i.name.slice(i.name.lastIndexOf("@") + 1) }));
377
+ const args = (c) => ["yank", "--version", c.version, ...(undo ? ["--undo"] : []), ...(decl.registry ? ["--registry", decl.registry] : []), c.name];
378
+ if (!ctx.apply)
379
+ return crates.map((c) => ({ what: `cargo ${args(c).join(" ")}` }));
380
+ const cred = readCredential(ctx.env, [tokenName], ctx.redactor);
381
+ if (!cred) {
382
+ throw new PublishTargetError("publish-credentials-missing", `the ${label} target reads its token from ${tokenName}, and it is not set`, `Set ${tokenName} to a token of ${label} that may yank the crates${decl.registry ? "" : " (on crates.io, one with the yank scope)"}.`);
383
+ }
384
+ const actions = [];
385
+ for (const c of crates) {
386
+ const what = `cargo ${args(c).join(" ")}`;
387
+ const now = await indexEntry(ctx, c, cred.value);
388
+ if (now === null) {
389
+ actions.push({ what: `${c.name}@${c.version} is not in the index of ${label}; nothing to ${undo ? "restore" : "yank"}`, already: true });
390
+ continue;
391
+ }
392
+ if (now.yanked === !undo) {
393
+ actions.push({ what: `${c.name}@${c.version} is ${undo ? "not yanked" : "yanked"} already`, already: true });
394
+ continue;
395
+ }
396
+ ctx.log(`running ${what}`);
397
+ const r = await run(cargo, args(c), ctx.cwd, { ...ctx.env, [cargoVar]: cred.value }).catch((err) => {
398
+ throw new PublishTargetError("publish-cargo-missing", `cargo could not be run: ${err instanceof Error ? err.message : String(err)}`, "Install a Rust toolchain on the PATH.");
399
+ });
400
+ for (const l of `${r.stdout}\n${r.stderr}`.split("\n").filter((x) => x.trim()))
401
+ ctx.log(`cargo: ${ctx.redactor.redact(l)}`);
402
+ if (r.code !== 0) {
403
+ const tail = ctx.redactor.redact(r.stderr.trim().split("\n").slice(-3).join(" "));
404
+ throw new PublishTargetError("release-status-cargo-failed", `${what} exited ${r.code}${tail ? `: ${tail}` : ""}`, `Yanking needs a token of ${label} that may yank ${c.name}.`);
405
+ }
406
+ actions.push({ what });
407
+ }
408
+ return actions;
409
+ },
410
+ };
411
+ return target;
412
+ }
@@ -15,7 +15,7 @@
15
15
  * (`_authToken=...`, `Authorization: Bearer ...`).
16
16
  */
17
17
  /** Environment variables that hold a token in CI or for a registry. Their values are masked in all publish output. */
18
- export declare const TOKEN_ENV_VARS: readonly ["NODE_AUTH_TOKEN", "NPM_TOKEN", "NPM_ID_TOKEN", "SIGSTORE_ID_TOKEN", "ACTIONS_ID_TOKEN_REQUEST_TOKEN", "ACTIONS_RUNTIME_TOKEN", "GITHUB_TOKEN", "GH_TOKEN", "GITLAB_TOKEN", "CI_JOB_TOKEN", "FORGEJO_TOKEN", "GITEA_TOKEN", "OCI_PASSWORD", "DOCKER_PASSWORD", "VSCE_PAT", "OVSX_PAT"];
18
+ export declare const TOKEN_ENV_VARS: readonly ["NODE_AUTH_TOKEN", "NPM_TOKEN", "NPM_ID_TOKEN", "SIGSTORE_ID_TOKEN", "ACTIONS_ID_TOKEN_REQUEST_TOKEN", "ACTIONS_RUNTIME_TOKEN", "GITHUB_TOKEN", "GH_TOKEN", "GITLAB_TOKEN", "CI_JOB_TOKEN", "FORGEJO_TOKEN", "GITEA_TOKEN", "OCI_PASSWORD", "DOCKER_PASSWORD", "VSCE_PAT", "OVSX_PAT", "PYPI_TOKEN", "TEST_PYPI_TOKEN", "TWINE_PASSWORD", "PYPI_ID_TOKEN", "CARGO_REGISTRY_TOKEN", "CRATES_IO_ID_TOKEN", "MCP_GITHUB_TOKEN", "MCP_REGISTRY_TOKEN"];
19
19
  /** What a masked value is replaced with. */
20
20
  export declare const REDACTED = "[redacted]";
21
21
  /** Masks credentials in text a publish prints. */
@@ -32,6 +32,14 @@ export const TOKEN_ENV_VARS = [
32
32
  "DOCKER_PASSWORD",
33
33
  "VSCE_PAT",
34
34
  "OVSX_PAT",
35
+ "PYPI_TOKEN",
36
+ "TEST_PYPI_TOKEN",
37
+ "TWINE_PASSWORD",
38
+ "PYPI_ID_TOKEN",
39
+ "CARGO_REGISTRY_TOKEN",
40
+ "CRATES_IO_ID_TOKEN",
41
+ "MCP_GITHUB_TOKEN",
42
+ "MCP_REGISTRY_TOKEN",
35
43
  ];
36
44
  /** What a masked value is replaced with. */
37
45
  export const REDACTED = "[redacted]";