@intentius/chant 0.124.101 → 0.124.103

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 (109) hide show
  1. package/dist/ci-evidence-claims.d.ts +12 -0
  2. package/dist/ci-evidence-claims.js +12 -0
  3. package/dist/cli/commands/onboard.js +8 -8
  4. package/dist/cli/handlers/release-init.js +53 -19
  5. package/dist/cli/handlers/release.d.ts +1 -1
  6. package/dist/cli/handlers/release.js +12 -9
  7. package/dist/cli/main.js +13 -2
  8. package/dist/cli/parse-args.js +5 -0
  9. package/dist/cli/registry.d.ts +2 -0
  10. package/dist/cli/release-commands/cut.js +4 -3
  11. package/dist/cli/release-commands/init.js +4 -1
  12. package/dist/cli/release-commands/workflow.js +4 -2
  13. package/dist/cloud-lister/index.d.ts +4 -1
  14. package/dist/cloud-lister/index.js +2 -1
  15. package/dist/cloud-lister/kubernetes-components.d.ts +56 -0
  16. package/dist/cloud-lister/kubernetes-components.js +641 -0
  17. package/dist/cloud-lister/kubernetes.d.ts +18 -0
  18. package/dist/cloud-lister/kubernetes.js +26 -1
  19. package/dist/cloud-lister/mask.d.ts +5 -1
  20. package/dist/cloud-lister/mask.js +14 -5
  21. package/dist/config-import.d.ts +1 -1
  22. package/dist/config-import.js +6 -2
  23. package/dist/config-sandbox.d.ts +1 -1
  24. package/dist/config-sandbox.js +3 -3
  25. package/dist/config.d.ts +75 -1
  26. package/dist/config.js +27 -2
  27. package/dist/deep-observation.js +9 -3
  28. package/dist/floor-table.data.js +13 -6
  29. package/dist/lexicon.d.ts +4 -2
  30. package/dist/lifecycle/__fixtures__/package-files.d.ts +32 -0
  31. package/dist/lifecycle/__fixtures__/package-files.js +72 -0
  32. package/dist/lifecycle/__fixtures__/publish-fakes.js +5 -0
  33. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  34. package/dist/lifecycle/publish-credentials.js +5 -0
  35. package/dist/lifecycle/publish-declaration.d.ts +123 -0
  36. package/dist/lifecycle/publish-declaration.js +141 -2
  37. package/dist/lifecycle/publish-helm.d.ts +83 -0
  38. package/dist/lifecycle/publish-helm.js +451 -0
  39. package/dist/lifecycle/publish-maven.d.ts +79 -0
  40. package/dist/lifecycle/publish-maven.js +363 -0
  41. package/dist/lifecycle/publish-mcp-registry.js +1 -2
  42. package/dist/lifecycle/publish-npm.d.ts +27 -1
  43. package/dist/lifecycle/publish-npm.js +52 -2
  44. package/dist/lifecycle/publish-nuget.d.ts +93 -0
  45. package/dist/lifecycle/publish-nuget.js +376 -0
  46. package/dist/lifecycle/publish-oci.d.ts +57 -1
  47. package/dist/lifecycle/publish-oci.js +1 -1
  48. package/dist/lifecycle/publish-package-files.d.ts +16 -0
  49. package/dist/lifecycle/publish-package-files.js +39 -0
  50. package/dist/lifecycle/publish-pypi.d.ts +2 -0
  51. package/dist/lifecycle/publish-pypi.js +1 -1
  52. package/dist/lifecycle/publish-rubygems.d.ts +84 -0
  53. package/dist/lifecycle/publish-rubygems.js +365 -0
  54. package/dist/lifecycle/publish-targets.d.ts +10 -0
  55. package/dist/lifecycle/publish-targets.js +22 -0
  56. package/dist/lifecycle/publish-train-names.d.ts +4 -1
  57. package/dist/lifecycle/publish-train-names.js +5 -0
  58. package/dist/lifecycle/release-artifacts.d.ts +80 -2
  59. package/dist/lifecycle/release-artifacts.js +241 -5
  60. package/dist/lifecycle/release-cut.d.ts +6 -1
  61. package/dist/lifecycle/release-cut.js +15 -0
  62. package/dist/lifecycle/release-doctor.js +208 -6
  63. package/dist/lifecycle/release-init-registries.d.ts +48 -0
  64. package/dist/lifecycle/release-init-registries.js +97 -0
  65. package/dist/lifecycle/release-init.d.ts +22 -2
  66. package/dist/lifecycle/release-init.js +139 -13
  67. package/dist/lifecycle/release-next.js +1 -2
  68. package/dist/lifecycle/release-publish.d.ts +1 -1
  69. package/dist/lifecycle/release-publish.js +1 -1
  70. package/dist/lifecycle/release-tag.js +1 -2
  71. package/dist/op/local-executor.d.ts +1 -1
  72. package/dist/op/local-executor.js +2 -2
  73. package/dist/op/op-waves-evidence.js +9 -2
  74. package/dist/release-floors.d.ts +1 -1
  75. package/dist/release-floors.js +1 -1
  76. package/dist/sensitive-key.d.ts +12 -0
  77. package/dist/sensitive-key.js +52 -0
  78. package/dist/tool-pins.d.ts +2 -0
  79. package/dist/tool-pins.js +12 -0
  80. package/dist/ts-loader.d.ts +8 -0
  81. package/dist/ts-loader.js +19 -0
  82. package/dist/wave-runtime.mjs +325 -325
  83. package/dist/workspace/lexicon-outputs.d.ts +1 -1
  84. package/dist/workspace/lexicon-outputs.js +1 -1
  85. package/dist/workspace/release-steps/index.js +4 -0
  86. package/dist/workspace/release-steps/nfpm.d.ts +13 -0
  87. package/dist/workspace/release-steps/nfpm.js +29 -0
  88. package/dist/workspace/release-steps/nuget.d.ts +14 -0
  89. package/dist/workspace/release-steps/nuget.js +16 -0
  90. package/dist/workspace/release-steps/targets.d.ts +2 -2
  91. package/dist/workspace/release-steps/targets.js +3 -3
  92. package/dist/workspace/release-train-workflow.d.ts +27 -2
  93. package/dist/workspace/release-train-workflow.js +171 -14
  94. package/dist/workspace/release-train.js +5 -1
  95. package/dist/workspace/release-workflow.d.ts +39 -3
  96. package/dist/workspace/release-workflow.js +80 -24
  97. package/dist/workspace/train-artifacts.d.ts +107 -0
  98. package/dist/workspace/train-artifacts.js +239 -0
  99. package/dist/workspace/train-cut.d.ts +14 -2
  100. package/dist/workspace/train-cut.js +49 -7
  101. package/dist/workspace/train-prepare.d.ts +6 -3
  102. package/dist/workspace/train-prepare.js +54 -8
  103. package/dist/workspace/train-publish.d.ts +9 -0
  104. package/dist/workspace/train-publish.js +29 -4
  105. package/dist/workspace/train-shell.d.ts +5 -0
  106. package/dist/workspace/train-shell.js +17 -0
  107. package/dist/workspace/trust/check-evidence-report.d.ts +3 -7
  108. package/dist/workspace/trust/check-evidence-report.js +3 -7
  109. package/package.json +1 -1
@@ -0,0 +1,363 @@
1
+ /**
2
+ * The Maven Central target (#5232): a bundle of Maven components uploaded to
3
+ * the Central Portal (`POST /api/v1/publisher/upload`).
4
+ *
5
+ * The bundle is a `.zip` in Maven repository layout
6
+ * (`<group path>/<artifactId>/<version>/<artifactId>-<version>.pom` and the
7
+ * files beside it), a directory in that layout, which chant zips, or
8
+ * `artifact:<name>` for the one `.zip` the release records for that entry. A
9
+ * directory gets a `.md5` and `.sha1` for each file that has none, as Central
10
+ * asks; chant signs nothing, so each file needs its `.asc` beside it, from the
11
+ * build (`publish-maven-unsigned`). A file the release records must match its
12
+ * digest.
13
+ *
14
+ * The Portal holds a deployment it has validated until someone publishes it,
15
+ * so this target stages for real. The stage reads the repository
16
+ * (`https://repo1.maven.org/maven2/`) for each component's `.pom`: a
17
+ * component it serves with the same bytes is `present`, one with other
18
+ * bytes, or a bundle only part of which is there, is refused
19
+ * (`publish-maven-version-exists`). It then uploads the bundle with
20
+ * `publishingType=USER_MANAGED` and waits until the Portal says `VALIDATED`;
21
+ * `FAILED` is refused with the Portal's errors (`publish-maven-invalid`), and
22
+ * the deployment is left in the Portal for a person to read. The deployment's
23
+ * id goes in the publish record's state. The reveal publishes that deployment
24
+ * (`POST /api/v1/publisher/deployment/<id>`); one the Portal already
25
+ * publishes is not sent again.
26
+ *
27
+ * Credentials: a Central Portal user token, its name from `usernameEnv`
28
+ * (default `MAVEN_CENTRAL_USERNAME`) and its password from `passwordEnv`
29
+ * (default `MAVEN_CENTRAL_PASSWORD`), sent as `Authorization: Bearer
30
+ * <base64 of name:password>`. The Portal has no trusted publishing.
31
+ *
32
+ * Maven Central keeps every version it publishes and has no deprecation, so
33
+ * the target has no status change, and `chant release yank` refuses it.
34
+ *
35
+ * Under the `supply-chain` group a component with no SBOM in it (a file
36
+ * ending `-cyclonedx.json`, `-cyclonedx.xml` or `-spdx.json`, as the
37
+ * CycloneDX and SPDX Maven plugins attach one) is refused unless `sbom` is
38
+ * `false`.
39
+ */
40
+ import { createHash, randomBytes } from "node:crypto";
41
+ import { readdirSync, readFileSync, statSync } from "node:fs";
42
+ import { join, relative } from "node:path";
43
+ import { readCredential } from "./publish-credentials.js";
44
+ import { releaseVersion } from "./publish-index.js";
45
+ import { zipEntry, zipEntryNames } from "./publish-pypi.js";
46
+ import { bytesDigest, checkReleaseDigest, expandArtifactAssets, memberFile, publishTargetKey } from "./publish-targets.js";
47
+ import { trainName, waitUntilServed } from "./publish-train-names.js";
48
+ import { zipArchive } from "./release-artifacts.js";
49
+ import { PublishTargetError } from "./release-publish.js";
50
+ /** The first chant that publishes a `maven` target (#5232). */
51
+ export const PUBLISH_MAVEN_FLOOR = "0.124.102";
52
+ export const CENTRAL_PORTAL = "https://central.sonatype.com";
53
+ export const MAVEN_CENTRAL_REPOSITORY = "https://repo1.maven.org/maven2/";
54
+ /** How often the stage asks the Portal whether it has validated the bundle. */
55
+ export const MAVEN_STATUS_POLL_MS = 10000;
56
+ /** How long the stage waits for the Portal to validate the bundle. */
57
+ export const MAVEN_VALIDATION_WAIT_MS = 30 * 60000;
58
+ /** How long a train waits for the repository to serve what the reveal published: Central takes up to half an hour. */
59
+ export const MAVEN_VISIBLE_WAIT_MS = 60 * 60000;
60
+ export const mavenUsernameEnv = (decl) => decl.usernameEnv ?? "MAVEN_CENTRAL_USERNAME";
61
+ export const mavenPasswordEnv = (decl) => decl.passwordEnv ?? "MAVEN_CENTRAL_PASSWORD";
62
+ const CHECKSUM = /\.(md5|sha1|sha256|sha512)$/;
63
+ /** The components of a bundle's files, keyed by path. */
64
+ export function mavenComponents(files) {
65
+ const out = [];
66
+ for (const [path, bytes] of [...files.entries()].sort(([a], [b]) => a.localeCompare(b))) {
67
+ const m = /^(.+)\/([^/]+)\/([^/]+)\/([^/]+)\.pom$/.exec(path);
68
+ if (!m || m[4] !== `${m[2]}-${m[3]}`)
69
+ continue;
70
+ const dir = `${m[1]}/${m[2]}/${m[3]}`;
71
+ const own = [...files.keys()].filter((f) => f.startsWith(`${dir}/`) && !f.slice(dir.length + 1).includes("/")).sort();
72
+ out.push({ groupId: m[1].split("/").join("."), artifactId: m[2], version: m[3], dir, pom: bytes, files: own, sbom: own.find((f) => /-(cyclonedx\.(json|xml)|spdx\.json)$/.test(f)) ?? null });
73
+ }
74
+ return out;
75
+ }
76
+ /** The `groupId:artifactId` of each dependency a `.pom` needs at compile or run time. */
77
+ export function pomDependencies(pom) {
78
+ const body = pom.replace(/<!--[\s\S]*?-->/g, "").replace(/<dependencyManagement>[\s\S]*?<\/dependencyManagement>/g, "").replace(/<build>[\s\S]*?<\/build>/g, "").replace(/<profiles>[\s\S]*?<\/profiles>/g, "");
79
+ const out = new Set();
80
+ for (const d of body.matchAll(/<dependency>([\s\S]*?)<\/dependency>/g)) {
81
+ const get = (tag) => new RegExp(`<${tag}>\\s*([^<]+?)\\s*</${tag}>`).exec(d[1])?.[1];
82
+ const scope = get("scope") ?? "compile";
83
+ if (scope === "test" || scope === "provided" || scope === "system" || get("optional") === "true")
84
+ continue;
85
+ const g = get("groupId");
86
+ const a = get("artifactId");
87
+ if (g && a && !g.includes("${"))
88
+ out.add(`${g}:${a}`);
89
+ }
90
+ return [...out];
91
+ }
92
+ const hex = (algo, bytes) => createHash(algo).update(bytes).digest("hex");
93
+ /** Every file under `abs`, by its path from `abs` with `/` between parts. */
94
+ function walk(abs, base = abs) {
95
+ return readdirSync(abs)
96
+ .sort()
97
+ .flatMap((n) => {
98
+ const p = join(abs, n);
99
+ return statSync(p).isDirectory() ? walk(p, base) : [relative(base, p).split("\\").join("/")];
100
+ });
101
+ }
102
+ /** The bundle a declaration names, read: the zip to upload and its components. */
103
+ export function readMavenBundle(ctx, bundle) {
104
+ const paths = expandArtifactAssets(ctx.release, [bundle]);
105
+ if (paths.length !== 1)
106
+ throw new PublishTargetError("publish-maven-bundle", `${bundle} is ${paths.length} files, and a maven target uploads one bundle`, "Have the build write one .zip, or name the directory in Maven repository layout.");
107
+ const path = paths[0];
108
+ const abs = memberFile(ctx.cwd, path);
109
+ const files = new Map();
110
+ let zip;
111
+ if (statSync(abs).isDirectory()) {
112
+ for (const f of walk(abs)) {
113
+ const bytes = readFileSync(join(abs, f));
114
+ checkReleaseDigest(ctx.release, "asset", ctx.cwd, join(path, f), [bytesDigest(new Uint8Array(bytes))]);
115
+ files.set(f, bytes);
116
+ }
117
+ for (const [f, bytes] of [...files.entries()]) {
118
+ if (CHECKSUM.test(f) || f.endsWith(".asc"))
119
+ continue;
120
+ if (!files.has(`${f}.md5`))
121
+ files.set(`${f}.md5`, Buffer.from(hex("md5", bytes)));
122
+ if (!files.has(`${f}.sha1`))
123
+ files.set(`${f}.sha1`, Buffer.from(hex("sha1", bytes)));
124
+ }
125
+ zip = zipArchive([...files.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([name, bytes]) => ({ name, bytes })), 315532800);
126
+ }
127
+ else {
128
+ zip = readFileSync(abs);
129
+ checkReleaseDigest(ctx.release, "asset", ctx.cwd, path, [bytesDigest(new Uint8Array(zip))]);
130
+ try {
131
+ for (const n of zipEntryNames(zip))
132
+ if (!n.endsWith("/"))
133
+ files.set(n, zipEntry(zip, n) ?? Buffer.alloc(0));
134
+ }
135
+ catch (err) {
136
+ throw new PublishTargetError("publish-maven-bundle", `${path} is not a zip chant can read: ${err instanceof Error ? err.message : String(err)}`, "Name a .zip in Maven repository layout, or the directory itself.");
137
+ }
138
+ }
139
+ const components = mavenComponents(files);
140
+ if (components.length === 0) {
141
+ throw new PublishTargetError("publish-maven-no-components", `${path} holds no component: no <group path>/<artifactId>/<version>/<artifactId>-<version>.pom`, "Point bundle at a Maven repository layout, such as the directory mvn deploy -DaltDeploymentRepository=local::file:./target/staging-deploy writes.");
142
+ }
143
+ for (const c of components) {
144
+ if (c.version.endsWith("-SNAPSHOT"))
145
+ throw new PublishTargetError("publish-maven-snapshot", `${c.groupId}:${c.artifactId}:${c.version} is a snapshot, and Maven Central publishes releases`, "Build the release's version, such as the release's label.");
146
+ const unsigned = c.files.filter((f) => !CHECKSUM.test(f) && !f.endsWith(".asc") && !files.has(`${f}.asc`));
147
+ if (unsigned.length > 0) {
148
+ throw new PublishTargetError("publish-maven-unsigned", `${unsigned.join(", ")} ${unsigned.length === 1 ? "has" : "have"} no .asc signature beside ${unsigned.length === 1 ? "it" : "them"}, and Maven Central takes only signed files`, "Sign the files with GPG in the build, such as with maven-gpg-plugin, and publish the key's public half to a keyserver.");
149
+ }
150
+ }
151
+ return { path, zip, digest: bytesDigest(new Uint8Array(zip)), files, components };
152
+ }
153
+ const coordinate = (c) => `${c.groupId}:${c.artifactId}@${c.version}`;
154
+ export function mavenTarget(decl, deps) {
155
+ const fetchImpl = deps.fetch ?? ((url, init) => fetch(url, init));
156
+ const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
157
+ const now = deps.now ?? Date.now;
158
+ const api = (decl.api ?? CENTRAL_PORTAL).replace(/\/+$/, "");
159
+ const repository = (decl.repository ?? MAVEN_CENTRAL_REPOSITORY).replace(/\/*$/, "/");
160
+ const userName = mavenUsernameEnv(decl);
161
+ const passName = mavenPasswordEnv(decl);
162
+ const label = decl.api ? new URL(api).host : "Maven Central";
163
+ const read = (ctx) => {
164
+ const b = readMavenBundle(ctx, decl.bundle);
165
+ if (ctx.requireSbom && decl.sbom !== false) {
166
+ const without = b.components.find((c) => c.sbom === null);
167
+ if (without) {
168
+ throw new PublishTargetError("publish-sbom-missing", `${without.groupId}:${without.artifactId}:${without.version} carries no SBOM: Maven Central keeps an SBOM as a file of the component, such as ${without.artifactId}-${without.version}-cyclonedx.json`, "Attach one in the build, such as with cyclonedx-maven-plugin, or set sbom: false to publish without one.");
169
+ }
170
+ }
171
+ return b;
172
+ };
173
+ const items = (cs) => cs.map((c) => ({ name: coordinate(c), destination: `${CENTRAL_PORTAL}/artifact/${c.groupId}/${c.artifactId}/${c.version}`, digest: bytesDigest(new Uint8Array(c.pom)), ...(c.sbom ? { sbom: c.sbom.split("/").pop() } : {}) }));
174
+ const authorization = (ctx) => {
175
+ const user = readCredential(ctx.env, [userName], ctx.redactor);
176
+ const pass = readCredential(ctx.env, [passName], ctx.redactor);
177
+ if (!user || !pass) {
178
+ throw new PublishTargetError("publish-credentials-missing", `the ${label} target reads a Central Portal user token from ${userName} and ${passName}, and ${[!user ? userName : null, !pass ? passName : null].filter(Boolean).join(" and ")} ${!user && !pass ? "are" : "is"} not set`, `Generate a user token at ${CENTRAL_PORTAL}/account and set ${userName} to its name and ${passName} to its password.`);
179
+ }
180
+ const bearer = Buffer.from(`${user.value}:${pass.value}`, "utf-8").toString("base64");
181
+ ctx.redactor.add(bearer);
182
+ return `Bearer ${bearer}`;
183
+ };
184
+ const fail = (ctx, code, what, status, text, fix) => {
185
+ throw new PublishTargetError(code, ctx.redactor.redact(`${what} on ${label} answered ${status}${text ? `: ${text.replace(/\s+/g, " ").slice(0, 300)}` : ""}`), fix);
186
+ };
187
+ const pomUrl = (c) => `${repository}${c.groupId.split(".").join("/")}/${c.artifactId}/${c.version}/${c.artifactId}-${c.version}.pom`;
188
+ /** The `.pom` the repository serves for a component, or null. */
189
+ const served = async (ctx, c) => {
190
+ const url = pomUrl(c);
191
+ const res = await fetchImpl(url, { method: "GET", headers: { "user-agent": "chant" } });
192
+ if (res.status === 404)
193
+ return null;
194
+ if (res.status !== 200)
195
+ fail(ctx, "publish-maven-failed", `reading ${url}`, res.status, await res.text().catch(() => ""));
196
+ return res.arrayBuffer ? Buffer.from(await res.arrayBuffer()) : Buffer.from(await res.text(), "utf-8");
197
+ };
198
+ /** True when every component is published with the same `.pom`; false when none is; refused otherwise. */
199
+ const published = async (ctx, cs) => {
200
+ const there = [];
201
+ for (const c of cs) {
202
+ const pom = await served(ctx, c);
203
+ if (pom === null)
204
+ continue;
205
+ if (!pom.equals(c.pom))
206
+ throw new PublishTargetError("publish-maven-version-exists", `${label} already has ${c.groupId}:${c.artifactId}:${c.version}, with another .pom`, "Maven Central never takes a version twice: cut a release with a new version.");
207
+ there.push(coordinate(c));
208
+ }
209
+ if (there.length === 0)
210
+ return false;
211
+ if (there.length === cs.length)
212
+ return true;
213
+ throw new PublishTargetError("publish-maven-version-exists", `${label} already has ${there.join(", ")}, and not ${cs.map(coordinate).filter((n) => !there.includes(n)).join(", ")}; a deployment that holds a published component fails validation`, "Leave the published components out of the bundle, or cut a release with a new version.");
214
+ };
215
+ /** The deployment's state and errors, or null when the Portal has no such deployment. */
216
+ const status = async (ctx, auth, id) => {
217
+ const url = `${api}/api/v1/publisher/status?id=${encodeURIComponent(id)}`;
218
+ const res = await fetchImpl(url, { method: "POST", headers: { "user-agent": "chant", accept: "application/json", authorization: auth } });
219
+ const text = await res.text().catch(() => "");
220
+ if (res.status === 404)
221
+ return null;
222
+ if (res.status !== 200)
223
+ fail(ctx, "publish-maven-failed", `reading deployment ${id}`, res.status, text);
224
+ try {
225
+ const body = JSON.parse(text);
226
+ return { state: typeof body.deploymentState === "string" ? body.deploymentState : "UNKNOWN", errors: body.errors === undefined ? "" : JSON.stringify(body.errors) };
227
+ }
228
+ catch {
229
+ return fail(ctx, "publish-maven-failed", `reading deployment ${id}`, res.status, "not JSON");
230
+ }
231
+ };
232
+ /** Wait until the Portal is done validating; refuses `FAILED` and a wait past the cap. */
233
+ const validated = async (ctx, auth, id) => {
234
+ const start = now();
235
+ let logged;
236
+ for (;;) {
237
+ const s = await status(ctx, auth, id);
238
+ if (s === null)
239
+ throw new PublishTargetError("publish-maven-deployment-missing", `${label} has no deployment ${id}: it was dropped`, "Cut a release with a new version, or upload the bundle in the Central Portal by hand.");
240
+ if (s.state === "FAILED") {
241
+ throw new PublishTargetError("publish-maven-invalid", ctx.redactor.redact(`${label} refused deployment ${id}${s.errors ? `: ${s.errors.slice(0, 600)}` : ""}`), `Fix the bundle and cut a new release. The deployment stays in the Central Portal at ${CENTRAL_PORTAL}/publishing/deployments, where it can be read and dropped.`);
242
+ }
243
+ if (s.state !== "PENDING" && s.state !== "VALIDATING")
244
+ return s.state;
245
+ if (now() - start >= MAVEN_VALIDATION_WAIT_MS) {
246
+ throw new PublishTargetError("publish-maven-validation-timeout", `${label} did not validate deployment ${id} within ${Math.round(MAVEN_VALIDATION_WAIT_MS / 60000)} minutes`, "Run the same publish again: it waits on the same deployment and uploads nothing twice.");
247
+ }
248
+ if (logged === undefined || now() - logged >= 60000) {
249
+ ctx.log(`waiting for ${label} to validate deployment ${id} (${s.state})`);
250
+ logged = now();
251
+ }
252
+ await sleep(MAVEN_STATUS_POLL_MS);
253
+ }
254
+ };
255
+ const target = {
256
+ kind: "maven",
257
+ name: `${label} ${decl.bundle}`,
258
+ destination: label,
259
+ credentialEnv: [userName, passName],
260
+ key: publishTargetKey(decl),
261
+ async names(ctx) {
262
+ const { components } = readMavenBundle(ctx, decl.bundle);
263
+ const provides = components.map((c) => trainName("maven", `${c.groupId}:${c.artifactId}`));
264
+ const needs = new Set(components.flatMap((c) => pomDependencies(c.pom.toString("utf-8")).map((d) => trainName("maven", d))));
265
+ return { provides, needs: [...needs].filter((n) => !provides.includes(n)) };
266
+ },
267
+ /** #5165: whether the repository serves each component's `.pom` at the release's version. */
268
+ async published(ctx) {
269
+ const version = releaseVersion(ctx.label);
270
+ if (!version)
271
+ return null;
272
+ let components;
273
+ try {
274
+ components = readMavenBundle(ctx, decl.bundle).components;
275
+ }
276
+ catch {
277
+ return null;
278
+ }
279
+ for (const c of components)
280
+ if ((await served(ctx, { ...c, version })) === null)
281
+ return false;
282
+ return true;
283
+ },
284
+ /** #5165: wait until the repository serves each component the reveal published. */
285
+ async visible(ctx, done) {
286
+ const cs = done.items.filter((i) => i.attachment === undefined && !i.refused).map((i) => /^([^:]+):([^@]+)@(.+)$/.exec(i.name)).filter((m) => m !== null).map((m) => ({ groupId: m[1], artifactId: m[2], version: m[3] }));
287
+ if (cs.length === 0)
288
+ return;
289
+ await waitUntilServed(ctx, deps, {
290
+ what: label,
291
+ code: "publish-maven-not-served",
292
+ capMs: MAVEN_VISIBLE_WAIT_MS,
293
+ check: async () => {
294
+ const missing = [];
295
+ for (const c of cs)
296
+ if ((await served(ctx, c)) === null)
297
+ missing.push(coordinate(c));
298
+ return missing;
299
+ },
300
+ });
301
+ },
302
+ async plan(ctx) {
303
+ const b = read(ctx);
304
+ authorization(ctx);
305
+ return items(b.components);
306
+ },
307
+ async stage(ctx) {
308
+ const b = read(ctx);
309
+ const auth = authorization(ctx);
310
+ if (await published(ctx, b.components)) {
311
+ ctx.log(`${label} already has every component with the same .pom`);
312
+ const staged = { target: target.name, destination: target.destination, items: items(b.components).map((i) => ({ ...i, present: true })), state: { present: "true" } };
313
+ return staged;
314
+ }
315
+ const boundary = `chant-${randomBytes(12).toString("hex")}`;
316
+ const name = `${b.components[0].groupId}:${b.components[0].artifactId}:${b.components[0].version}`;
317
+ const body = Buffer.concat([
318
+ Buffer.from(`--${boundary}\r\nContent-Disposition: form-data; name="bundle"; filename="bundle.zip"\r\nContent-Type: application/octet-stream\r\n\r\n`, "utf-8"),
319
+ b.zip,
320
+ Buffer.from(`\r\n--${boundary}--\r\n`, "utf-8"),
321
+ ]);
322
+ ctx.log(`uploading ${b.path} (${b.zip.byteLength} bytes, ${b.components.length} component${b.components.length === 1 ? "" : "s"}) to ${label}, held for the reveal to publish`);
323
+ const res = await fetchImpl(`${api}/api/v1/publisher/upload?publishingType=USER_MANAGED&name=${encodeURIComponent(name)}`, {
324
+ method: "POST",
325
+ headers: { "user-agent": "chant", "content-type": `multipart/form-data; boundary=${boundary}`, authorization: auth },
326
+ body: new Uint8Array(body),
327
+ });
328
+ const text = (await res.text().catch(() => "")).trim();
329
+ if (res.status !== 200 && res.status !== 201)
330
+ fail(ctx, "publish-maven-failed", "uploading the bundle", res.status, text, res.status === 401 || res.status === 403 ? `Check the user token in ${userName} and ${passName}, and that its account owns the namespace ${b.components[0].groupId}.` : undefined);
331
+ const id = text.replace(/^"|"$/g, "");
332
+ if (!id)
333
+ fail(ctx, "publish-maven-failed", "uploading the bundle", res.status, "no deployment id");
334
+ ctx.log(`${label} took the bundle as deployment ${id}`);
335
+ const state = await validated(ctx, auth, id);
336
+ ctx.log(`${label} validated deployment ${id} (${state}); the reveal publishes it`);
337
+ const staged = { target: target.name, destination: target.destination, items: items(b.components), state: { deployment: id } };
338
+ return staged;
339
+ },
340
+ async reveal(ctx, staged) {
341
+ if (staged.state.present === "true")
342
+ return { target: target.name, destination: target.destination, items: staged.items.map((i) => ({ ...i, present: true })) };
343
+ const id = staged.state.deployment;
344
+ if (!id)
345
+ throw new PublishTargetError("publish-maven-deployment-missing", "the stage recorded no deployment to publish", "Cut a release with a new version.");
346
+ const auth = authorization(ctx);
347
+ const state = await validated(ctx, auth, id);
348
+ if (state === "PUBLISHING" || state === "PUBLISHED") {
349
+ ctx.log(`${label} already publishes deployment ${id} (${state})`);
350
+ }
351
+ else {
352
+ ctx.log(`publishing deployment ${id} on ${label}`);
353
+ const res = await fetchImpl(`${api}/api/v1/publisher/deployment/${encodeURIComponent(id)}`, { method: "POST", headers: { "user-agent": "chant", authorization: auth } });
354
+ const text = await res.text().catch(() => "");
355
+ if (res.status < 200 || res.status > 299)
356
+ fail(ctx, "publish-maven-failed", `publishing deployment ${id}`, res.status, text);
357
+ ctx.log(`${label} is publishing deployment ${id}; the repository serves it within about half an hour`);
358
+ }
359
+ return { target: target.name, destination: target.destination, items: staged.items };
360
+ },
361
+ };
362
+ return target;
363
+ }
@@ -34,14 +34,13 @@
34
34
  * the file.
35
35
  */
36
36
  import { readFileSync } from "node:fs";
37
- import { NEXT_RELEASE } from "../release-floors.js";
38
37
  import { readCredential } from "./publish-credentials.js";
39
38
  import { releaseVersion } from "./publish-homebrew.js";
40
39
  import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets.js";
41
40
  import { trainName, waitUntilServed } from "./publish-train-names.js";
42
41
  import { PublishTargetError } from "./release-publish.js";
43
42
  /** The first chant with the `mcp-registry` publish target: a `server.json` published to the MCP Registry after the packages it names, with GitHub OIDC, and the `mcp-registry-*` checks of `chant release doctor` (#5162). */
44
- export const PUBLISH_MCP_REGISTRY_FLOOR = NEXT_RELEASE;
43
+ export const PUBLISH_MCP_REGISTRY_FLOOR = "0.124.101";
45
44
  export const MCP_REGISTRY = "https://registry.modelcontextprotocol.io";
46
45
  /** The variable a `github-token` target reads by default. */
47
46
  export const MCP_GITHUB_TOKEN_ENV = "MCP_GITHUB_TOKEN";
@@ -52,7 +52,7 @@
52
52
  * environment, and everything it prints is redacted before chant prints it.
53
53
  */
54
54
  import type { NpmPublishDeclaration } from "./publish-declaration.js";
55
- import { type PublishContext, type PublishDeps, type PublishTarget } from "./release-publish.js";
55
+ import { PublishTargetError, type PublishContext, type PublishDeps, type PublishTarget } from "./release-publish.js";
56
56
  export interface NpmPackage {
57
57
  path: string;
58
58
  abs: string;
@@ -106,4 +106,30 @@ export declare function checkDeclaredPackageImages(decls: ReadonlyArray<{
106
106
  type: string;
107
107
  packages?: readonly string[];
108
108
  }>, release: PublishContext["release"], cwd: string, bin?: string, env?: NodeJS.ProcessEnv): void;
109
+ /** Whether the registry has ever published the package. Throws a {@link PublishTargetError} when it can't say. */
110
+ export type NpmPublishedLookup = (name: string, registry: string | undefined) => boolean;
111
+ /** The default {@link NpmPublishedLookup}: `npm view <name> version`, with the registry the target declares. A 404 is "never published"; any other failure is the registry's error. */
112
+ export declare function npmPublishedLookup(bin?: string, env?: NodeJS.ProcessEnv): NpmPublishedLookup;
113
+ /** The packages the npm targets of `decls` publish, by name, with the registry each target declares. Directories without a readable, non-private package.json are left for the publish's plan to refuse. */
114
+ export declare function declaredNpmPackages(decls: ReadonlyArray<{
115
+ type: string;
116
+ packages?: readonly string[];
117
+ registry?: string;
118
+ }>, cwd: string): Array<{
119
+ name: string;
120
+ registry: string | undefined;
121
+ }>;
122
+ /** The refusal for packages the registry has never had: npm trusted publishing can't create a package. */
123
+ export declare function neverPublishedError(names: readonly string[]): PublishTargetError;
124
+ /**
125
+ * Refuses a cut whose npm targets name a package the registry has never
126
+ * published (#5230). Run by the cut before anything is recorded or tagged, and
127
+ * by the train cut before its first member. A registry that can't answer is a
128
+ * refusal too (`publish-npm-registry-unreadable`), not a pass.
129
+ */
130
+ export declare function checkPackagesPublished(decls: ReadonlyArray<{
131
+ type: string;
132
+ packages?: readonly string[];
133
+ registry?: string;
134
+ }>, cwd: string, lookup?: NpmPublishedLookup): void;
109
135
  export declare function npmTarget(decl: NpmPublishDeclaration, deps: PublishDeps): PublishTarget;
@@ -51,7 +51,7 @@
51
51
  * registry refuses the attestation on the token path. npm runs with the run's
52
52
  * environment, and everything it prints is redacted before chant prints it.
53
53
  */
54
- import { execFileSync, spawn } from "node:child_process";
54
+ import { execFileSync, spawn, spawnSync } from "node:child_process";
55
55
  import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
56
56
  import { tmpdir } from "node:os";
57
57
  import { join, relative, resolve, sep } from "node:path";
@@ -61,7 +61,7 @@ import { trainName } from "./publish-train-names.js";
61
61
  import { readPins, unknownPins } from "./release-images.js";
62
62
  import { NPM_STAGE_TAG, PublishTargetError, statusMessage } from "./release-publish.js";
63
63
  import { prereleaseOf } from "./release-prerelease.js";
64
- /** npm's output when a publish could not authenticate, as publish-packages.sh matches it. */
64
+ /** npm's output when a publish could not authenticate. */
65
65
  const NPM_AUTH_FAILED = /ENEEDAUTH|E401|need auth/;
66
66
  /** Read a package's name and version, from its directory or its packed `.tgz`, and find the SBOM it carries. */
67
67
  function readPackage(ctx, path, sbom) {
@@ -265,6 +265,56 @@ export function checkDeclaredPackageImages(decls, release, cwd, bin = "npm", env
265
265
  checkPackageImages(release, cwd, pkgs, bin, env);
266
266
  }
267
267
  }
268
+ /** The default {@link NpmPublishedLookup}: `npm view <name> version`, with the registry the target declares. A 404 is "never published"; any other failure is the registry's error. */
269
+ export function npmPublishedLookup(bin = "npm", env = process.env) {
270
+ return (name, registry) => {
271
+ const r = spawnSync(bin, ["view", name, "version", ...(registry ? ["--registry", registry] : [])], { encoding: "utf-8", env });
272
+ if (r.status === 0)
273
+ return true;
274
+ const out = `${r.stdout ?? ""}\n${r.stderr ?? ""}`;
275
+ if (/\bE404\b|\b404 Not Found\b/.test(out))
276
+ return false;
277
+ throw new PublishTargetError("publish-npm-registry-unreadable", `npm view ${name} exited ${r.status ?? "without a status"}, so whether ${name} has ever been published is unknown: ${(r.error?.message ?? out).trim().split("\n").filter(Boolean).at(-1) ?? "no output"}`, "Check that npm can reach the registry, and cut again.");
278
+ };
279
+ }
280
+ /** The packages the npm targets of `decls` publish, by name, with the registry each target declares. Directories without a readable, non-private package.json are left for the publish's plan to refuse. */
281
+ export function declaredNpmPackages(decls, cwd) {
282
+ const out = new Map();
283
+ for (const decl of decls) {
284
+ if (decl.type !== "npm")
285
+ continue;
286
+ for (const path of decl.packages ?? []) {
287
+ const abs = resolve(cwd, path);
288
+ if (!existsSync(abs) || !isDir(abs))
289
+ continue;
290
+ try {
291
+ const pkg = JSON.parse(readFileSync(join(abs, "package.json"), "utf-8"));
292
+ if (typeof pkg.name === "string" && pkg.private !== true && !out.has(`${decl.registry ?? ""}\n${pkg.name}`))
293
+ out.set(`${decl.registry ?? ""}\n${pkg.name}`, { name: pkg.name, registry: decl.registry });
294
+ }
295
+ catch {
296
+ // Not a package the plan can read.
297
+ }
298
+ }
299
+ }
300
+ return [...out.values()];
301
+ }
302
+ /** The refusal for packages the registry has never had: npm trusted publishing can't create a package. */
303
+ export function neverPublishedError(names) {
304
+ const list = names.join(", ");
305
+ return new PublishTargetError("publish-npm-never-published", `${list} ${names.length === 1 ? "has" : "have"} never been published to npm, and trusted publishing can't create a package, so its first publish would fail partway through the release`, `Publish one placeholder version of ${list} by hand (npm login, then npm publish), then add the trusted publisher on npmjs.com under the package's Settings, and cut again.`);
306
+ }
307
+ /**
308
+ * Refuses a cut whose npm targets name a package the registry has never
309
+ * published (#5230). Run by the cut before anything is recorded or tagged, and
310
+ * by the train cut before its first member. A registry that can't answer is a
311
+ * refusal too (`publish-npm-registry-unreadable`), not a pass.
312
+ */
313
+ export function checkPackagesPublished(decls, cwd, lookup = npmPublishedLookup()) {
314
+ const missing = declaredNpmPackages(decls, cwd).filter((p) => !lookup(p.name, p.registry)).map((p) => p.name);
315
+ if (missing.length > 0)
316
+ throw neverPublishedError(missing);
317
+ }
268
318
  export function npmTarget(decl, deps) {
269
319
  const bin = deps.npm ?? "npm";
270
320
  const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
@@ -0,0 +1,93 @@
1
+ /**
2
+ * The NuGet target (#5232): `.nupkg` files pushed to nuget.org, or to another
3
+ * feed that takes NuGet's push API (`PUT <pushUrl>`, a multipart body whose
4
+ * first part is the package, the key in `X-NuGet-ApiKey`).
5
+ *
6
+ * The packages are files, directories of them, or `artifact:<name>`. Each
7
+ * file the release records must match its digest. The id and version are
8
+ * read from the `.nuspec` at the package's root.
9
+ *
10
+ * A feed has no draft: a version is listed once it is pushed and validated,
11
+ * and an id and version can never be pushed again. So the stage pushes
12
+ * nothing. It checks the packages and the credential, and reads the feed's
13
+ * flat container (`<base>/<id>/index.json`) for the versions it already
14
+ * holds: such a version is `present`. nuget.org signs every package it takes
15
+ * with its repository signature, so the bytes it serves are never the bytes
16
+ * pushed and no digest is compared. The reveal reads the flat container
17
+ * again and pushes the rest; a push answered 409 (the version exists) is
18
+ * `present` too, since a version pushed moments ago is not in the flat
19
+ * container until nuget.org has validated it.
20
+ *
21
+ * Credentials:
22
+ *
23
+ * - `auth: "token"`: an API key from `tokenEnv` (default `NUGET_API_KEY`).
24
+ * - `auth: "trusted-publishing"`, nuget.org only: the run's OIDC ID token
25
+ * (audience `https://www.nuget.org`, from GitHub Actions or
26
+ * `NUGET_ID_TOKEN`, a GitLab job's `id_tokens`) is posted to
27
+ * `https://www.nuget.org/api/v2/token` with the user in `userEnv` (default
28
+ * `NUGET_USER`), the nuget.org profile whose trusted publishing policy
29
+ * names the workflow, for an API key that lasts an hour. nuget.org takes
30
+ * an ID token once, so the stage exchanges one only in GitHub Actions,
31
+ * which issues a new token each time it is asked; with `NUGET_ID_TOKEN`
32
+ * the reveal's exchange is the only one.
33
+ *
34
+ * Unset, `auth` is a token when the key's variable is set, else trusted
35
+ * publishing when the run has an OIDC ID token.
36
+ *
37
+ * A status change (#5163): `chant release yank` unlists each version the
38
+ * release pushed (`DELETE <pushUrl>/<id>/<version>`, which nuget.org reads as
39
+ * an unlist; the version stays restorable for anyone who names it), and
40
+ * `restore` lists it again (`POST`). NuGet's API has no deprecation, so
41
+ * `deprecate` changes nothing.
42
+ *
43
+ * Under the `supply-chain` group a package that carries no SBOM (an
44
+ * `.spdx.json`, `.cdx.json` or `.cyclonedx.json` file, or `_manifest/spdx_*`
45
+ * as Microsoft's sbom-tool writes it) is refused unless `sbom` is `false`.
46
+ */
47
+ import type { NugetPublishDeclaration } from "./publish-declaration.js";
48
+ import { type PublishDeps, type PublishTarget } from "./release-publish.js";
49
+ /** The first chant that publishes a `nuget` target (#5232). */
50
+ export declare const PUBLISH_NUGET_FLOOR = "0.124.102";
51
+ export declare const NUGET_ORG: {
52
+ readonly label: "nuget.org";
53
+ readonly site: "https://www.nuget.org";
54
+ readonly push: "https://www.nuget.org/api/v2/package";
55
+ readonly flat: "https://api.nuget.org/v3-flatcontainer/";
56
+ readonly token: "https://www.nuget.org/api/v2/token";
57
+ };
58
+ /** The audience nuget.org takes an OIDC ID token for. */
59
+ export declare const NUGET_AUDIENCE = "https://www.nuget.org";
60
+ /** The variable an OIDC ID token for nuget.org is read from outside GitHub Actions, as nuget.org's docs name it for GitLab. */
61
+ export declare const NUGET_ID_TOKEN_ENV = "NUGET_ID_TOKEN";
62
+ /** The feed a declaration pushes to. */
63
+ export declare function nugetFeed(decl: Pick<NugetPublishDeclaration, "pushUrl" | "flatContainerUrl">): {
64
+ label: string;
65
+ nugetOrg: boolean;
66
+ push: string;
67
+ flat: string;
68
+ };
69
+ export declare const nugetTokenEnv: (decl: Pick<NugetPublishDeclaration, "tokenEnv">) => string;
70
+ export declare const nugetUserEnv: (decl: Pick<NugetPublishDeclaration, "userEnv">) => string;
71
+ /** How the target authenticates in `env`. */
72
+ export declare function nugetAuth(decl: NugetPublishDeclaration, env: NodeJS.ProcessEnv): "token" | "trusted-publishing";
73
+ /**
74
+ * A NuGet version as the flat container lists it: lowercased, no build
75
+ * metadata, no leading zeros, and a fourth part of `0` left off.
76
+ */
77
+ export declare function normalizeNugetVersion(version: string): string;
78
+ /** One `.nupkg`, read. */
79
+ export interface NugetPackage {
80
+ path: string;
81
+ file: string;
82
+ bytes: Buffer;
83
+ digest: string;
84
+ id: string;
85
+ version: string;
86
+ /** The package ids its `.nuspec` depends on. */
87
+ dependencies: string[];
88
+ /** The SBOM entry it carries, if any. */
89
+ sbom: string | null;
90
+ }
91
+ /** Read one `.nupkg`: its `.nuspec`'s id, version and dependencies. */
92
+ export declare function readNupkg(path: string, abs: string): NugetPackage;
93
+ export declare function nugetTarget(decl: NugetPublishDeclaration, deps: PublishDeps): PublishTarget;