@intentius/chant 0.124.101 → 0.124.102

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 (101) 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/handlers/release-init.js +50 -18
  4. package/dist/cli/handlers/release.d.ts +1 -1
  5. package/dist/cli/handlers/release.js +12 -9
  6. package/dist/cli/release-commands/cut.js +4 -3
  7. package/dist/cli/release-commands/init.js +4 -1
  8. package/dist/cli/release-commands/workflow.js +4 -2
  9. package/dist/cloud-lister/index.d.ts +4 -1
  10. package/dist/cloud-lister/index.js +2 -1
  11. package/dist/cloud-lister/kubernetes-components.d.ts +56 -0
  12. package/dist/cloud-lister/kubernetes-components.js +642 -0
  13. package/dist/cloud-lister/kubernetes.d.ts +18 -0
  14. package/dist/cloud-lister/kubernetes.js +26 -1
  15. package/dist/cloud-lister/mask.d.ts +5 -1
  16. package/dist/cloud-lister/mask.js +14 -5
  17. package/dist/config-import.d.ts +1 -1
  18. package/dist/config-import.js +6 -2
  19. package/dist/config-sandbox.d.ts +1 -1
  20. package/dist/config-sandbox.js +3 -3
  21. package/dist/config.d.ts +75 -1
  22. package/dist/config.js +27 -2
  23. package/dist/deep-observation.js +9 -3
  24. package/dist/floor-table.data.js +12 -6
  25. package/dist/lexicon.d.ts +4 -2
  26. package/dist/lifecycle/__fixtures__/package-files.d.ts +32 -0
  27. package/dist/lifecycle/__fixtures__/package-files.js +72 -0
  28. package/dist/lifecycle/__fixtures__/publish-fakes.js +5 -0
  29. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  30. package/dist/lifecycle/publish-credentials.js +5 -0
  31. package/dist/lifecycle/publish-declaration.d.ts +123 -0
  32. package/dist/lifecycle/publish-declaration.js +140 -0
  33. package/dist/lifecycle/publish-helm.d.ts +83 -0
  34. package/dist/lifecycle/publish-helm.js +452 -0
  35. package/dist/lifecycle/publish-maven.d.ts +79 -0
  36. package/dist/lifecycle/publish-maven.js +364 -0
  37. package/dist/lifecycle/publish-mcp-registry.js +1 -2
  38. package/dist/lifecycle/publish-npm.d.ts +27 -1
  39. package/dist/lifecycle/publish-npm.js +51 -1
  40. package/dist/lifecycle/publish-nuget.d.ts +93 -0
  41. package/dist/lifecycle/publish-nuget.js +377 -0
  42. package/dist/lifecycle/publish-oci.d.ts +57 -1
  43. package/dist/lifecycle/publish-oci.js +1 -1
  44. package/dist/lifecycle/publish-package-files.d.ts +16 -0
  45. package/dist/lifecycle/publish-package-files.js +39 -0
  46. package/dist/lifecycle/publish-pypi.d.ts +2 -0
  47. package/dist/lifecycle/publish-pypi.js +1 -1
  48. package/dist/lifecycle/publish-rubygems.d.ts +84 -0
  49. package/dist/lifecycle/publish-rubygems.js +366 -0
  50. package/dist/lifecycle/publish-targets.d.ts +10 -0
  51. package/dist/lifecycle/publish-targets.js +22 -0
  52. package/dist/lifecycle/publish-train-names.d.ts +4 -1
  53. package/dist/lifecycle/publish-train-names.js +5 -0
  54. package/dist/lifecycle/release-artifacts.d.ts +80 -2
  55. package/dist/lifecycle/release-artifacts.js +242 -5
  56. package/dist/lifecycle/release-cut.d.ts +6 -1
  57. package/dist/lifecycle/release-cut.js +15 -0
  58. package/dist/lifecycle/release-doctor.js +208 -6
  59. package/dist/lifecycle/release-init-registries.d.ts +48 -0
  60. package/dist/lifecycle/release-init-registries.js +97 -0
  61. package/dist/lifecycle/release-init.d.ts +22 -2
  62. package/dist/lifecycle/release-init.js +132 -7
  63. package/dist/lifecycle/release-next.js +1 -2
  64. package/dist/lifecycle/release-publish.d.ts +1 -1
  65. package/dist/lifecycle/release-publish.js +1 -1
  66. package/dist/lifecycle/release-tag.js +1 -2
  67. package/dist/op/local-executor.d.ts +1 -1
  68. package/dist/op/local-executor.js +2 -2
  69. package/dist/op/op-waves-evidence.js +9 -2
  70. package/dist/release-floors.d.ts +1 -1
  71. package/dist/release-floors.js +1 -1
  72. package/dist/sensitive-key.d.ts +12 -0
  73. package/dist/sensitive-key.js +52 -0
  74. package/dist/tool-pins.d.ts +2 -0
  75. package/dist/tool-pins.js +12 -0
  76. package/dist/ts-loader.d.ts +8 -0
  77. package/dist/ts-loader.js +19 -0
  78. package/dist/wave-runtime.mjs +325 -325
  79. package/dist/workspace/lexicon-outputs.d.ts +1 -1
  80. package/dist/workspace/lexicon-outputs.js +1 -1
  81. package/dist/workspace/release-steps/index.js +4 -0
  82. package/dist/workspace/release-steps/nfpm.d.ts +13 -0
  83. package/dist/workspace/release-steps/nfpm.js +29 -0
  84. package/dist/workspace/release-steps/nuget.d.ts +14 -0
  85. package/dist/workspace/release-steps/nuget.js +16 -0
  86. package/dist/workspace/release-steps/targets.d.ts +2 -2
  87. package/dist/workspace/release-steps/targets.js +3 -3
  88. package/dist/workspace/release-train-workflow.d.ts +7 -0
  89. package/dist/workspace/release-train-workflow.js +46 -10
  90. package/dist/workspace/release-workflow.d.ts +28 -3
  91. package/dist/workspace/release-workflow.js +38 -15
  92. package/dist/workspace/train-cut.d.ts +2 -2
  93. package/dist/workspace/train-cut.js +27 -5
  94. package/dist/workspace/train-prepare.d.ts +6 -3
  95. package/dist/workspace/train-prepare.js +54 -8
  96. package/dist/workspace/train-publish.js +2 -3
  97. package/dist/workspace/train-shell.d.ts +5 -0
  98. package/dist/workspace/train-shell.js +17 -0
  99. package/dist/workspace/trust/check-evidence-report.d.ts +3 -7
  100. package/dist/workspace/trust/check-evidence-report.js +3 -7
  101. package/package.json +1 -1
@@ -0,0 +1,452 @@
1
+ /**
2
+ * The Helm target (#5233): chart archives pushed to an OCI registry, and
3
+ * listed in a classic chart repository's `index.yaml`.
4
+ *
5
+ * Each chart is a `.tgz` as `helm package` writes it, or as a `helm` entry of
6
+ * `release.artifacts` packs it (./release-artifacts.ts). Its name, version
7
+ * and the rest of its `Chart.yaml` are read from the archive, and a chart
8
+ * whose version is not the release's label from its first digit is refused
9
+ * (`publish-helm-version-mismatch`).
10
+ *
11
+ * `oci`: the chart goes to `<repository>/<chart name>` as `helm push` puts
12
+ * it: an image manifest whose config is the chart's metadata as JSON
13
+ * (`application/vnd.cncf.helm.config.v1+json`) and whose one layer is the
14
+ * archive (`application/vnd.cncf.helm.chart.content.v1.tar+gzip`). The
15
+ * registry is spoken to as the `oci` target speaks to it (./publish-oci.ts),
16
+ * with the same credentials. The stage pushes by digest; the reveal tags
17
+ * the digest with the chart's version (`+` written `_`, as helm does), which
18
+ * is what `helm install oci://<repository>/<name> --version <version>` reads.
19
+ *
20
+ * `index`: a chart repository served from a branch of a GitHub repository,
21
+ * such as `gh-pages`. The index's entry for each chart is its `Chart.yaml`
22
+ * with `urls`, `created` and `digest`, as `helm repo index` writes it. With
23
+ * `url`, each chart is downloaded from there, such as the forge release a
24
+ * `forge` target attaches it to; without it, the archive is committed
25
+ * beside the index and named by its file name. The stage commits to
26
+ * `chant-publish/helm-<version>` at the branch's head, and the reveal
27
+ * fast-forwards the branch, or commits onto it when it moved. The index is
28
+ * read and added to, never rewritten: a version it lists with the same
29
+ * digest is left, and one it lists with another is refused
30
+ * (`publish-helm-version-taken`), since a chart version is never replaced.
31
+ * With `index`, the target reveals after every other target, since the
32
+ * index points at files they make downloadable.
33
+ */
34
+ import { readFileSync } from "node:fs";
35
+ import { basename, posix } from "node:path";
36
+ import { gunzipSync } from "node:zlib";
37
+ import { readCredential } from "./publish-credentials.js";
38
+ import { GitHubRepo, githubApi } from "./publish-github.js";
39
+ import { fillUrl, releaseVersion } from "./publish-index.js";
40
+ import { Registry, ociCredential, parseRepository } from "./publish-oci.js";
41
+ import { bytesDigest, checkReleaseDigest, expandArtifactAssets, memberFile, publishTargetKey } from "./publish-targets.js";
42
+ import { trainName, waitUntilServed } from "./publish-train-names.js";
43
+ import { PublishTargetError } from "./release-publish.js";
44
+ import { NEXT_RELEASE } from "../release-floors.js";
45
+ import { emitYAML, parseYAML } from "../yaml.js";
46
+ /** The first chant that publishes a `helm` target (#5233). */
47
+ export const PUBLISH_HELM_FLOOR = NEXT_RELEASE;
48
+ /** The media type of a chart's config blob: its metadata as JSON. */
49
+ export const HELM_CONFIG_MEDIA_TYPE = "application/vnd.cncf.helm.config.v1+json";
50
+ /** The media type of a chart's archive layer. */
51
+ export const HELM_CHART_MEDIA_TYPE = "application/vnd.cncf.helm.chart.content.v1.tar+gzip";
52
+ const IMAGE_MANIFEST = "application/vnd.oci.image.manifest.v1+json";
53
+ /** The variable the index's token is read from when the declaration names none. */
54
+ export const HELM_INDEX_TOKEN_ENV = "GITHUB_TOKEN";
55
+ /**
56
+ * The `Chart.yaml` of a chart archive: the one file `<dir>/Chart.yaml` at the
57
+ * top of its gzipped tar. Reads ustar names, with a GNU long name or a PAX
58
+ * `path` in place of a short one. Null when the archive has none.
59
+ */
60
+ export function chartYamlOf(gz) {
61
+ let tar;
62
+ try {
63
+ tar = gunzipSync(gz);
64
+ }
65
+ catch {
66
+ return null;
67
+ }
68
+ let at = 0;
69
+ let longName = null;
70
+ const text = (b) => b.toString("utf-8").replace(/\0.*$/s, "");
71
+ while (at + 512 <= tar.length) {
72
+ const h = tar.subarray(at, at + 512);
73
+ if (h.every((b) => b === 0))
74
+ break;
75
+ const size = parseInt(text(h.subarray(124, 136)).trim() || "0", 8);
76
+ const type = String.fromCharCode(h[156]);
77
+ const prefix = text(h.subarray(345, 500));
78
+ const short = text(h.subarray(0, 100));
79
+ const body = tar.subarray(at + 512, at + 512 + size);
80
+ at += 512 + Math.ceil(size / 512) * 512;
81
+ if (type === "L") {
82
+ longName = text(body);
83
+ continue;
84
+ }
85
+ if (type === "x") {
86
+ const m = /(?:^|\n)\d+ path=([^\n]*)\n/.exec(body.toString("utf-8"));
87
+ if (m)
88
+ longName = m[1];
89
+ continue;
90
+ }
91
+ if (type === "g")
92
+ continue;
93
+ const name = (longName ?? (prefix ? `${prefix}/${short}` : short)).replace(/^\.\//, "");
94
+ longName = null;
95
+ if ((type === "0" || type === "\0") && /^[^/]+\/Chart\.yaml$/.test(name))
96
+ return body.toString("utf-8");
97
+ }
98
+ return null;
99
+ }
100
+ /** Read a chart archive's metadata, refused (`publish-helm-not-a-chart`) when it holds no readable `Chart.yaml` with a name and a version. */
101
+ export function readChartArchive(path, bytes) {
102
+ const yaml = chartYamlOf(bytes);
103
+ const refuse = (why) => {
104
+ throw new PublishTargetError("publish-helm-not-a-chart", `${path} is not a Helm chart archive: ${why}`, "Name the .tgz helm package writes, or a helm entry of release.artifacts with artifact:<name>.");
105
+ };
106
+ if (yaml === null)
107
+ refuse("it is not a gzipped tar with a <chart>/Chart.yaml");
108
+ let metadata = {};
109
+ try {
110
+ metadata = parseYAML(yaml);
111
+ }
112
+ catch (err) {
113
+ refuse(`its Chart.yaml is not YAML chant can read: ${err instanceof Error ? err.message : String(err)}`);
114
+ }
115
+ const name = metadata.name;
116
+ const version = metadata.version;
117
+ if (typeof name !== "string" || name === "")
118
+ refuse("its Chart.yaml has no name");
119
+ if (typeof version !== "string" || version === "")
120
+ refuse("its Chart.yaml has no version");
121
+ return { path, file: basename(path), bytes, digest: bytesDigest(bytes), name: name, version: version, metadata };
122
+ }
123
+ /** The OCI tag of a chart version: helm writes `+` as `_`, which a tag can't hold. */
124
+ export function helmOciTag(version) {
125
+ return version.replace(/\+/g, "_");
126
+ }
127
+ /** The config blob and the manifest `helm push` would make for a chart, with no time in them, so the same chart is the same digest. */
128
+ export function helmOciManifest(chart) {
129
+ const config = new Uint8Array(Buffer.from(JSON.stringify(chart.metadata)));
130
+ const annotations = { "org.opencontainers.image.title": chart.name, "org.opencontainers.image.version": chart.version };
131
+ if (typeof chart.metadata.description === "string" && chart.metadata.description !== "")
132
+ annotations["org.opencontainers.image.description"] = chart.metadata.description;
133
+ const manifest = new Uint8Array(Buffer.from(JSON.stringify({
134
+ schemaVersion: 2,
135
+ mediaType: IMAGE_MANIFEST,
136
+ config: { mediaType: HELM_CONFIG_MEDIA_TYPE, digest: bytesDigest(config), size: config.byteLength },
137
+ layers: [{ mediaType: HELM_CHART_MEDIA_TYPE, digest: chart.digest, size: chart.bytes.byteLength }],
138
+ annotations,
139
+ })));
140
+ return { config, manifest, digest: bytesDigest(manifest) };
141
+ }
142
+ /**
143
+ * The index with each chart's entry added, or null when it lists every chart
144
+ * already with the same digest. A version it lists with another digest is
145
+ * refused.
146
+ */
147
+ export function addToHelmIndex(existing, charts, created, where) {
148
+ let index;
149
+ if (existing === null || existing.trim() === "")
150
+ index = { apiVersion: "v1", entries: {} };
151
+ else {
152
+ try {
153
+ index = parseYAML(existing);
154
+ }
155
+ catch (err) {
156
+ throw new PublishTargetError("publish-helm-index-unreadable", `${where} is not YAML chant can read: ${err instanceof Error ? err.message : String(err)}`, "Fix the index by hand, or point index.path at the chart repository's index.yaml.");
157
+ }
158
+ if (typeof index !== "object" || index === null || (index.entries !== undefined && (typeof index.entries !== "object" || index.entries === null))) {
159
+ throw new PublishTargetError("publish-helm-index-unreadable", `${where} is not a chart repository index: it has no entries map`);
160
+ }
161
+ index.entries ?? (index.entries = {});
162
+ index.apiVersion ?? (index.apiVersion = "v1");
163
+ }
164
+ let changed = false;
165
+ for (const { chart, url } of charts) {
166
+ const list = Array.isArray(index.entries[chart.name]) ? index.entries[chart.name] : [];
167
+ const hex = chart.digest.slice("sha256:".length);
168
+ const listed = list.find((e) => e.version === chart.version);
169
+ if (listed) {
170
+ if (listed.digest === hex)
171
+ continue;
172
+ throw new PublishTargetError("publish-helm-version-taken", `${where} lists ${chart.name} ${chart.version} with the digest ${String(listed.digest)}, and this chart is ${hex}`, "A chart version is never replaced: cut a new release, so the chart carries a new version.");
173
+ }
174
+ index.entries[chart.name] = [{ ...chart.metadata, urls: [url], created, digest: hex }, ...list];
175
+ changed = true;
176
+ }
177
+ if (!changed)
178
+ return null;
179
+ index.generated = created;
180
+ const { apiVersion, entries, generated, ...rest } = index;
181
+ return `${emitYAML({ apiVersion, entries, generated, ...rest }, 0).replace(/\n*$/, "")}\n`;
182
+ }
183
+ export function helmTarget(decl, deps) {
184
+ const fetchImpl = deps.fetch ?? ((url, init) => fetch(url, init));
185
+ const failed = "publish-helm-failed";
186
+ const ix = decl.index;
187
+ const branch = ix?.branch ?? "gh-pages";
188
+ const indexPath = ix?.path ?? "index.yaml";
189
+ const indexDir = posix.dirname(indexPath) === "." ? "" : posix.dirname(indexPath);
190
+ const tokenEnv = ix?.tokenEnv ?? HELM_INDEX_TOKEN_ENV;
191
+ const credentialEnv = [...(decl.oci ? [decl.oci.passwordEnv ?? "OCI_PASSWORD"] : []), ...(ix ? [tokenEnv] : [])];
192
+ const where = [decl.oci ? decl.oci.repository : null, ix ? `${ix.repo}@${branch}:${indexPath}` : null].filter(Boolean).join(" and ");
193
+ const now = () => new Date(deps.now ? deps.now() : Date.now()).toISOString();
194
+ /** Each chart named, read and checked against the release's record and its label. */
195
+ const charts = (ctx) => {
196
+ const version = releaseVersion(ctx.label);
197
+ const out = [];
198
+ for (const p of expandArtifactAssets(ctx.release, decl.charts)) {
199
+ const bytes = new Uint8Array(readFileSync(memberFile(ctx.cwd, p)));
200
+ checkReleaseDigest(ctx.release, "asset", ctx.cwd, p, [bytesDigest(bytes)]);
201
+ const chart = readChartArchive(p, bytes);
202
+ if (version !== null && chart.version !== version) {
203
+ throw new PublishTargetError("publish-helm-version-mismatch", `${p} is ${chart.name} ${chart.version}, and the release is labelled ${ctx.label}, so the chart's version would not be the release's`, "Pack the chart at the cut with a helm entry of release.artifacts, which sets its version from the label, or set version in Chart.yaml to the label from its first digit.");
204
+ }
205
+ if (out.some((c) => c.name === chart.name))
206
+ throw new PublishTargetError("publish-helm-chart-taken", `two of the charts are named ${chart.name}`, "Name each chart once.");
207
+ out.push(chart);
208
+ }
209
+ return out;
210
+ };
211
+ const ociRef = (chart) => `${decl.oci.repository.replace(/\/+$/, "")}/${chart.name}`;
212
+ const connect = (ctx, chart) => {
213
+ const repo = parseRepository(ociRef(chart));
214
+ const cred = ociCredential({ ...(decl.oci.usernameEnv ? { usernameEnv: decl.oci.usernameEnv } : {}), ...(decl.oci.passwordEnv ? { passwordEnv: decl.oci.passwordEnv } : {}) }, repo, ctx);
215
+ return { cred, registry: new Registry(repo, fetchImpl, cred, ctx, deps.sleep) };
216
+ };
217
+ const ociItem = (chart, digest) => ({ name: `${chart.file} (tag ${helmOciTag(chart.version)})`, destination: `${ociRef(chart)}@${digest}`, digest });
218
+ const token = (ctx) => {
219
+ const t = readCredential(ctx.env, [tokenEnv], ctx.redactor);
220
+ if (!t)
221
+ throw new PublishTargetError("publish-credentials-missing", `the helm target reads the token for ${ix.repo} from ${tokenEnv}, and it is not set`, `Set ${tokenEnv} to a token that may push to ${branch} of ${ix.repo}.`);
222
+ return t;
223
+ };
224
+ const github = (ctx) => new GitHubRepo(githubApi(ix.api, ctx.env), ix.repo, token(ctx), fetchImpl, ctx, failed);
225
+ /** Each chart and the URL the index gives it. */
226
+ const listed = (ctx, cs) => {
227
+ const version = releaseVersion(ctx.label) ?? "";
228
+ return cs.map((chart) => ({
229
+ chart,
230
+ url: ix.url ? fillUrl(ix.url, { tag: ctx.releaseTag ?? "", label: ctx.label ?? "", version, name: chart.file }) : chart.file,
231
+ path: indexDir ? `${indexDir}/${chart.file}` : chart.file,
232
+ }));
233
+ };
234
+ /** What the branch at `ref` needs: the index with the charts added, and each archive committed beside it when there is no `url`. */
235
+ const changesAt = async (repo, ref, ctx, cs) => {
236
+ const entries = listed(ctx, cs);
237
+ const now0 = await repo.file(indexPath, ref);
238
+ const created = ctx.cut?.timestamp ?? now();
239
+ const text = addToHelmIndex(now0 ? now0.bytes.toString("utf-8") : null, entries, created, `${ix.repo}@${ref}:${indexPath}`);
240
+ const out = [];
241
+ if (!ix.url) {
242
+ for (const e of entries) {
243
+ const there = await repo.file(e.path, ref);
244
+ if (!there || bytesDigest(new Uint8Array(there.bytes)) !== e.chart.digest)
245
+ out.push({ path: e.path, bytes: e.chart.bytes });
246
+ }
247
+ }
248
+ if (text !== null)
249
+ out.push({ path: indexPath, bytes: new Uint8Array(Buffer.from(text, "utf-8")) });
250
+ return out;
251
+ };
252
+ const indexItems = (ctx, cs, present) => listed(ctx, cs).flatMap((e) => [
253
+ ...(ix.url ? [] : [{ name: e.chart.file, destination: `${ix.repo}@${branch}:${e.path}`, digest: e.chart.digest, ...(present ? { present: true } : {}) }]),
254
+ { name: `${e.chart.name} ${e.chart.version} in ${indexPath}`, destination: `${ix.repo}@${branch}:${indexPath}`, ...(present ? { present: true } : {}) },
255
+ ]);
256
+ const message = (ctx, cs) => `${cs.map((c) => `${c.name} ${c.version}`).join(", ")}${ctx.releaseTag ? `, released as ${ctx.releaseTag}` : ""}`;
257
+ const staging = (ctx) => `chant-publish/helm-${releaseVersion(ctx.label) ?? ctx.release.releaseDigest.slice(0, 12)}`;
258
+ const target = {
259
+ kind: "helm",
260
+ name: `helm ${decl.charts.join(", ")}`,
261
+ destination: where,
262
+ credentialEnv,
263
+ key: publishTargetKey(decl),
264
+ ...(ix ? { revealsLast: true } : {}),
265
+ /** #5165: each chart, under the OCI repository it goes to and the index that lists it. */
266
+ async names(ctx) {
267
+ const provides = new Set();
268
+ let cs = [];
269
+ try {
270
+ cs = charts(ctx);
271
+ }
272
+ catch {
273
+ cs = [];
274
+ }
275
+ for (const c of cs) {
276
+ if (decl.oci)
277
+ provides.add(trainName("oci", ociRef(c)));
278
+ if (ix)
279
+ provides.add(trainName("index", `${ix.repo}/${c.name}`));
280
+ }
281
+ return { provides: [...provides], needs: [] };
282
+ },
283
+ /** #5165: whether each chart's version tag is in the registry and the index lists each version; null when the charts can't be read here. */
284
+ async published(ctx) {
285
+ let cs;
286
+ try {
287
+ cs = charts(ctx);
288
+ }
289
+ catch {
290
+ return null;
291
+ }
292
+ if (decl.oci) {
293
+ for (const c of cs)
294
+ if ((await connect(ctx, c).registry.getManifest(helmOciTag(c.version))) === null)
295
+ return false;
296
+ }
297
+ if (ix) {
298
+ if (!readCredential(ctx.env, [tokenEnv], ctx.redactor))
299
+ return null;
300
+ const there = await github(ctx).file(indexPath, branch);
301
+ if (!there)
302
+ return false;
303
+ let index;
304
+ try {
305
+ index = parseYAML(there.bytes.toString("utf-8"));
306
+ }
307
+ catch {
308
+ return null;
309
+ }
310
+ for (const c of cs)
311
+ if (!(index.entries?.[c.name] ?? []).some((e) => e.version === c.version))
312
+ return false;
313
+ }
314
+ return true;
315
+ },
316
+ /** #5165: wait until each version tag names the chart's manifest, and the branch's index lists each chart. */
317
+ async visible(ctx, published) {
318
+ const oci = published.items.filter((i) => typeof i.digest === "string" && / \(tag [^)]+\)$/.test(i.name));
319
+ await waitUntilServed(ctx, deps, {
320
+ what: where,
321
+ code: "publish-helm-not-served",
322
+ check: async () => {
323
+ const missing = [];
324
+ for (const i of oci) {
325
+ const at = i.destination.lastIndexOf("@");
326
+ const ref = i.destination.slice(0, at);
327
+ const tag = /\(tag ([^)]+)\)$/.exec(i.name)[1];
328
+ const repo = parseRepository(ref);
329
+ const cred = ociCredential({ ...(decl.oci?.usernameEnv ? { usernameEnv: decl.oci.usernameEnv } : {}), ...(decl.oci?.passwordEnv ? { passwordEnv: decl.oci.passwordEnv } : {}) }, repo, ctx);
330
+ const got = await new Registry(repo, fetchImpl, cred, ctx, deps.sleep).getManifest(tag);
331
+ if (got?.digest !== i.digest)
332
+ missing.push(`${ref}:${tag}`);
333
+ }
334
+ if (ix && readCredential(ctx.env, [tokenEnv], ctx.redactor)) {
335
+ const names = published.items.map((i) => / in [^ ]+$/.exec(i.name) ? i.name.replace(/ in [^ ]+$/, "").split(" ") : null).filter((n) => n !== null && n.length === 2);
336
+ if (names.length > 0) {
337
+ const there = await github(ctx).file(indexPath, branch);
338
+ const index = there ? parseYAML(there.bytes.toString("utf-8")) : null;
339
+ for (const [name, version] of names)
340
+ if (!(index?.entries?.[name] ?? []).some((e) => e.version === version))
341
+ missing.push(`${name} ${version} in ${ix.repo}@${branch}:${indexPath}`);
342
+ }
343
+ }
344
+ return missing;
345
+ },
346
+ });
347
+ },
348
+ async plan(ctx) {
349
+ const cs = charts(ctx);
350
+ if (decl.oci)
351
+ for (const c of cs)
352
+ connect(ctx, c);
353
+ if (ix)
354
+ token(ctx);
355
+ return [...(decl.oci ? cs.map((c) => ociItem(c, helmOciManifest(c).digest)) : []), ...(ix ? indexItems(ctx, cs, false) : [])];
356
+ },
357
+ async stage(ctx) {
358
+ const cs = charts(ctx);
359
+ const items = [];
360
+ const state = {};
361
+ if (decl.oci) {
362
+ for (const c of cs) {
363
+ const { cred, registry } = connect(ctx, c);
364
+ const m = helmOciManifest(c);
365
+ if (await registry.hasManifest(m.digest, IMAGE_MANIFEST)) {
366
+ ctx.log(`${ociRef(c)} already holds ${m.digest}; the chart is not pushed again`);
367
+ items.push({ ...ociItem(c, m.digest), present: true });
368
+ continue;
369
+ }
370
+ ctx.log(`pushing ${c.path} to ${ociRef(c)} by digest ${m.digest}, ${cred ? `with credentials from ${cred.password.from}` : "anonymously"}; no tag moves yet`);
371
+ await registry.pushBlob(bytesDigest(m.config), () => m.config);
372
+ await registry.pushBlob(c.digest, () => c.bytes);
373
+ await registry.putManifest(m.digest, IMAGE_MANIFEST, m.manifest);
374
+ items.push(ociItem(c, m.digest));
375
+ }
376
+ }
377
+ if (ix) {
378
+ const repo = github(ctx);
379
+ const head = await repo.branchHead(branch);
380
+ if (!head)
381
+ throw new PublishTargetError(failed, `${ix.repo} has no branch ${branch}`, `Create ${branch} in ${ix.repo}, such as an empty branch GitHub Pages serves, or set index.branch.`);
382
+ const changes = await changesAt(repo, branch, ctx, cs);
383
+ if (changes.length === 0) {
384
+ ctx.log(`${branch} of ${ix.repo} already lists ${cs.map((c) => `${c.name} ${c.version}`).join(", ")}`);
385
+ items.push(...indexItems(ctx, cs, true));
386
+ state.present = "true";
387
+ }
388
+ else {
389
+ const at = staging(ctx);
390
+ ctx.log(`committing ${changes.map((c) => c.path).join(", ")} to ${at} of ${ix.repo}, at ${branch}'s head ${head.slice(0, 12)}`);
391
+ const commit = await repo.commitTree(head, changes, message(ctx, cs));
392
+ if ((await repo.branchHead(at)) === null)
393
+ await repo.createBranch(at, commit);
394
+ else
395
+ await repo.moveRef(`heads/${at}`, commit, true);
396
+ items.push(...indexItems(ctx, cs, false));
397
+ Object.assign(state, { staging: at, commit });
398
+ }
399
+ }
400
+ return { target: target.name, destination: target.destination, items, state };
401
+ },
402
+ async reveal(ctx, staged) {
403
+ const cs = charts(ctx);
404
+ const items = [];
405
+ if (decl.oci) {
406
+ for (const c of cs) {
407
+ const { registry } = connect(ctx, c);
408
+ const m = helmOciManifest(c);
409
+ const tag = helmOciTag(c.version);
410
+ const now0 = await registry.getManifest(tag);
411
+ if (now0?.digest === m.digest)
412
+ ctx.log(`${ociRef(c)}:${tag} already names ${m.digest}`);
413
+ else {
414
+ await registry.putManifest(tag, IMAGE_MANIFEST, m.manifest);
415
+ ctx.log(`tagged ${ociRef(c)}@${m.digest} ${tag}`);
416
+ }
417
+ items.push(ociItem(c, m.digest));
418
+ }
419
+ }
420
+ if (ix) {
421
+ if (staged.state.present === "true") {
422
+ items.push(...indexItems(ctx, cs, true));
423
+ }
424
+ else {
425
+ const repo = github(ctx);
426
+ const { staging: at, commit } = staged.state;
427
+ if (!at || !commit)
428
+ throw new PublishTargetError(failed, `the staged index for ${ix.repo} has no staging commit to reveal`, "Run the same publish again: it stages the index again.");
429
+ ctx.log(`fast-forwarding ${branch} of ${ix.repo} to ${commit.slice(0, 12)}`);
430
+ if (!(await repo.moveRef(`heads/${branch}`, commit, false))) {
431
+ const changes = await changesAt(repo, branch, ctx, cs);
432
+ if (changes.length === 0)
433
+ ctx.log(`${branch} moved since the stage and already lists the charts`);
434
+ else {
435
+ ctx.log(`${branch} moved since the stage; committing the index onto it`);
436
+ const head = await repo.branchHead(branch);
437
+ if (!head)
438
+ throw new PublishTargetError(failed, `${ix.repo} has no branch ${branch}`, `Create ${branch} in ${ix.repo}, or set index.branch.`);
439
+ const onto = await repo.commitTree(head, changes, message(ctx, cs));
440
+ if (!(await repo.moveRef(`heads/${branch}`, onto, false)))
441
+ throw new PublishTargetError(failed, `${branch} of ${ix.repo} moved again while the index was committed onto it`, "Run the same publish again: it commits the index onto the branch's new head.");
442
+ }
443
+ }
444
+ await repo.deleteRef(`heads/${at}`);
445
+ items.push(...indexItems(ctx, cs, false));
446
+ }
447
+ }
448
+ return { target: target.name, destination: target.destination, items };
449
+ },
450
+ };
451
+ return target;
452
+ }
@@ -0,0 +1,79 @@
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 type { MavenPublishDeclaration } from "./publish-declaration.js";
41
+ import { type PublishContext, type PublishDeps, type PublishTarget } from "./release-publish.js";
42
+ /** The first chant that publishes a `maven` target (#5232). */
43
+ export declare const PUBLISH_MAVEN_FLOOR = "0.124.102";
44
+ export declare const CENTRAL_PORTAL = "https://central.sonatype.com";
45
+ export declare const MAVEN_CENTRAL_REPOSITORY = "https://repo1.maven.org/maven2/";
46
+ /** How often the stage asks the Portal whether it has validated the bundle. */
47
+ export declare const MAVEN_STATUS_POLL_MS = 10000;
48
+ /** How long the stage waits for the Portal to validate the bundle. */
49
+ export declare const MAVEN_VALIDATION_WAIT_MS: number;
50
+ /** How long a train waits for the repository to serve what the reveal published: Central takes up to half an hour. */
51
+ export declare const MAVEN_VISIBLE_WAIT_MS: number;
52
+ export declare const mavenUsernameEnv: (decl: Pick<MavenPublishDeclaration, "usernameEnv">) => string;
53
+ export declare const mavenPasswordEnv: (decl: Pick<MavenPublishDeclaration, "passwordEnv">) => string;
54
+ /** One Maven component of a bundle. */
55
+ export interface MavenComponent {
56
+ groupId: string;
57
+ artifactId: string;
58
+ version: string;
59
+ /** Its directory in the bundle. */
60
+ dir: string;
61
+ pom: Buffer;
62
+ /** Its files in the bundle, by path. */
63
+ files: string[];
64
+ /** The SBOM file it carries, if any. */
65
+ sbom: string | null;
66
+ }
67
+ /** The components of a bundle's files, keyed by path. */
68
+ export declare function mavenComponents(files: ReadonlyMap<string, Buffer>): MavenComponent[];
69
+ /** The `groupId:artifactId` of each dependency a `.pom` needs at compile or run time. */
70
+ export declare function pomDependencies(pom: string): string[];
71
+ /** The bundle a declaration names, read: the zip to upload and its components. */
72
+ export declare function readMavenBundle(ctx: Pick<PublishContext, "cwd" | "release">, bundle: string): {
73
+ path: string;
74
+ zip: Buffer;
75
+ digest: string;
76
+ files: Map<string, Buffer>;
77
+ components: MavenComponent[];
78
+ };
79
+ export declare function mavenTarget(decl: MavenPublishDeclaration, deps: PublishDeps): PublishTarget;