@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,365 @@
1
+ /**
2
+ * The RubyGems target (#5232): `.gem` files pushed to RubyGems.org, or to
3
+ * another host that takes its API (`POST /api/v1/gems`, the gem as the body,
4
+ * the key in `Authorization`).
5
+ *
6
+ * The gems are files, directories of them, or `artifact:<name>`. Each file
7
+ * the release records must match its digest. The name, version and platform
8
+ * are read from the gem's own `metadata.gz`.
9
+ *
10
+ * A host has no draft: a version is visible once it is pushed, and a name,
11
+ * version and platform can never be pushed again, even after a yank. So the
12
+ * stage pushes nothing. It checks the gems and the credential, and reads
13
+ * `/api/v1/versions/<name>.json`: a version the host lists for the platform
14
+ * with the same SHA-256 is `present`; one it lists with another is refused
15
+ * (`publish-rubygems-version-exists`). The reveal reads it again and pushes
16
+ * the rest, so a reveal run again after a push whose record was lost sends
17
+ * nothing twice.
18
+ *
19
+ * Credentials:
20
+ *
21
+ * - `auth: "token"`: an API key from `tokenEnv` (default `GEM_HOST_API_KEY`,
22
+ * the variable `gem push` reads), with the push scope.
23
+ * - `auth: "trusted-publishing"`, RubyGems.org only: the run's OIDC ID token
24
+ * (audience `rubygems.org`, from GitHub Actions or `RUBYGEMS_ID_TOKEN`) is
25
+ * exchanged at `POST /api/v1/oidc/trusted_publisher/exchange_token` for a
26
+ * key that lasts minutes. The stage exchanges to check that RubyGems.org
27
+ * takes this workflow as a trusted publisher, and drops the key; the
28
+ * reveal exchanges again.
29
+ *
30
+ * Unset, `auth` is a token when the key's variable is set, else trusted
31
+ * publishing when the run has an OIDC ID token.
32
+ *
33
+ * A status change (#5163): `chant release yank` yanks each version the
34
+ * release pushed (`DELETE /api/v1/gems/yank`), with a key in `tokenEnv` that
35
+ * may yank. RubyGems.org takes no yank back, so `restore` is refused, and it
36
+ * has no deprecation, so `deprecate` changes nothing.
37
+ *
38
+ * A host keeps no file beside a gem, so nothing is attached. Under the
39
+ * `supply-chain` group the target is refused (`publish-sbom-missing`) unless
40
+ * `sbom` is `false`.
41
+ */
42
+ import { readFileSync } from "node:fs";
43
+ import { gunzipSync } from "node:zlib";
44
+ import { readCredential } from "./publish-credentials.js";
45
+ import { releaseVersion } from "./publish-index.js";
46
+ import { packageFiles } from "./publish-package-files.js";
47
+ import { tarEntries } from "./publish-pypi.js";
48
+ import { bytesDigest, checkReleaseDigest, hasIdToken, publishTargetKey, runIdToken } from "./publish-targets.js";
49
+ import { trainName, waitUntilServed } from "./publish-train-names.js";
50
+ import { PublishTargetError } from "./release-publish.js";
51
+ /** The first chant that publishes a `rubygems` target (#5232). */
52
+ export const PUBLISH_RUBYGEMS_FLOOR = "0.124.102";
53
+ export const RUBYGEMS_ORG = "https://rubygems.org";
54
+ /** The audience RubyGems.org takes an OIDC ID token for. */
55
+ export const RUBYGEMS_AUDIENCE = "rubygems.org";
56
+ /** The variable an OIDC ID token for RubyGems.org is read from outside GitHub Actions. */
57
+ export const RUBYGEMS_ID_TOKEN_ENV = "RUBYGEMS_ID_TOKEN";
58
+ export const rubygemsHost = (decl) => (decl.host ?? RUBYGEMS_ORG).replace(/\/+$/, "");
59
+ export const rubygemsTokenEnv = (decl) => decl.tokenEnv ?? "GEM_HOST_API_KEY";
60
+ /** How the target authenticates in `env`. */
61
+ export function rubygemsAuth(decl, env) {
62
+ if (decl.auth)
63
+ return decl.auth;
64
+ if (env[rubygemsTokenEnv(decl)])
65
+ return "token";
66
+ return decl.host === undefined && hasIdToken(env, RUBYGEMS_ID_TOKEN_ENV) ? "trusted-publishing" : "token";
67
+ }
68
+ const unquote = (s) => s.trim().replace(/^(['"])(.*)\1$/, "$2");
69
+ /** A gemspec's name, version, platform and runtime dependencies, from the YAML `gem build` writes into `metadata.gz`. */
70
+ export function parseGemMetadata(yaml) {
71
+ const name = /^name: *(.+)$/m.exec(yaml)?.[1];
72
+ const version = /^version: *!ruby\/object:Gem::Version\s*\n\s+version: *(.+)$/m.exec(yaml)?.[1] ?? /^version: *([^!\s].*)$/m.exec(yaml)?.[1];
73
+ const platform = /^platform: *(.+)$/m.exec(yaml)?.[1];
74
+ const deps = /^dependencies: *\n([\s\S]*?)(?=^[^\s-])/m.exec(`${yaml}\n.`)?.[1] ?? "";
75
+ const dependencies = deps
76
+ .split(/^- !ruby\/object:Gem::Dependency\s*$/m)
77
+ .map((block) => ({ name: /^ {2}name: *(.+)$/m.exec(block)?.[1], type: /^ {2}type: *:?(\w+)/m.exec(block)?.[1] }))
78
+ .filter((d) => d.name !== undefined && d.type !== "development")
79
+ .map((d) => unquote(d.name));
80
+ return { name: name ? unquote(name) : null, version: version ? unquote(version) : null, platform: platform ? unquote(platform) : "ruby", dependencies: [...new Set(dependencies)] };
81
+ }
82
+ /** Read one `.gem`: a tar holding `metadata.gz`. */
83
+ export function readGem(path, abs) {
84
+ const bytes = readFileSync(abs);
85
+ const file = abs.split(/[\\/]/).pop();
86
+ const bad = (why) => new PublishTargetError("publish-rubygems-not-a-gem", `${path} is not a gem chant can read: ${why}`, "Name the .gem files gem build writes.");
87
+ let meta;
88
+ try {
89
+ const gz = tarEntries(bytes).get("metadata.gz");
90
+ if (!gz)
91
+ throw new Error("it holds no metadata.gz");
92
+ meta = parseGemMetadata(gunzipSync(gz).toString("utf-8"));
93
+ }
94
+ catch (err) {
95
+ throw bad(err instanceof Error ? err.message : String(err));
96
+ }
97
+ if (!meta.name || !meta.version)
98
+ throw bad("its metadata has no name or version");
99
+ return { path, file, bytes, digest: bytesDigest(new Uint8Array(bytes)), name: meta.name, version: meta.version, platform: meta.platform, dependencies: meta.dependencies };
100
+ }
101
+ const full = (g) => `${g.name}-${g.version}${g.platform === "ruby" ? "" : `-${g.platform}`}`;
102
+ /** An item's name: `<name>@<version>`, with `-<platform>` for a platform gem. A gem version holds no `-`. */
103
+ export const gemItemName = (g) => `${g.name}@${g.version}${g.platform === "ruby" ? "" : `-${g.platform}`}`;
104
+ /** The gem an item names. */
105
+ export function parseGemItemName(name) {
106
+ const at = name.lastIndexOf("@");
107
+ if (at <= 0)
108
+ return null;
109
+ const rest = name.slice(at + 1);
110
+ const dash = rest.indexOf("-");
111
+ return { name: name.slice(0, at), version: dash < 0 ? rest : rest.slice(0, dash), platform: dash < 0 ? "ruby" : rest.slice(dash + 1) };
112
+ }
113
+ export function rubygemsTarget(decl, deps) {
114
+ const fetchImpl = deps.fetch ?? ((url, init) => fetch(url, init));
115
+ const host = rubygemsHost(decl);
116
+ const label = decl.host ? new URL(host).host : "RubyGems.org";
117
+ const tokenName = rubygemsTokenEnv(decl);
118
+ const gems = (ctx) => {
119
+ if (ctx.requireSbom && decl.sbom !== false) {
120
+ throw new PublishTargetError("publish-sbom-missing", `${label} keeps no file beside a gem, so the gems 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.");
121
+ }
122
+ return packageFiles(ctx, decl.gems, ".gem", "publish-rubygems", "Build the gems before publishing, such as with gem build.").map(({ path, abs }) => {
123
+ const g = readGem(path, abs);
124
+ checkReleaseDigest(ctx.release, "asset", ctx.cwd, path, [g.digest]);
125
+ return g;
126
+ });
127
+ };
128
+ const item = (g) => ({ name: gemItemName(g), destination: `${host}/gems/${g.name}/versions/${g.version}${g.platform === "ruby" ? "" : `-${g.platform}`}`, digest: g.digest });
129
+ const fail = (ctx, code, what, status, text, fix) => {
130
+ throw new PublishTargetError(code, ctx.redactor.redact(`${what} on ${label} answered ${status}${text ? `: ${text.replace(/\s+/g, " ").slice(0, 300)}` : ""}`), fix);
131
+ };
132
+ /** Each version the host lists for a gem, `<version>-<platform>` to its SHA-256 in hex (or null); empty when it has no such gem. */
133
+ const listed = async (ctx, name) => {
134
+ const url = `${host}/api/v1/versions/${encodeURIComponent(name)}.json`;
135
+ const res = await fetchImpl(url, { method: "GET", headers: { "user-agent": "chant", accept: "application/json" } });
136
+ const text = await res.text().catch(() => "");
137
+ if (res.status === 404)
138
+ return new Map();
139
+ if (res.status !== 200)
140
+ fail(ctx, "publish-rubygems-failed", `reading ${url}`, res.status, text);
141
+ const out = new Map();
142
+ try {
143
+ for (const v of JSON.parse(text)) {
144
+ if (typeof v.number === "string")
145
+ out.set(`${v.number}-${typeof v.platform === "string" ? v.platform : "ruby"}`, typeof v.sha === "string" ? v.sha.toLowerCase() : null);
146
+ }
147
+ }
148
+ catch {
149
+ fail(ctx, "publish-rubygems-failed", `reading ${url}`, res.status, "not a JSON list");
150
+ }
151
+ return out;
152
+ };
153
+ /** Each gem: `present` when the host lists it with the same bytes; refused when it lists it with others. */
154
+ const presence = async (ctx, list) => {
155
+ const byName = new Map();
156
+ const out = new Map();
157
+ for (const g of list) {
158
+ if (!byName.has(g.name))
159
+ byName.set(g.name, await listed(ctx, g.name));
160
+ const versions = byName.get(g.name);
161
+ const key = `${g.version}-${g.platform}`;
162
+ if (!versions.has(key)) {
163
+ out.set(g.file, false);
164
+ continue;
165
+ }
166
+ const sha = versions.get(key);
167
+ if (sha && `sha256:${sha}` !== g.digest) {
168
+ throw new PublishTargetError("publish-rubygems-version-exists", `${label} already has ${full(g)}, with sha256:${sha}, not ${g.digest}`, "A gem host never takes a version twice: cut a release with a new version.");
169
+ }
170
+ out.set(g.file, true);
171
+ }
172
+ return out;
173
+ };
174
+ const credential = (ctx) => {
175
+ const auth = rubygemsAuth(decl, ctx.env);
176
+ if (auth === "trusted-publishing") {
177
+ if (!hasIdToken(ctx.env, RUBYGEMS_ID_TOKEN_ENV)) {
178
+ throw new PublishTargetError("publish-credentials-missing", `the RubyGems.org target publishes with trusted publishing, and this run has no OIDC ID token: not a GitHub Actions job with id-token: write, and ${RUBYGEMS_ID_TOKEN_ENV} is not set`, "In GitHub Actions, give the job permissions: id-token: write.");
179
+ }
180
+ return { auth, key: null, from: null };
181
+ }
182
+ const cred = readCredential(ctx.env, [tokenName], ctx.redactor);
183
+ if (!cred) {
184
+ throw new PublishTargetError("publish-credentials-missing", `the ${label} target reads its API key from ${tokenName}, and it is not set${decl.host ? "" : ", and this run has no OIDC ID token for trusted publishing"}`, decl.host ? `Set ${tokenName} to a key the host takes.` : `Set ${tokenName} to a RubyGems.org API key with the push scope, or publish from a GitHub Actions job with id-token: write and a trusted publisher on RubyGems.org.`);
185
+ }
186
+ return { auth, key: cred.value, from: cred.from };
187
+ };
188
+ /** Trusted publishing: a key for this run, for its OIDC ID token. */
189
+ const exchange = async (ctx) => {
190
+ const jwt = await runIdToken(ctx, fetchImpl, RUBYGEMS_AUDIENCE, RUBYGEMS_ID_TOKEN_ENV, "publish-rubygems-trusted-publishing");
191
+ const res = await fetchImpl(`${host}/api/v1/oidc/trusted_publisher/exchange_token`, { method: "POST", headers: { "user-agent": "chant", "content-type": "application/json", accept: "application/json" }, body: JSON.stringify({ jwt }) });
192
+ const text = await res.text().catch(() => "");
193
+ let body = {};
194
+ try {
195
+ body = JSON.parse(text);
196
+ }
197
+ catch {
198
+ // Reported by its status.
199
+ }
200
+ if (res.status < 200 || res.status > 299 || typeof body.rubygems_api_key !== "string" || !body.rubygems_api_key) {
201
+ throw new PublishTargetError("publish-rubygems-trusted-publishing", ctx.redactor.redact(`RubyGems.org gave no API key for this run's OIDC ID token: it answered ${res.status}${typeof body.error === "string" ? `: ${body.error}` : text ? `: ${text.replace(/\s+/g, " ").slice(0, 300)}` : ""}`), "Add this repository and workflow as a trusted publisher of the gem on RubyGems.org (a pending trusted publisher for a gem that does not exist yet).");
202
+ }
203
+ ctx.redactor.add(body.rubygems_api_key);
204
+ return body.rubygems_api_key;
205
+ };
206
+ const push = async (ctx, g, key) => {
207
+ ctx.log(`pushing ${g.file} (${g.bytes.byteLength} bytes) to ${label}`);
208
+ const res = await fetchImpl(`${host}/api/v1/gems`, { method: "POST", headers: { "user-agent": "chant", "content-type": "application/octet-stream", authorization: key }, body: new Uint8Array(g.bytes) });
209
+ const text = await res.text().catch(() => "");
210
+ if (res.status === 200 || res.status === 201)
211
+ return "sent";
212
+ if (res.status === 409 || /repushing|already been pushed/i.test(text)) {
213
+ // Another push of this version won the race, or a record was lost: the host keeps the first bytes it took.
214
+ const now = await presence(ctx, [g]).catch((err) => {
215
+ if (err instanceof PublishTargetError)
216
+ throw err;
217
+ return new Map();
218
+ });
219
+ if (now.get(g.file))
220
+ return "present";
221
+ throw new PublishTargetError("publish-rubygems-version-exists", ctx.redactor.redact(`${label} refused ${g.file}: ${text.replace(/\s+/g, " ").slice(0, 300)}`), "A gem host never takes a version twice, even after a yank: cut a release with a new version.");
222
+ }
223
+ return fail(ctx, "publish-rubygems-failed", `pushing ${g.file}`, res.status, text, /otp|multi.?factor|mfa/i.test(text)
224
+ ? "The account asks for a one-time password on API pushes: publish with trusted publishing, or set its MFA level to UI and gem signin."
225
+ : res.status === 401 || res.status === 403
226
+ ? `Check that the key has the push scope and that its owner owns ${g.name}.`
227
+ : undefined);
228
+ };
229
+ const target = {
230
+ kind: "rubygems",
231
+ name: `${label} ${decl.gems.join(", ")}`,
232
+ destination: label,
233
+ credentialEnv: [tokenName, RUBYGEMS_ID_TOKEN_ENV],
234
+ key: publishTargetKey(decl),
235
+ uploadsAtReveal: true,
236
+ async names(ctx) {
237
+ const list = packageFiles(ctx, decl.gems, ".gem", "publish-rubygems", "Build the gems before publishing.").map(({ path, abs }) => readGem(path, abs));
238
+ const provides = [...new Set(list.map((g) => trainName("rubygems", g.name)))];
239
+ const needs = new Set(list.flatMap((g) => g.dependencies.map((d) => trainName("rubygems", d))));
240
+ return { provides, needs: [...needs].filter((n) => !provides.includes(n)) };
241
+ },
242
+ /** #5165: whether the host lists each gem at the release's version. */
243
+ async published(ctx) {
244
+ const version = releaseVersion(ctx.label);
245
+ if (!version)
246
+ return null;
247
+ let list;
248
+ try {
249
+ list = packageFiles(ctx, decl.gems, ".gem", "publish-rubygems", "").map(({ path, abs }) => readGem(path, abs));
250
+ }
251
+ catch {
252
+ return null;
253
+ }
254
+ for (const g of list) {
255
+ const versions = await listed(ctx, g.name);
256
+ if (!versions.has(`${version}-${g.platform}`))
257
+ return false;
258
+ }
259
+ return true;
260
+ },
261
+ /** #5165: wait until the host lists each gem the reveal pushed. */
262
+ async visible(ctx, published) {
263
+ const list = published.items.filter((i) => i.attachment === undefined && !i.refused).map((i) => parseGemItemName(i.name)).filter((g) => g !== null);
264
+ if (list.length === 0)
265
+ return;
266
+ await waitUntilServed(ctx, deps, {
267
+ what: label,
268
+ code: "publish-rubygems-not-served",
269
+ check: async () => {
270
+ const missing = [];
271
+ for (const g of list)
272
+ if (!(await listed(ctx, g.name)).has(`${g.version}-${g.platform}`))
273
+ missing.push(full(g));
274
+ return missing;
275
+ },
276
+ });
277
+ },
278
+ async plan(ctx) {
279
+ const list = gems(ctx);
280
+ credential(ctx);
281
+ return list.map(item);
282
+ },
283
+ async stage(ctx) {
284
+ const list = gems(ctx);
285
+ const cred = credential(ctx);
286
+ if (cred.key)
287
+ ctx.log(`using the API key from ${cred.from}; ${label} has no read-only check of a key, so whether it may push shows at the reveal`);
288
+ else {
289
+ await exchange(ctx);
290
+ ctx.log("RubyGems.org takes this run as a trusted publisher; the reveal asks for a new key, since one lasts minutes");
291
+ }
292
+ const present = await presence(ctx, list);
293
+ const items = list.map((g) => (present.get(g.file) ? { ...item(g), present: true } : item(g)));
294
+ const waiting = items.filter((i) => !i.present).map((i) => i.name);
295
+ ctx.log(waiting.length === 0 ? `${label} already has every gem with the same bytes` : `${waiting.join(", ")} ${waiting.length === 1 ? "is" : "are"} pushed at the reveal, since ${label} has no draft`);
296
+ const staged = { target: target.name, destination: target.destination, items, state: waiting.length === 0 ? { present: "true" } : {} };
297
+ return staged;
298
+ },
299
+ async reveal(ctx, staged) {
300
+ if (staged.state.present === "true")
301
+ return { target: target.name, destination: target.destination, items: staged.items.map((i) => ({ ...i, present: true })) };
302
+ const list = gems(ctx);
303
+ const cred = credential(ctx);
304
+ // Read again: a reveal run after a push whose record was lost finds the gem there.
305
+ const present = await presence(ctx, list);
306
+ let key = cred.key;
307
+ const done = [];
308
+ const items = [];
309
+ for (const g of list) {
310
+ if (present.get(g.file)) {
311
+ items.push({ ...item(g), present: true });
312
+ continue;
313
+ }
314
+ key ?? (key = await exchange(ctx));
315
+ let r;
316
+ try {
317
+ r = await push(ctx, g, key);
318
+ }
319
+ catch (err) {
320
+ if (err instanceof PublishTargetError && done.length > 0)
321
+ throw new PublishTargetError(err.code, `${err.message}. Pushed before it: ${done.join(", ")}; the same publish run again pushes only the rest`, err.fix);
322
+ throw err;
323
+ }
324
+ if (r === "sent")
325
+ done.push(g.file);
326
+ items.push(r === "present" ? { ...item(g), present: true } : item(g));
327
+ }
328
+ return { target: target.name, destination: target.destination, items };
329
+ },
330
+ /** #5163: yank each version the release pushed. A yank can't be undone, and there is no deprecation. */
331
+ async setStatus(ctx) {
332
+ if (ctx.status === "deprecated")
333
+ return [{ what: `${label} unchanged: a gem version has no deprecation; yank takes it out of resolution`, already: true }];
334
+ const pushed = ctx.revealed
335
+ .filter((i) => i.attachment === undefined && !i.refused)
336
+ .map((i) => parseGemItemName(i.name))
337
+ .filter((g) => g !== null);
338
+ if (ctx.status === "active") {
339
+ return pushed.map((g) => ({ what: `restore ${full(g)}`, refused: { code: "release-status-unsupported", message: `${label} takes no yank back`, fix: "Cut a release with a new version." } }));
340
+ }
341
+ const what = (g) => `DELETE ${host}/api/v1/gems/yank gem_name=${g.name} version=${g.version}${g.platform === "ruby" ? "" : ` platform=${g.platform}`}`;
342
+ if (!ctx.apply)
343
+ return pushed.map((g) => ({ what: what(g) }));
344
+ const cred = readCredential(ctx.env, [tokenName], ctx.redactor);
345
+ if (!cred)
346
+ throw new PublishTargetError("publish-credentials-missing", `the ${label} target reads its API key from ${tokenName}, and it is not set`, `Set ${tokenName} to a key of ${label} with the yank scope.`);
347
+ const actions = [];
348
+ for (const g of pushed) {
349
+ if (!(await listed(ctx, g.name)).has(`${g.version}-${g.platform}`)) {
350
+ actions.push({ what: `${full(g)} is not listed on ${label}; it is yanked already, or was never pushed`, already: true });
351
+ continue;
352
+ }
353
+ const form = new URLSearchParams({ gem_name: g.name, version: g.version, ...(g.platform === "ruby" ? {} : { platform: g.platform }) }).toString();
354
+ ctx.log(`yanking ${full(g)} on ${label}`);
355
+ const res = await fetchImpl(`${host}/api/v1/gems/yank`, { method: "DELETE", headers: { "user-agent": "chant", "content-type": "application/x-www-form-urlencoded", authorization: cred.value }, body: form });
356
+ const text = await res.text().catch(() => "");
357
+ if (res.status < 200 || res.status > 299)
358
+ fail(ctx, "release-status-rubygems-failed", what(g), res.status, text, `Yanking needs a key with the yank scope whose owner owns ${g.name}.`);
359
+ actions.push({ what: what(g) });
360
+ }
361
+ return actions;
362
+ },
363
+ };
364
+ return target;
365
+ }
@@ -24,6 +24,16 @@
24
24
  * - `index` (./publish-index.ts): manifests in an index repository such as
25
25
  * krew-index or winget-pkgs, committed or proposed in a pull request,
26
26
  * revealed after every other target. `homebrew` is its tap preset.
27
+ * - `helm` (./publish-helm.ts): Helm chart archives pushed to an OCI
28
+ * registry, and listed in a chart repository's `index.yaml` on a branch of
29
+ * a GitHub repository (#5233).
30
+ * - `maven` (./publish-maven.ts): a bundle uploaded to the Central Portal
31
+ * and validated at the stage, published to Maven Central at the reveal
32
+ * (#5232).
33
+ * - `nuget` (./publish-nuget.ts): `.nupkg` files pushed to nuget.org or
34
+ * another feed, with an API key or nuget.org's trusted publishing (#5232).
35
+ * - `rubygems` (./publish-rubygems.ts): `.gem` files pushed to RubyGems.org
36
+ * or another host, with an API key or trusted publishing (#5232).
27
37
  *
28
38
  * A file a target reads that the release records as an artifact at the same
29
39
  * path is checked against the release's digest, and a file that differs is
@@ -24,6 +24,16 @@
24
24
  * - `index` (./publish-index.ts): manifests in an index repository such as
25
25
  * krew-index or winget-pkgs, committed or proposed in a pull request,
26
26
  * revealed after every other target. `homebrew` is its tap preset.
27
+ * - `helm` (./publish-helm.ts): Helm chart archives pushed to an OCI
28
+ * registry, and listed in a chart repository's `index.yaml` on a branch of
29
+ * a GitHub repository (#5233).
30
+ * - `maven` (./publish-maven.ts): a bundle uploaded to the Central Portal
31
+ * and validated at the stage, published to Maven Central at the reveal
32
+ * (#5232).
33
+ * - `nuget` (./publish-nuget.ts): `.nupkg` files pushed to nuget.org or
34
+ * another feed, with an API key or nuget.org's trusted publishing (#5232).
35
+ * - `rubygems` (./publish-rubygems.ts): `.gem` files pushed to RubyGems.org
36
+ * or another host, with an API key or trusted publishing (#5232).
27
37
  *
28
38
  * A file a target reads that the release records as an artifact at the same
29
39
  * path is checked against the release's digest, and a file that differs is
@@ -72,6 +82,18 @@ export async function createPublishTargets(decls, deps = {}) {
72
82
  case "index":
73
83
  out.push((await import("./publish-index.js")).indexTarget(d, deps));
74
84
  break;
85
+ case "helm":
86
+ out.push((await import("./publish-helm.js")).helmTarget(d, deps));
87
+ break;
88
+ case "maven":
89
+ out.push((await import("./publish-maven.js")).mavenTarget(d, deps));
90
+ break;
91
+ case "nuget":
92
+ out.push((await import("./publish-nuget.js")).nugetTarget(d, deps));
93
+ break;
94
+ case "rubygems":
95
+ out.push((await import("./publish-rubygems.js")).rubygemsTarget(d, deps));
96
+ break;
75
97
  }
76
98
  }
77
99
  return out;
@@ -11,6 +11,9 @@
11
11
  * | `oci` | the repository, lowercased, with no tag or digest, and Docker Hub's `docker.io/` (and `library/`) left off |
12
12
  * | `pypi` | the project name normalized as PEP 503 does |
13
13
  * | `cargo` | the crate name, lowercased, `_` as `-` |
14
+ * | `maven` | `<groupId>:<artifactId>` |
15
+ * | `nuget` | the package id, lowercased |
16
+ * | `rubygems` | the gem name |
14
17
  * | `marketplace` | `<publisher>.<name>`, lowercased |
15
18
  * | `mcp` | the server's name in `server.json` |
16
19
  * | `forge`, `homebrew`, `index`, `tauri-updater` | where it publishes: the repository, and the formula or manifest name |
@@ -19,7 +22,7 @@
19
22
  * and an image an mcp entry lists is `oci:<repository>` in both.
20
23
  */
21
24
  import { type PublishContextBase, type PublishDeps } from "./release-publish.js";
22
- export type TrainNameKind = "npm" | "oci" | "pypi" | "cargo" | "marketplace" | "mcp" | "forge" | "homebrew" | "index" | "tauri-updater";
25
+ export type TrainNameKind = "npm" | "oci" | "pypi" | "cargo" | "marketplace" | "mcp" | "forge" | "homebrew" | "index" | "tauri-updater" | "maven" | "nuget" | "rubygems";
23
26
  /** An image reference's repository, as a train compares it: lowercased, no tag or digest, no `docker.io/` or `library/`. */
24
27
  export declare function ociRepositoryName(ref: string): string;
25
28
  /** `<kind>:<name>`, the name in the form its registry compares. */
@@ -11,6 +11,9 @@
11
11
  * | `oci` | the repository, lowercased, with no tag or digest, and Docker Hub's `docker.io/` (and `library/`) left off |
12
12
  * | `pypi` | the project name normalized as PEP 503 does |
13
13
  * | `cargo` | the crate name, lowercased, `_` as `-` |
14
+ * | `maven` | `<groupId>:<artifactId>` |
15
+ * | `nuget` | the package id, lowercased |
16
+ * | `rubygems` | the gem name |
14
17
  * | `marketplace` | `<publisher>.<name>`, lowercased |
15
18
  * | `mcp` | the server's name in `server.json` |
16
19
  * | `forge`, `homebrew`, `index`, `tauri-updater` | where it publishes: the repository, and the formula or manifest name |
@@ -47,6 +50,8 @@ export function trainName(kind, name) {
47
50
  return `cargo:${name.toLowerCase().replace(/_/g, "-")}`;
48
51
  case "marketplace":
49
52
  return `marketplace:${name.toLowerCase()}`;
53
+ case "nuget":
54
+ return `nuget:${name.toLowerCase()}`;
50
55
  default:
51
56
  return `${kind}:${name}`;
52
57
  }
@@ -33,6 +33,24 @@
33
33
  * targets publish them. The goreleaser run is `CHANT_GORELEASER` when set,
34
34
  * which `chant release workflow` points at the version it pins
35
35
  * (../tool-pins.ts), else `goreleaser` on the PATH.
36
+ * - `{ name, helm: { chart, dir?, appVersion? } }` (#5233): chant packs the
37
+ * Helm chart in the directory `chart` into `<dir>/<chart name>-<version>.tgz`
38
+ * itself, as `helm package` lays it out (the chart's files under a
39
+ * directory named for it, less what `.helmignore` and helm's own default
40
+ * leave out), with `version` in `Chart.yaml` set to the label from its first
41
+ * digit and, with `appVersion`, `appVersion` set to the label. Every entry is
42
+ * dated `SOURCE_DATE_EPOCH`, so the same chart packs to the same bytes. No
43
+ * helm is needed; a chart's dependencies are packed as they sit in its
44
+ * `charts/` directory.
45
+ * - `{ name, nfpm: { config?, packagers?, platforms?, dir?, fileName? } }`
46
+ * (#5233): the cut runs nfpm once per packager (`deb` and `rpm` by default)
47
+ * and platform, with `CHANT_RELEASE_VERSION` (the label from its first
48
+ * digit), `CHANT_RELEASE_LABEL`, `CHANT_RELEASE_OS` and `CHANT_RELEASE_ARCH`
49
+ * set for the config to read, and records each package. The config's
50
+ * `version` must name `${CHANT_RELEASE_VERSION}` or `${CHANT_RELEASE_LABEL}`
51
+ * (`release-artifact-version-mismatch`). The nfpm run is `CHANT_NFPM` when
52
+ * set, which `chant release workflow` points at the version it pins
53
+ * (../tool-pins.ts), else `nfpm` on the PATH.
36
54
  * - `{ name, checksums, of? }`: a file of `<sha256> <file name>` lines, as
37
55
  * `sha256sum` writes and checks them, over the files of the entries `of`
38
56
  * names (default: every entry before it).
@@ -55,6 +73,10 @@ import type { Release, ReleaseArtifact } from "./release-store.js";
55
73
  export declare const RELEASE_ARTIFACTS_FLOOR = "0.124.101";
56
74
  /** The variable naming the goreleaser binary the cut runs. */
57
75
  export declare const GORELEASER_ENV = "CHANT_GORELEASER";
76
+ /** The first chant with `helm` and `nfpm` entries in `release.artifacts` (#5233). */
77
+ export declare const RELEASE_ARTIFACTS_PACKAGES_FLOOR = "0.124.102";
78
+ /** The variable naming the nfpm binary the cut runs (#5233). */
79
+ export declare const NFPM_ENV = "CHANT_NFPM";
58
80
  /** How an archive entry packs a platform's outputs. */
59
81
  export interface ReleaseArchiveSpec {
60
82
  /** The archive's file name without its extension. May hold `{name}`, `{os}`, `{arch}`, `{label}` and `{version}`. Default `{name}_{os}_{arch}`, or `{name}` with no platforms. */
@@ -120,7 +142,38 @@ export interface ReleaseArtifactChecksums {
120
142
  /** The entries it covers. Default: every entry before it. */
121
143
  of?: string[];
122
144
  }
123
- export type ReleaseArtifactDeclaration = ReleaseArtifactBuild | ReleaseArtifactPrebuilt | ReleaseArtifactGoreleaser | ReleaseArtifactChecksums;
145
+ /** A Helm chart chant packs itself (#5233). */
146
+ export interface ReleaseArtifactHelm {
147
+ name: string;
148
+ helm: {
149
+ /** The chart's directory, holding `Chart.yaml`, relative to the member. */
150
+ chart: string;
151
+ /** The directory the chart archive is written to, relative to the member. Default `dist`. */
152
+ dir?: string;
153
+ /** Set `appVersion` in the packed `Chart.yaml` to the release's label too. Default false. */
154
+ appVersion?: boolean;
155
+ };
156
+ }
157
+ /** The package formats an nfpm entry builds. */
158
+ export declare const NFPM_PACKAGERS: readonly ["deb", "rpm", "apk", "archlinux", "ipk"];
159
+ export type NfpmPackager = (typeof NFPM_PACKAGERS)[number];
160
+ /** Linux packages nfpm builds from files the member has, such as an earlier entry's binaries (#5233). */
161
+ export interface ReleaseArtifactNfpm {
162
+ name: string;
163
+ nfpm: {
164
+ /** The nfpm config, relative to the member. Default `nfpm.yaml`. */
165
+ config?: string;
166
+ /** The package formats. Default `["deb", "rpm"]`. */
167
+ packagers?: NfpmPackager[];
168
+ /** The platforms, `os/arch`, to package for, once each, with `CHANT_RELEASE_OS` and `CHANT_RELEASE_ARCH` set. Default: once, for the config's own `arch`. */
169
+ platforms?: string[];
170
+ /** The directory the packages are written to, relative to the member. Default `dist`. */
171
+ dir?: string;
172
+ /** Each package's file name without its extension: `{name}`, `{version}`, `{label}`, `{os}`, `{arch}` and `{packager}`. Default `{name}_{version}_{arch}`, or `{name}_{version}` with no platforms. */
173
+ fileName?: string;
174
+ };
175
+ }
176
+ export type ReleaseArtifactDeclaration = ReleaseArtifactBuild | ReleaseArtifactPrebuilt | ReleaseArtifactGoreleaser | ReleaseArtifactChecksums | ReleaseArtifactHelm | ReleaseArtifactNfpm;
124
177
  /**
125
178
  * The `artifacts.json` types recorded from goreleaser by default: what its
126
179
  * own release would upload. A `Binary` is recorded only when it sits at the
@@ -181,15 +234,38 @@ export interface BuildArtifactsInput {
181
234
  * cut.
182
235
  */
183
236
  export declare function buildReleaseArtifacts(i: BuildArtifactsInput): ReleaseArtifact[];
237
+ /** Helm's ignore rules: a `.helmignore`'s lines and helm's default, `templates/.?*`. */
238
+ interface HelmIgnoreRule {
239
+ re: RegExp;
240
+ negate: boolean;
241
+ dirOnly: boolean;
242
+ /** No `/` in the pattern: it matches a path's last segment. */
243
+ base: boolean;
244
+ }
245
+ /** The rules of a `.helmignore`, after helm's default. A `**` is refused, as helm refuses it. */
246
+ export declare function helmIgnoreRules(text: string | null, where: string): HelmIgnoreRule[];
247
+ /** Whether helm leaves `rel` (a path from the chart's directory) out of the chart, as its ignore package decides. */
248
+ export declare function helmIgnored(rules: readonly HelmIgnoreRule[], rel: string, dir: boolean): boolean;
249
+ /** The top-level `version` of an nfpm config, unquoted, or null. */
250
+ export declare function nfpmConfigVersion(text: string): string | null;
251
+ /** Whether an nfpm config's version carries the release's: it names the variable chant sets, or is the label or its version. */
252
+ export declare function nfpmVersionFollowsLabel(version: string | null, label: string, labelVer: string): boolean;
184
253
  interface ArchiveEntry {
185
254
  /** The path inside the archive. */
186
255
  name: string;
187
256
  abs: string;
257
+ /** The entry's bytes, in place of the file's (its mode is still the file's), such as a chart's `Chart.yaml` with its version set (#5233). */
258
+ bytes?: Buffer;
188
259
  }
260
+ /** An entry of a zip: a file, or bytes with no file (#5232), which get mode 0644. */
261
+ export type ZipEntry = ArchiveEntry | {
262
+ name: string;
263
+ bytes: Buffer;
264
+ };
189
265
  /** A gzipped ustar archive of the entries in order, each dated `mtime`, owned by uid and gid 0 and mode 0755 when executable, else 0644. */
190
266
  export declare function tarGzArchive(entries: readonly ArchiveEntry[], mtime: number): Buffer;
191
267
  /** A zip of the entries in order, deflated, each dated `mtime` (UTC) with its Unix mode. */
192
- export declare function zipArchive(entries: readonly ArchiveEntry[], mtime: number): Buffer;
268
+ export declare function zipArchive(entries: readonly ZipEntry[], mtime: number): Buffer;
193
269
  /** The files the release records for `names`, the entries `release.artifacts` declares. */
194
270
  export declare function releaseArtifactFiles(release: Pick<Release, "artifactDigests">, names: readonly string[]): ReleaseArtifact[];
195
271
  /** Where a recorded file differs from the release in `cwd`: missing, or another digest. */
@@ -205,6 +281,8 @@ export declare function copyArtifactFiles(files: readonly {
205
281
  }[], from: string, to: string, o?: {
206
282
  missingOk?: boolean;
207
283
  }): void;
284
+ /** Whether any entry is packaged by nfpm, for the workflow's install step (#5233). */
285
+ export declare function usesNfpm(artifacts: readonly ReleaseArtifactDeclaration[]): boolean;
208
286
  /** Whether any entry is built by goreleaser, for the workflow's install step. */
209
287
  export declare function usesGoreleaser(artifacts: readonly ReleaseArtifactDeclaration[]): boolean;
210
288
  /** The `artifact:<name>` prefix a forge, homebrew or index target's `assets` names an entry's files with. */