@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.
- package/dist/ci-evidence-claims.d.ts +12 -0
- package/dist/ci-evidence-claims.js +12 -0
- package/dist/cli/commands/onboard.js +8 -8
- package/dist/cli/handlers/release-init.js +53 -19
- package/dist/cli/handlers/release.d.ts +1 -1
- package/dist/cli/handlers/release.js +12 -9
- package/dist/cli/main.js +13 -2
- package/dist/cli/parse-args.js +5 -0
- package/dist/cli/registry.d.ts +2 -0
- package/dist/cli/release-commands/cut.js +4 -3
- package/dist/cli/release-commands/init.js +4 -1
- package/dist/cli/release-commands/workflow.js +4 -2
- package/dist/cloud-lister/index.d.ts +4 -1
- package/dist/cloud-lister/index.js +2 -1
- package/dist/cloud-lister/kubernetes-components.d.ts +56 -0
- package/dist/cloud-lister/kubernetes-components.js +641 -0
- package/dist/cloud-lister/kubernetes.d.ts +18 -0
- package/dist/cloud-lister/kubernetes.js +26 -1
- package/dist/cloud-lister/mask.d.ts +5 -1
- package/dist/cloud-lister/mask.js +14 -5
- package/dist/config-import.d.ts +1 -1
- package/dist/config-import.js +6 -2
- package/dist/config-sandbox.d.ts +1 -1
- package/dist/config-sandbox.js +3 -3
- package/dist/config.d.ts +75 -1
- package/dist/config.js +27 -2
- package/dist/deep-observation.js +9 -3
- package/dist/floor-table.data.js +13 -6
- package/dist/lexicon.d.ts +4 -2
- package/dist/lifecycle/__fixtures__/package-files.d.ts +32 -0
- package/dist/lifecycle/__fixtures__/package-files.js +72 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.js +5 -0
- package/dist/lifecycle/publish-credentials.d.ts +1 -1
- package/dist/lifecycle/publish-credentials.js +5 -0
- package/dist/lifecycle/publish-declaration.d.ts +123 -0
- package/dist/lifecycle/publish-declaration.js +141 -2
- package/dist/lifecycle/publish-helm.d.ts +83 -0
- package/dist/lifecycle/publish-helm.js +451 -0
- package/dist/lifecycle/publish-maven.d.ts +79 -0
- package/dist/lifecycle/publish-maven.js +363 -0
- package/dist/lifecycle/publish-mcp-registry.js +1 -2
- package/dist/lifecycle/publish-npm.d.ts +27 -1
- package/dist/lifecycle/publish-npm.js +52 -2
- package/dist/lifecycle/publish-nuget.d.ts +93 -0
- package/dist/lifecycle/publish-nuget.js +376 -0
- package/dist/lifecycle/publish-oci.d.ts +57 -1
- package/dist/lifecycle/publish-oci.js +1 -1
- package/dist/lifecycle/publish-package-files.d.ts +16 -0
- package/dist/lifecycle/publish-package-files.js +39 -0
- package/dist/lifecycle/publish-pypi.d.ts +2 -0
- package/dist/lifecycle/publish-pypi.js +1 -1
- package/dist/lifecycle/publish-rubygems.d.ts +84 -0
- package/dist/lifecycle/publish-rubygems.js +365 -0
- package/dist/lifecycle/publish-targets.d.ts +10 -0
- package/dist/lifecycle/publish-targets.js +22 -0
- package/dist/lifecycle/publish-train-names.d.ts +4 -1
- package/dist/lifecycle/publish-train-names.js +5 -0
- package/dist/lifecycle/release-artifacts.d.ts +80 -2
- package/dist/lifecycle/release-artifacts.js +241 -5
- package/dist/lifecycle/release-cut.d.ts +6 -1
- package/dist/lifecycle/release-cut.js +15 -0
- package/dist/lifecycle/release-doctor.js +208 -6
- package/dist/lifecycle/release-init-registries.d.ts +48 -0
- package/dist/lifecycle/release-init-registries.js +97 -0
- package/dist/lifecycle/release-init.d.ts +22 -2
- package/dist/lifecycle/release-init.js +139 -13
- package/dist/lifecycle/release-next.js +1 -2
- package/dist/lifecycle/release-publish.d.ts +1 -1
- package/dist/lifecycle/release-publish.js +1 -1
- package/dist/lifecycle/release-tag.js +1 -2
- package/dist/op/local-executor.d.ts +1 -1
- package/dist/op/local-executor.js +2 -2
- package/dist/op/op-waves-evidence.js +9 -2
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/sensitive-key.d.ts +12 -0
- package/dist/sensitive-key.js +52 -0
- package/dist/tool-pins.d.ts +2 -0
- package/dist/tool-pins.js +12 -0
- package/dist/ts-loader.d.ts +8 -0
- package/dist/ts-loader.js +19 -0
- package/dist/wave-runtime.mjs +325 -325
- package/dist/workspace/lexicon-outputs.d.ts +1 -1
- package/dist/workspace/lexicon-outputs.js +1 -1
- package/dist/workspace/release-steps/index.js +4 -0
- package/dist/workspace/release-steps/nfpm.d.ts +13 -0
- package/dist/workspace/release-steps/nfpm.js +29 -0
- package/dist/workspace/release-steps/nuget.d.ts +14 -0
- package/dist/workspace/release-steps/nuget.js +16 -0
- package/dist/workspace/release-steps/targets.d.ts +2 -2
- package/dist/workspace/release-steps/targets.js +3 -3
- package/dist/workspace/release-train-workflow.d.ts +27 -2
- package/dist/workspace/release-train-workflow.js +171 -14
- package/dist/workspace/release-train.js +5 -1
- package/dist/workspace/release-workflow.d.ts +39 -3
- package/dist/workspace/release-workflow.js +80 -24
- package/dist/workspace/train-artifacts.d.ts +107 -0
- package/dist/workspace/train-artifacts.js +239 -0
- package/dist/workspace/train-cut.d.ts +14 -2
- package/dist/workspace/train-cut.js +49 -7
- package/dist/workspace/train-prepare.d.ts +6 -3
- package/dist/workspace/train-prepare.js +54 -8
- package/dist/workspace/train-publish.d.ts +9 -0
- package/dist/workspace/train-publish.js +29 -4
- package/dist/workspace/train-shell.d.ts +5 -0
- package/dist/workspace/train-shell.js +17 -0
- package/dist/workspace/trust/check-evidence-report.d.ts +3 -7
- package/dist/workspace/trust/check-evidence-report.js +3 -7
- package/package.json +1 -1
|
@@ -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,10 +73,20 @@ import { createHash } from "node:crypto";
|
|
|
55
73
|
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
56
74
|
import { dirname, isAbsolute, posix, relative, resolve } from "node:path";
|
|
57
75
|
import { deflateRawSync, gzipSync } from "node:zlib";
|
|
76
|
+
import { stampVersionFile } from "./release-version-formats.js";
|
|
77
|
+
import { parseYAML } from "../yaml.js";
|
|
58
78
|
/** The first chant with `release.artifacts`, `chant release artifacts` and `artifact:<name>` in a forge or homebrew target's `assets` (#5151). */
|
|
59
79
|
export const RELEASE_ARTIFACTS_FLOOR = "0.124.101";
|
|
60
80
|
/** The variable naming the goreleaser binary the cut runs. */
|
|
61
81
|
export const GORELEASER_ENV = "CHANT_GORELEASER";
|
|
82
|
+
/** The first chant with `helm` and `nfpm` entries in `release.artifacts` (#5233). */
|
|
83
|
+
export const RELEASE_ARTIFACTS_PACKAGES_FLOOR = "0.124.102";
|
|
84
|
+
/** The variable naming the nfpm binary the cut runs (#5233). */
|
|
85
|
+
export const NFPM_ENV = "CHANT_NFPM";
|
|
86
|
+
/** The package formats an nfpm entry builds. */
|
|
87
|
+
export const NFPM_PACKAGERS = ["deb", "rpm", "apk", "archlinux", "ipk"];
|
|
88
|
+
/** Each packager's file extension. */
|
|
89
|
+
const NFPM_EXTENSIONS = { deb: "deb", rpm: "rpm", apk: "apk", archlinux: "pkg.tar.zst", ipk: "ipk" };
|
|
62
90
|
/**
|
|
63
91
|
* The `artifacts.json` types recorded from goreleaser by default: what its
|
|
64
92
|
* own release would upload. A `Binary` is recorded only when it sits at the
|
|
@@ -79,9 +107,12 @@ const PLATFORM = /^[a-z0-9]+\/[a-z0-9_]+(?:\/[a-z0-9]+)?$/;
|
|
|
79
107
|
const PLACEHOLDER = /\{([a-z]+)\}/g;
|
|
80
108
|
const OUTPUT_KEYS = new Set(["os", "arch", "ext", "label", "version"]);
|
|
81
109
|
const ARCHIVE_KEYS = new Set(["name", "os", "arch", "label", "version"]);
|
|
110
|
+
const NFPM_NAME_KEYS = new Set(["name", "version", "label", "os", "arch", "packager"]);
|
|
82
111
|
const outside = (p) => isAbsolute(p) || p.split(/[\\/]/).includes("..");
|
|
83
112
|
const isGoreleaser = (a) => "goreleaser" in a && a.goreleaser !== undefined;
|
|
84
113
|
const isChecksums = (a) => "checksums" in a && a.checksums !== undefined;
|
|
114
|
+
const isHelm = (a) => "helm" in a && a.helm !== undefined;
|
|
115
|
+
const isNfpm = (a) => "nfpm" in a && a.nfpm !== undefined;
|
|
85
116
|
/** An entry of files at `outputs`: built by its command, or (#5183) with no command, built before the cut. */
|
|
86
117
|
const isFiles = (a) => ("build" in a && a.build !== undefined) || ("outputs" in a && a.outputs !== undefined) || ("builtBy" in a && a.builtBy !== undefined);
|
|
87
118
|
const commandOf = (a) => ("build" in a ? a.build : undefined);
|
|
@@ -127,9 +158,9 @@ export function checkReleaseArtifacts(artifacts, o = {}) {
|
|
|
127
158
|
throw new ReleaseArtifactError("release-artifact-name-taken", `release.artifacts names "${a.name}" twice`);
|
|
128
159
|
if (o.imageNames?.includes(a.name))
|
|
129
160
|
throw new ReleaseArtifactError("release-artifact-name-taken", `release.artifacts names "${a.name}", which release.images names too, and a release records each name once`, "Rename one of them.");
|
|
130
|
-
const kinds = [isFiles(a), isGoreleaser(a), isChecksums(a)].filter(Boolean).length;
|
|
161
|
+
const kinds = [isFiles(a), isGoreleaser(a), isChecksums(a), isHelm(a), isNfpm(a)].filter(Boolean).length;
|
|
131
162
|
if (kinds !== 1)
|
|
132
|
-
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)} names ${kinds === 0 ? "none" : "more than one"} of outputs, goreleaser and checksums; name one`);
|
|
163
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)} names ${kinds === 0 ? "none" : "more than one"} of outputs, goreleaser, helm, nfpm and checksums; name one`);
|
|
133
164
|
if (isFiles(a)) {
|
|
134
165
|
const jobs = builtByOf(a);
|
|
135
166
|
if (jobs.length > 0 && commandOf(a) !== undefined)
|
|
@@ -186,6 +217,28 @@ export function checkReleaseArtifacts(artifacts, o = {}) {
|
|
|
186
217
|
if (a.goreleaser.types !== undefined && a.goreleaser.types.length === 0)
|
|
187
218
|
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: goreleaser.types is empty, so nothing would be recorded`);
|
|
188
219
|
}
|
|
220
|
+
else if (isHelm(a)) {
|
|
221
|
+
inside(a, "the chart directory", a.helm.chart);
|
|
222
|
+
inside(a, "the chart archive directory", a.helm.dir);
|
|
223
|
+
}
|
|
224
|
+
else if (isNfpm(a)) {
|
|
225
|
+
inside(a, "the nfpm config", a.nfpm.config);
|
|
226
|
+
inside(a, "the package directory", a.nfpm.dir);
|
|
227
|
+
const packagers = a.nfpm.packagers;
|
|
228
|
+
if (packagers !== undefined && (packagers.length === 0 || !packagers.every((p) => NFPM_PACKAGERS.includes(p)) || new Set(packagers).size !== packagers.length)) {
|
|
229
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: nfpm.packagers is a list of distinct ${NFPM_PACKAGERS.join(", ")}, not ${JSON.stringify(packagers)}`);
|
|
230
|
+
}
|
|
231
|
+
if (a.nfpm.platforms !== undefined && (a.nfpm.platforms.length === 0 || !a.nfpm.platforms.every((p) => PLATFORM.test(p)) || new Set(a.nfpm.platforms).size !== a.nfpm.platforms.length)) {
|
|
232
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: nfpm.platforms is a list of distinct os/arch such as linux/amd64, not ${JSON.stringify(a.nfpm.platforms)}`);
|
|
233
|
+
}
|
|
234
|
+
if (a.nfpm.fileName !== undefined) {
|
|
235
|
+
const unknown = placeholders(a.nfpm.fileName).filter((k) => !NFPM_NAME_KEYS.has(k));
|
|
236
|
+
if (unknown.length > 0 || /[\\/]/.test(a.nfpm.fileName))
|
|
237
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: nfpm.fileName ${a.nfpm.fileName} is not a file name holding {name}, {version}, {label}, {os}, {arch} and {packager}`);
|
|
238
|
+
if (a.nfpm.platforms === undefined && placeholders(a.nfpm.fileName).some((k) => k === "os" || k === "arch"))
|
|
239
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: nfpm.fileName ${a.nfpm.fileName} names a platform, and the entry has no platforms`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
189
242
|
else if (isChecksums(a)) {
|
|
190
243
|
inside(a, "the checksums file", a.checksums);
|
|
191
244
|
for (const n of a.of ?? []) {
|
|
@@ -345,6 +398,12 @@ export function buildReleaseArtifacts(i) {
|
|
|
345
398
|
else if (isGoreleaser(a)) {
|
|
346
399
|
files.push(...goreleaserFiles(a, i, baseEnv(), run).map((abs) => record(a.name, abs)));
|
|
347
400
|
}
|
|
401
|
+
else if (isHelm(a)) {
|
|
402
|
+
files.push(record(a.name, packHelmChart(a, i)));
|
|
403
|
+
}
|
|
404
|
+
else if (isNfpm(a)) {
|
|
405
|
+
files.push(...nfpmFiles(a, i, baseEnv, run).map((abs) => record(a.name, abs)));
|
|
406
|
+
}
|
|
348
407
|
else if (isChecksums(a)) {
|
|
349
408
|
const names = a.of ?? [...byEntry.keys()];
|
|
350
409
|
const covered = names.flatMap((n) => byEntry.get(n) ?? []);
|
|
@@ -410,6 +469,179 @@ function goreleaserFiles(a, i, env, run) {
|
|
|
410
469
|
return files.sort();
|
|
411
470
|
}
|
|
412
471
|
const shellWord = (s) => (/^[A-Za-z0-9_./:=,@+%-]+$/.test(s) ? s : `'${s.replace(/'/g, "'\\''")}'`);
|
|
472
|
+
/** A `filepath.Match` pattern as a regular expression: `*` and `?` within a segment, `[...]` a class. */
|
|
473
|
+
function globSegmentRe(pattern) {
|
|
474
|
+
let out = "";
|
|
475
|
+
for (let k = 0; k < pattern.length; k++) {
|
|
476
|
+
const c = pattern[k];
|
|
477
|
+
if (c === "*")
|
|
478
|
+
out += "[^/]*";
|
|
479
|
+
else if (c === "?")
|
|
480
|
+
out += "[^/]";
|
|
481
|
+
else if (c === "\\" && k + 1 < pattern.length)
|
|
482
|
+
out += `\\${pattern[++k]}`;
|
|
483
|
+
else if (c === "[") {
|
|
484
|
+
const end = pattern.indexOf("]", k + 1);
|
|
485
|
+
if (end < 0)
|
|
486
|
+
out += "\\[";
|
|
487
|
+
else {
|
|
488
|
+
out += `[${pattern.slice(k + 1, end).replace(/\\/g, "\\\\")}]`;
|
|
489
|
+
k = end;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
else
|
|
493
|
+
out += c.replace(/[.+^${}()|\]\\]/g, "\\$&");
|
|
494
|
+
}
|
|
495
|
+
return new RegExp(`^${out}$`);
|
|
496
|
+
}
|
|
497
|
+
/** The rules of a `.helmignore`, after helm's default. A `**` is refused, as helm refuses it. */
|
|
498
|
+
export function helmIgnoreRules(text, where) {
|
|
499
|
+
const rules = [];
|
|
500
|
+
for (const raw of ["templates/.?*", ...(text ?? "").split(/\r?\n/)]) {
|
|
501
|
+
let line = raw.trim();
|
|
502
|
+
if (line === "" || line.startsWith("#"))
|
|
503
|
+
continue;
|
|
504
|
+
if (line.includes("**"))
|
|
505
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where}: .helmignore has ${line}, and helm does not read **`, "Name the paths with * and ?, as helm does.");
|
|
506
|
+
const negate = line.startsWith("!");
|
|
507
|
+
if (negate)
|
|
508
|
+
line = line.slice(1);
|
|
509
|
+
const dirOnly = line.endsWith("/");
|
|
510
|
+
if (dirOnly)
|
|
511
|
+
line = line.replace(/\/+$/, "");
|
|
512
|
+
line = line.replace(/^\//, "");
|
|
513
|
+
if (line === "")
|
|
514
|
+
continue;
|
|
515
|
+
rules.push({ re: globSegmentRe(line), negate, dirOnly, base: !line.includes("/") });
|
|
516
|
+
}
|
|
517
|
+
return rules;
|
|
518
|
+
}
|
|
519
|
+
/** Whether helm leaves `rel` (a path from the chart's directory) out of the chart, as its ignore package decides. */
|
|
520
|
+
export function helmIgnored(rules, rel, dir) {
|
|
521
|
+
const name = rel.includes("/") ? rel.slice(rel.lastIndexOf("/") + 1) : rel;
|
|
522
|
+
for (const r of rules) {
|
|
523
|
+
if (r.dirOnly && !dir)
|
|
524
|
+
continue;
|
|
525
|
+
const hit = r.re.test(r.base ? name : rel);
|
|
526
|
+
if (r.negate ? !hit : hit)
|
|
527
|
+
return true;
|
|
528
|
+
}
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
/** Every file of the chart at `abs` that helm packs, from the chart's directory, sorted, `Chart.yaml` first. */
|
|
532
|
+
function helmChartFiles(abs, rules) {
|
|
533
|
+
const out = [];
|
|
534
|
+
const walk = (rel) => {
|
|
535
|
+
for (const e of readdirSync(rel ? resolve(abs, rel) : abs).sort()) {
|
|
536
|
+
const p = rel ? `${rel}/${e}` : e;
|
|
537
|
+
const st = statSync(resolve(abs, p));
|
|
538
|
+
if (helmIgnored(rules, p, st.isDirectory()))
|
|
539
|
+
continue;
|
|
540
|
+
if (st.isDirectory())
|
|
541
|
+
walk(p);
|
|
542
|
+
else if (st.isFile())
|
|
543
|
+
out.push(p);
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
walk("");
|
|
547
|
+
return [...out.filter((p) => p === "Chart.yaml"), ...out.filter((p) => p !== "Chart.yaml")];
|
|
548
|
+
}
|
|
549
|
+
/** Pack a `helm` entry's chart into `<dir>/<name>-<version>.tgz`, as `helm package --version` would, every entry dated `SOURCE_DATE_EPOCH`. Returns the archive. */
|
|
550
|
+
function packHelmChart(a, i) {
|
|
551
|
+
const where = `release.artifacts "${a.name}"`;
|
|
552
|
+
const version = labelVersion(i.label);
|
|
553
|
+
if (i.label === null || version === null)
|
|
554
|
+
throw new ReleaseArtifactError("release-artifact-no-label", `${where} packs a Helm chart, whose version is the release's label from its first digit, and the cut has ${i.label === null ? "no label" : `the label ${i.label}, which has no digit`}`, "Cut the release with a label such as v1.4.0.");
|
|
555
|
+
const dir = resolve(i.cwd, a.helm.chart);
|
|
556
|
+
const chartFile = resolve(dir, "Chart.yaml");
|
|
557
|
+
if (!existsSync(chartFile))
|
|
558
|
+
throw new ReleaseArtifactError("release-artifact-no-output", `${where}: ${posix.join(a.helm.chart, "Chart.yaml")} does not exist, so ${a.helm.chart} is not a Helm chart`, "Set helm.chart to the directory that holds the chart's Chart.yaml.");
|
|
559
|
+
const text = readFileSync(chartFile, "utf-8");
|
|
560
|
+
let name;
|
|
561
|
+
try {
|
|
562
|
+
name = parseYAML(text).name;
|
|
563
|
+
}
|
|
564
|
+
catch (err) {
|
|
565
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where}: ${posix.join(a.helm.chart, "Chart.yaml")} is not YAML chant can read: ${err instanceof Error ? err.message : String(err)}`);
|
|
566
|
+
}
|
|
567
|
+
if (typeof name !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(name))
|
|
568
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where}: ${posix.join(a.helm.chart, "Chart.yaml")} names no chart name helm takes`, "Give the chart a name of letters, digits, '.', '_' and '-'.");
|
|
569
|
+
let chart;
|
|
570
|
+
try {
|
|
571
|
+
chart = stampVersionFile({ path: "Chart.yaml", field: "version" }, text, version);
|
|
572
|
+
if (a.helm.appVersion)
|
|
573
|
+
chart = stampVersionFile({ path: "Chart.yaml", field: "appVersion" }, chart, i.label);
|
|
574
|
+
}
|
|
575
|
+
catch (err) {
|
|
576
|
+
const e = err;
|
|
577
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where}: ${e.message ?? String(err)}`, e.fix);
|
|
578
|
+
}
|
|
579
|
+
const ignore = existsSync(resolve(dir, ".helmignore")) ? readFileSync(resolve(dir, ".helmignore"), "utf-8") : null;
|
|
580
|
+
const files = helmChartFiles(dir, helmIgnoreRules(ignore, where));
|
|
581
|
+
const entries = files.map((f) => ({ name: `${name}/${f}`, abs: resolve(dir, f), ...(f === "Chart.yaml" ? { bytes: Buffer.from(chart, "utf-8") } : {}) }));
|
|
582
|
+
const archive = resolve(i.cwd, a.helm.dir ?? "dist", `${name}-${version}.tgz`);
|
|
583
|
+
mkdirSync(dirname(archive), { recursive: true });
|
|
584
|
+
writeFileSync(archive, tarGzArchive(entries, i.sourceDateEpoch));
|
|
585
|
+
return archive;
|
|
586
|
+
}
|
|
587
|
+
/** The top-level `version` of an nfpm config, unquoted, or null. */
|
|
588
|
+
export function nfpmConfigVersion(text) {
|
|
589
|
+
const m = /^version:[ \t]*(.*?)[ \t]*(?:#.*)?$/m.exec(text);
|
|
590
|
+
if (!m)
|
|
591
|
+
return null;
|
|
592
|
+
return m[1].replace(/^(["'])(.*)\1$/, "$2");
|
|
593
|
+
}
|
|
594
|
+
/** Whether an nfpm config's version carries the release's: it names the variable chant sets, or is the label or its version. */
|
|
595
|
+
export function nfpmVersionFollowsLabel(version, label, labelVer) {
|
|
596
|
+
if (version === null)
|
|
597
|
+
return false;
|
|
598
|
+
return /\$\{?CHANT_RELEASE_(VERSION|LABEL)\}?/.test(version) || version === label || version === labelVer;
|
|
599
|
+
}
|
|
600
|
+
/** Run nfpm for each platform and packager of an `nfpm` entry and list the packages it wrote. */
|
|
601
|
+
function nfpmFiles(a, i, baseEnv, run) {
|
|
602
|
+
const where = `release.artifacts "${a.name}"`;
|
|
603
|
+
const version = labelVersion(i.label);
|
|
604
|
+
if (i.label === null || version === null)
|
|
605
|
+
throw new ReleaseArtifactError("release-artifact-no-label", `${where} is packaged by nfpm, whose packages carry the release's label as their version, and the cut has ${i.label === null ? "no label" : `the label ${i.label}, which has no digit`}`, "Cut the release with a label such as v1.4.0.");
|
|
606
|
+
const config = a.nfpm.config ?? "nfpm.yaml";
|
|
607
|
+
const configAbs = resolve(i.cwd, config);
|
|
608
|
+
if (!existsSync(configAbs))
|
|
609
|
+
throw new ReleaseArtifactError("release-artifact-no-output", `${where}: the nfpm config ${config} does not exist`, "Set nfpm.config to the member's nfpm config.");
|
|
610
|
+
const declared = nfpmConfigVersion(readFileSync(configAbs, "utf-8"));
|
|
611
|
+
if (!nfpmVersionFollowsLabel(declared, i.label, version)) {
|
|
612
|
+
throw new ReleaseArtifactError("release-artifact-version-mismatch", `${where}: ${config} gives the packages the version ${JSON.stringify(declared)}, and the release is labelled ${i.label}, so they would not carry the release's version`, 'Set the version in the nfpm config to the one chant passes: version: "${CHANT_RELEASE_VERSION}".');
|
|
613
|
+
}
|
|
614
|
+
const env0 = baseEnv();
|
|
615
|
+
const bin = env0[NFPM_ENV] || "nfpm";
|
|
616
|
+
const files = [];
|
|
617
|
+
for (const platform of a.nfpm.platforms ?? [null]) {
|
|
618
|
+
for (const packager of a.nfpm.packagers ?? ["deb", "rpm"]) {
|
|
619
|
+
const env = baseEnv();
|
|
620
|
+
env.CHANT_RELEASE_VERSION = version;
|
|
621
|
+
const values = { name: a.name, label: i.label, version, packager };
|
|
622
|
+
if (platform !== null) {
|
|
623
|
+
const p = platformValues(platform);
|
|
624
|
+
Object.assign(values, { os: p.os, arch: p.arch });
|
|
625
|
+
env.CHANT_RELEASE_OS = p.os;
|
|
626
|
+
env.CHANT_RELEASE_ARCH = p.arch;
|
|
627
|
+
env.CHANT_RELEASE_EXT = p.ext;
|
|
628
|
+
}
|
|
629
|
+
const base = fill(a.nfpm.fileName ?? (platform !== null ? "{name}_{version}_{arch}" : "{name}_{version}"), values, `${where} nfpm.fileName`);
|
|
630
|
+
const target = posix.join((a.nfpm.dir ?? "dist").replace(/\\/g, "/"), `${base}.${NFPM_EXTENSIONS[packager]}`);
|
|
631
|
+
mkdirSync(dirname(resolve(i.cwd, target)), { recursive: true });
|
|
632
|
+
const command = [bin === "nfpm" ? bin : shellWord(bin), "package", "--config", shellWord(config), "--packager", packager, "--target", shellWord(target)].join(" ");
|
|
633
|
+
const on = `${packager}${platform !== null ? ` for ${platform}` : ""}`;
|
|
634
|
+
const status = run(command, { cwd: i.cwd, env });
|
|
635
|
+
if (status !== 0)
|
|
636
|
+
throw new ReleaseArtifactError("release-artifact-build-failed", `nfpm for artifact "${a.name}" (${on}) exited ${status ?? "with a signal"}: ${command}`);
|
|
637
|
+
const abs = resolve(i.cwd, target);
|
|
638
|
+
if (!existsSync(abs) || !statSync(abs).isFile())
|
|
639
|
+
throw new ReleaseArtifactError("release-artifact-no-output", `nfpm for artifact "${a.name}" (${on}) wrote no ${target}`);
|
|
640
|
+
files.push(abs);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return files;
|
|
644
|
+
}
|
|
413
645
|
const modeOf = (abs) => (statSync(abs).mode & 0o111 ? 0o755 : 0o644);
|
|
414
646
|
function tarHeader(name, size, mode, mtime) {
|
|
415
647
|
const h = Buffer.alloc(512);
|
|
@@ -444,7 +676,7 @@ function tarHeader(name, size, mode, mtime) {
|
|
|
444
676
|
export function tarGzArchive(entries, mtime) {
|
|
445
677
|
const parts = [];
|
|
446
678
|
for (const e of entries) {
|
|
447
|
-
const data = readFileSync(e.abs);
|
|
679
|
+
const data = e.bytes ?? readFileSync(e.abs);
|
|
448
680
|
parts.push(tarHeader(e.name, data.length, modeOf(e.abs), mtime), data, Buffer.alloc((512 - (data.length % 512)) % 512));
|
|
449
681
|
}
|
|
450
682
|
parts.push(Buffer.alloc(1024));
|
|
@@ -484,7 +716,7 @@ export function zipArchive(entries, mtime) {
|
|
|
484
716
|
const central = [];
|
|
485
717
|
let offset = 0;
|
|
486
718
|
for (const e of entries) {
|
|
487
|
-
const data = readFileSync(e.abs);
|
|
719
|
+
const data = "abs" in e ? (e.bytes ?? readFileSync(e.abs)) : e.bytes;
|
|
488
720
|
const packed = deflateRawSync(data, { level: 9 });
|
|
489
721
|
const name = Buffer.from(e.name, "utf-8");
|
|
490
722
|
const crc = crc32(data);
|
|
@@ -512,7 +744,7 @@ export function zipArchive(entries, mtime) {
|
|
|
512
744
|
c.writeUInt32LE(packed.length, 20);
|
|
513
745
|
c.writeUInt32LE(data.length, 24);
|
|
514
746
|
c.writeUInt16LE(name.length, 28);
|
|
515
|
-
c.writeUInt32LE(((0o100000 | modeOf(e.abs)) << 16) >>> 0, 38);
|
|
747
|
+
c.writeUInt32LE(((0o100000 | ("abs" in e ? modeOf(e.abs) : 0o644)) << 16) >>> 0, 38);
|
|
516
748
|
c.writeUInt32LE(offset, 42);
|
|
517
749
|
locals.push(local, name, packed);
|
|
518
750
|
central.push(c, name);
|
|
@@ -563,6 +795,10 @@ export function copyArtifactFiles(files, from, to, o = {}) {
|
|
|
563
795
|
copyFileSync(src, dest);
|
|
564
796
|
}
|
|
565
797
|
}
|
|
798
|
+
/** Whether any entry is packaged by nfpm, for the workflow's install step (#5233). */
|
|
799
|
+
export function usesNfpm(artifacts) {
|
|
800
|
+
return artifacts.some(isNfpm);
|
|
801
|
+
}
|
|
566
802
|
/** Whether any entry is built by goreleaser, for the workflow's install step. */
|
|
567
803
|
export function usesGoreleaser(artifacts) {
|
|
568
804
|
return artifacts.some(isGoreleaser);
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
import { type Release, type ReleaseArtifact, type ReleaseCut, type ReleaseCutGreen, type ReleaseCutIntent, type ReleaseCutOverride, type ReleasePublish, type ReleaseTarget } from "./release-store.js";
|
|
62
62
|
import type { CompiledTarget, TargetCompiler } from "../components/release-compile.js";
|
|
63
63
|
import type { ForgeChecksReader, ReleaseGreenSource } from "./release-green.js";
|
|
64
|
+
import type { NpmPublishedLookup } from "./publish-npm.js";
|
|
64
65
|
/** The first chant that cuts from a lane's green tag and writes `lane` on the cut line (#4692). */
|
|
65
66
|
export declare const RELEASE_CUT_LANE_FLOOR = "0.124.64";
|
|
66
67
|
/** The first chant that cuts a commit that is not green under an override and writes `override` on the cut line (#4693). */
|
|
@@ -80,7 +81,9 @@ export type ReleaseCutCode = "not-a-git-repository" | "release-commit-not-green"
|
|
|
80
81
|
/** #5183: an entry with no build command whose files are not there, or are read from a checkout of another commit. */
|
|
81
82
|
| "release-artifact-not-built" | "release-artifact-wrong-commit" | "release-version-no-label" | "release-version-label-invalid" | "release-version-no-package" | "release-version-invalid" | "release-version-no-file" | "release-version-no-field" | "release-version-format-unknown" | "release-unsigned" | "release-signer-refused" | "declaration-invalid"
|
|
82
83
|
/** #4941: the npm target's image check, run by the cut (./publish-npm.ts `checkPackageImages`). */
|
|
83
|
-
| "publish-npm-carries-image" | "publish-npm-pack-failed"
|
|
84
|
+
| "publish-npm-carries-image" | "publish-npm-pack-failed"
|
|
85
|
+
/** #5230: an npm target names a package the registry has never published, or the registry can't say. */
|
|
86
|
+
| "publish-npm-never-published" | "publish-npm-registry-unreadable";
|
|
84
87
|
export declare class ReleaseCutError extends Error {
|
|
85
88
|
readonly code: ReleaseCutCode;
|
|
86
89
|
readonly fix?: string | undefined;
|
|
@@ -112,6 +115,8 @@ export interface CutRequest {
|
|
|
112
115
|
* targets; with none, and no `release.images`, it has nothing to release.
|
|
113
116
|
*/
|
|
114
117
|
publishes?: readonly ReleasePublish[];
|
|
118
|
+
/** Whether the registry has ever published a package, for the cut's first-publish check (#5230). Default: `npm view`. */
|
|
119
|
+
npmPublished?: NpmPublishedLookup;
|
|
115
120
|
now?: () => Date;
|
|
116
121
|
/** The process environment the CI run is read from. */
|
|
117
122
|
env?: NodeJS.ProcessEnv;
|
|
@@ -389,6 +389,21 @@ async function prepare(req, record = false) {
|
|
|
389
389
|
if (artifactRelease && (req.publishes ?? []).length === 0 && !req.buildImages && !req.buildArtifacts) {
|
|
390
390
|
throw new ReleaseCutError("release-no-environments", "this member's chant.config.ts declares no environments and no release.publish target, so there is nothing to release", "Declare where the release publishes (release.publish: [{ type: \"npm\", packages: [\".\"] }]), or the environments it is compiled for in promotion order (environments: [\"dev\", \"staging\", \"prod\"]).");
|
|
391
391
|
}
|
|
392
|
+
// #5230: a package npm has never had can't be published by trusted publishing, so the cut stops before the label is spent.
|
|
393
|
+
// The config is loaded fresh through the normal loader every time, so a target that comes from an imported preset is seen too.
|
|
394
|
+
{
|
|
395
|
+
const { loadChantConfig } = await import("../config.js");
|
|
396
|
+
const { checkPackagesPublished, npmPublishedLookup } = await import("./publish-npm.js");
|
|
397
|
+
const { PublishTargetError } = await import("./release-publish.js");
|
|
398
|
+
try {
|
|
399
|
+
checkPackagesPublished((await loadChantConfig(cwd, { fresh: true })).config.release?.publish ?? [], cwd, req.npmPublished ?? npmPublishedLookup());
|
|
400
|
+
}
|
|
401
|
+
catch (err) {
|
|
402
|
+
if (err instanceof PublishTargetError)
|
|
403
|
+
throw new ReleaseCutError(err.code, `no release was cut: ${err.message}`, err.fix);
|
|
404
|
+
throw err;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
392
407
|
// #4657: the images first, so the build command that packs a package can pin their digests.
|
|
393
408
|
const builtImages = req.buildImages ? await req.buildImages(commit) : [];
|
|
394
409
|
// #5151: the files, after the images and before the build command.
|
|
@@ -33,12 +33,11 @@
|
|
|
33
33
|
* cosign signs with (`signing-oidc`) and cosign 3 (`signing-cosign`).
|
|
34
34
|
*/
|
|
35
35
|
import { execFileSync, spawn } from "node:child_process";
|
|
36
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
36
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
37
37
|
import { isAbsolute, join, resolve } from "node:path";
|
|
38
38
|
import { createRedactor, readCredential } from "./publish-credentials.js";
|
|
39
|
-
import { NEXT_RELEASE } from "../release-floors.js";
|
|
40
39
|
/** The first chant with `chant release doctor`, which checks each `release.publish` target before a cut, and whose `chant release workflow` runs it in a dispatched release's cut job (`release.workflow.doctor`) (#5161). */
|
|
41
|
-
export const RELEASE_DOCTOR_FLOOR =
|
|
40
|
+
export const RELEASE_DOCTOR_FLOOR = "0.124.101";
|
|
42
41
|
export const DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
|
|
43
42
|
function defaultRun(bin, args, opts) {
|
|
44
43
|
return new Promise((done) => {
|
|
@@ -134,6 +133,14 @@ async function checkTarget(decl, ctx) {
|
|
|
134
133
|
return [await checkMcpRegistry(decl, ctx)];
|
|
135
134
|
case "index":
|
|
136
135
|
return [await checkIndex(decl, ctx)];
|
|
136
|
+
case "helm":
|
|
137
|
+
return checkHelm(decl, ctx);
|
|
138
|
+
case "maven":
|
|
139
|
+
return [await checkMaven(decl, ctx)];
|
|
140
|
+
case "nuget":
|
|
141
|
+
return [await checkNuget(decl, ctx)];
|
|
142
|
+
case "rubygems":
|
|
143
|
+
return [await checkRubygems(decl, ctx)];
|
|
137
144
|
}
|
|
138
145
|
}
|
|
139
146
|
/**
|
|
@@ -324,9 +331,9 @@ async function checkNpm(decl, ctx) {
|
|
|
324
331
|
if (packument.status === 404) {
|
|
325
332
|
checks.push({
|
|
326
333
|
check: "npm-registry",
|
|
327
|
-
status:
|
|
328
|
-
message: `${name} is not on ${registry} yet. npm makes its first version latest as soon as it stages, and trusted publishing can't publish it, since a trusted publisher is set on a package that exists${user ? `; npm's config here signs in as ${user}, which can publish it` : ""}`,
|
|
329
|
-
fix: `Publish
|
|
334
|
+
status: "fail",
|
|
335
|
+
message: `${name} is not on ${registry} yet (publish-npm-never-published, which refuses the cut). npm makes its first version latest as soon as it stages, and trusted publishing can't publish it, since a trusted publisher is set on a package that exists${user ? `; npm's config here signs in as ${user}, which can publish it by hand` : ""}`,
|
|
336
|
+
fix: `Publish one placeholder version by hand (npm login, then npm publish), then add the trusted publisher on ${npmjs ? "npmjs.com under the package's Settings" : "the registry"}.`,
|
|
330
337
|
});
|
|
331
338
|
}
|
|
332
339
|
else if (!exists) {
|
|
@@ -606,6 +613,32 @@ async function checkHomebrew(decl, ctx) {
|
|
|
606
613
|
* scopes. A fine-grained or app token's rights on a repository its owner
|
|
607
614
|
* does not own are not shown.
|
|
608
615
|
*/
|
|
616
|
+
/**
|
|
617
|
+
* A helm target (#5233): the registry's credentials as the oci target's
|
|
618
|
+
* checks read them, for the repository the charts go under, and the token
|
|
619
|
+
* that pushes the index and whether it sees the repository.
|
|
620
|
+
*/
|
|
621
|
+
async function checkHelm(decl, ctx) {
|
|
622
|
+
const out = [];
|
|
623
|
+
if (decl.oci) {
|
|
624
|
+
const oci = await checkOci({ type: "oci", image: "", repository: decl.oci.repository, ...(decl.oci.usernameEnv ? { usernameEnv: decl.oci.usernameEnv } : {}), ...(decl.oci.passwordEnv ? { passwordEnv: decl.oci.passwordEnv } : {}) }, ctx);
|
|
625
|
+
out.push({ ...oci, kind: "helm", name: `helm oci ${decl.oci.repository}` });
|
|
626
|
+
}
|
|
627
|
+
if (decl.index) {
|
|
628
|
+
const checks = [];
|
|
629
|
+
const tokenEnv = decl.index.tokenEnv ?? "GITHUB_TOKEN";
|
|
630
|
+
const branch = decl.index.branch ?? "gh-pages";
|
|
631
|
+
out.push({ kind: "helm", name: `helm index ${decl.index.repo}@${branch}`, checks });
|
|
632
|
+
const token = readCredential(ctx.env, [tokenEnv], ctx.redactor);
|
|
633
|
+
if (!token)
|
|
634
|
+
checks.push(missing(ctx, "helm-index-credentials", `${tokenEnv} is not set`, `Set ${tokenEnv} to a token that may push to ${branch} of ${decl.index.repo}.`));
|
|
635
|
+
else {
|
|
636
|
+
const { githubApi } = await import("./publish-github.js");
|
|
637
|
+
checks.push(await repoAccess(ctx, { forge: "github", api: githubApi(decl.index.api, ctx.env), repo: decl.index.repo, token: token.value, check: "helm-index-access", tokenFrom: token.from }));
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
return out;
|
|
641
|
+
}
|
|
609
642
|
async function checkIndex(decl, ctx) {
|
|
610
643
|
const { indexSettings } = await import("./publish-index.js");
|
|
611
644
|
const { githubApi } = await import("./publish-github.js");
|
|
@@ -940,6 +973,175 @@ async function checkPypi(decl, ctx) {
|
|
|
940
973
|
: { check: "pypi-trusted-publisher", status: "fail", message: `${index.label} gave no upload token for this run (${ex.status}${ex.text ? `: ${short(ex.text)}` : ""})`, fix: `Register this workflow as a trusted publisher${name ? ` of ${name}` : ""} at ${index.site}/manage/account/publishing/.` });
|
|
941
974
|
return t;
|
|
942
975
|
}
|
|
976
|
+
// Maven Central, NuGet and RubyGems (#5232)
|
|
977
|
+
/** The files with `ext` the build already wrote at the paths `entries` names; `artifact:` entries are the cut's, so none yet. */
|
|
978
|
+
function builtFiles(cwd, entries, ext) {
|
|
979
|
+
const out = [];
|
|
980
|
+
for (const e of entries) {
|
|
981
|
+
if (e.startsWith("artifact:"))
|
|
982
|
+
continue;
|
|
983
|
+
const abs = resolve(cwd, e);
|
|
984
|
+
if (!existsSync(abs))
|
|
985
|
+
continue;
|
|
986
|
+
if (statSync(abs).isDirectory())
|
|
987
|
+
for (const f of readdirSync(abs).filter((n) => n.endsWith(ext)).sort())
|
|
988
|
+
out.push({ path: join(e, f), abs: join(abs, f) });
|
|
989
|
+
else
|
|
990
|
+
out.push({ path: e, abs });
|
|
991
|
+
}
|
|
992
|
+
return out;
|
|
993
|
+
}
|
|
994
|
+
async function checkMaven(decl, ctx) {
|
|
995
|
+
const { CENTRAL_PORTAL, MAVEN_CENTRAL_REPOSITORY, mavenPasswordEnv, mavenUsernameEnv, readMavenBundle } = await import("./publish-maven.js");
|
|
996
|
+
const checks = [];
|
|
997
|
+
const t = { kind: "maven", name: `maven ${decl.bundle}`, checks };
|
|
998
|
+
if (decl.bundle.startsWith("artifact:") || !existsSync(resolve(ctx.cwd, decl.bundle))) {
|
|
999
|
+
checks.push({ check: "maven-bundle", status: "unknown", message: `${decl.bundle} is not built yet; the publish reads its components and their signatures` });
|
|
1000
|
+
}
|
|
1001
|
+
else {
|
|
1002
|
+
try {
|
|
1003
|
+
const b = readMavenBundle({ cwd: ctx.cwd, release: { artifactDigests: [] } }, decl.bundle);
|
|
1004
|
+
t.name = `maven ${b.components.map((c) => `${c.groupId}:${c.artifactId}`).join(", ")}`;
|
|
1005
|
+
checks.push({ check: "maven-bundle", status: "ok", message: `holds ${b.components.map((c) => `${c.groupId}:${c.artifactId}:${c.version}`).join(", ")}, each file signed` });
|
|
1006
|
+
const repository = (decl.repository ?? MAVEN_CENTRAL_REPOSITORY).replace(/\/*$/, "/");
|
|
1007
|
+
const there = [];
|
|
1008
|
+
for (const c of b.components) {
|
|
1009
|
+
const res = await answer(ctx, `${repository}${c.groupId.split(".").join("/")}/${c.artifactId}/${c.version}/${c.artifactId}-${c.version}.pom`, { method: "GET", headers: {} });
|
|
1010
|
+
if (res.status === 200)
|
|
1011
|
+
there.push(`${c.groupId}:${c.artifactId}:${c.version}`);
|
|
1012
|
+
}
|
|
1013
|
+
if (there.length > 0)
|
|
1014
|
+
checks.push({ check: "maven-versions", status: "warn", message: `the repository already serves ${there.join(", ")}; Maven Central takes no version twice` });
|
|
1015
|
+
}
|
|
1016
|
+
catch (err) {
|
|
1017
|
+
checks.push({ check: "maven-bundle", status: "fail", message: err instanceof Error ? err.message : String(err), ...(err.fix ? { fix: err.fix } : {}) });
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
const user = mavenUsernameEnv(decl);
|
|
1021
|
+
const pass = mavenPasswordEnv(decl);
|
|
1022
|
+
const set = Boolean(readCredential(ctx.env, [user], ctx.redactor)) && Boolean(readCredential(ctx.env, [pass], ctx.redactor));
|
|
1023
|
+
checks.push(set
|
|
1024
|
+
? { check: "maven-token", status: "unknown", message: `the user token in ${user} and ${pass} is set; whether the Central Portal takes it, and for which namespace, shows at the stage's upload` }
|
|
1025
|
+
: missing(ctx, "maven-token", `${user} and ${pass} are not both set`, `Generate a user token at ${CENTRAL_PORTAL}/account and set ${user} and ${pass}.`));
|
|
1026
|
+
return t;
|
|
1027
|
+
}
|
|
1028
|
+
async function checkNuget(decl, ctx) {
|
|
1029
|
+
const { NUGET_AUDIENCE, NUGET_ID_TOKEN_ENV, NUGET_ORG, nugetAuth, nugetFeed, nugetTokenEnv, nugetUserEnv, readNupkg } = await import("./publish-nuget.js");
|
|
1030
|
+
const feed = nugetFeed(decl);
|
|
1031
|
+
const checks = [];
|
|
1032
|
+
const t = { kind: "nuget", name: `nuget ${feed.label}`, checks };
|
|
1033
|
+
const ids = [];
|
|
1034
|
+
for (const f of builtFiles(ctx.cwd, decl.packages, ".nupkg")) {
|
|
1035
|
+
try {
|
|
1036
|
+
ids.push(readNupkg(f.path, f.abs).id);
|
|
1037
|
+
}
|
|
1038
|
+
catch (err) {
|
|
1039
|
+
checks.push({ check: "nuget-package", status: "fail", message: err instanceof Error ? err.message : String(err) });
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
if (ids.length === 0)
|
|
1043
|
+
checks.push({ check: "nuget-package", status: "unknown", message: "no package is built yet, so the ids can't be looked up" });
|
|
1044
|
+
else
|
|
1045
|
+
t.name = `nuget ${feed.label} ${[...new Set(ids)].join(", ")}`;
|
|
1046
|
+
for (const id of new Set(ids)) {
|
|
1047
|
+
const res = await answer(ctx, `${feed.flat}${id.toLowerCase()}/index.json`, { method: "GET", headers: { accept: "application/json" } });
|
|
1048
|
+
checks.push(res.status === 200
|
|
1049
|
+
? { check: "nuget-package", status: "ok", message: `${feed.label} has the package ${id}` }
|
|
1050
|
+
: res.status === 404
|
|
1051
|
+
? { check: "nuget-package", status: "warn", message: `${feed.label} has no package ${id} yet; the first push creates it`, fix: feed.nugetOrg ? "The key's or the trusted publishing policy's scope must allow pushing new packages." : undefined }
|
|
1052
|
+
: { check: "nuget-package", status: "unknown", message: `${feed.flat}${id.toLowerCase()}/index.json answered ${res.status}` });
|
|
1053
|
+
}
|
|
1054
|
+
const auth = nugetAuth(decl, ctx.env);
|
|
1055
|
+
if (auth === "token") {
|
|
1056
|
+
const tokenName = nugetTokenEnv(decl);
|
|
1057
|
+
checks.push(readCredential(ctx.env, [tokenName], ctx.redactor)
|
|
1058
|
+
? { check: "nuget-token", status: "unknown", message: `the API key in ${tokenName} is set; ${feed.label} has no read-only check of a key, so whether it may push shows at the push` }
|
|
1059
|
+
: missing(ctx, "nuget-token", `${tokenName} is not set${feed.nugetOrg ? " and there is no OIDC ID token for trusted publishing" : ""}`, `Set ${tokenName} to an API key that may push the packages${feed.nugetOrg ? ", or publish with trusted publishing from a CI job with an OIDC ID token" : ""}.`));
|
|
1060
|
+
return t;
|
|
1061
|
+
}
|
|
1062
|
+
const userName = nugetUserEnv(decl);
|
|
1063
|
+
const user = readCredential(ctx.env, [userName], ctx.redactor);
|
|
1064
|
+
if (!user) {
|
|
1065
|
+
checks.push(missing(ctx, "nuget-trusted-publisher", `${userName} is not set, and trusted publishing names the nuget.org user whose policy trusts the workflow`, `Set ${userName} to that user's profile name.`));
|
|
1066
|
+
return t;
|
|
1067
|
+
}
|
|
1068
|
+
if (!ctx.environment.ci && !ctx.env[NUGET_ID_TOKEN_ENV]) {
|
|
1069
|
+
checks.push({ check: "nuget-trusted-publisher", status: "unknown", message: `whether nuget.org takes this workflow as a trusted publisher can only be tested by ${onlyTheWorkflow(ctx)}, with its OIDC token` });
|
|
1070
|
+
return t;
|
|
1071
|
+
}
|
|
1072
|
+
const tok = await idToken(ctx, NUGET_AUDIENCE, NUGET_ID_TOKEN_ENV);
|
|
1073
|
+
if ("none" in tok) {
|
|
1074
|
+
checks.push({ check: "nuget-trusted-publisher", status: "fail", message: tok.none, fix: `Give the job permissions: id-token: write, or declare ${NUGET_ID_TOKEN_ENV} under the GitLab job's id_tokens with aud: ${NUGET_AUDIENCE}.` });
|
|
1075
|
+
return t;
|
|
1076
|
+
}
|
|
1077
|
+
const ex = await answer(ctx, NUGET_ORG.token, { method: "POST", headers: { "content-type": "application/json", authorization: `Bearer ${tok.token}` }, body: JSON.stringify({ username: user.value, tokenType: "ApiKey" }) });
|
|
1078
|
+
const value = ex.json?.apiKey;
|
|
1079
|
+
if (typeof value === "string")
|
|
1080
|
+
ctx.redactor.add(value);
|
|
1081
|
+
checks.push(ex.status === 200 && typeof value === "string"
|
|
1082
|
+
? { check: "nuget-trusted-publisher", status: "ok", message: "nuget.org takes this workflow as a trusted publisher" }
|
|
1083
|
+
: { check: "nuget-trusted-publisher", status: "fail", message: `nuget.org gave no API key for this run (${ex.status}${ex.text ? `: ${short(ex.text)}` : ""})`, fix: `Add a trusted publishing policy on nuget.org for this repository and workflow file, created by the user in ${userName}.` });
|
|
1084
|
+
return t;
|
|
1085
|
+
}
|
|
1086
|
+
async function checkRubygems(decl, ctx) {
|
|
1087
|
+
const { RUBYGEMS_AUDIENCE, RUBYGEMS_ID_TOKEN_ENV, readGem, rubygemsAuth, rubygemsHost, rubygemsTokenEnv } = await import("./publish-rubygems.js");
|
|
1088
|
+
const host = rubygemsHost(decl);
|
|
1089
|
+
const label = decl.host ? new URL(host).host : "RubyGems.org";
|
|
1090
|
+
const checks = [];
|
|
1091
|
+
const t = { kind: "rubygems", name: `rubygems ${label}`, checks };
|
|
1092
|
+
const names = new Set();
|
|
1093
|
+
for (const f of builtFiles(ctx.cwd, decl.gems, ".gem")) {
|
|
1094
|
+
try {
|
|
1095
|
+
names.add(readGem(f.path, f.abs).name);
|
|
1096
|
+
}
|
|
1097
|
+
catch (err) {
|
|
1098
|
+
checks.push({ check: "rubygems-gem", status: "fail", message: err instanceof Error ? err.message : String(err) });
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
if (names.size === 0) {
|
|
1102
|
+
for (const spec of readdirSync(ctx.cwd).filter((n) => n.endsWith(".gemspec"))) {
|
|
1103
|
+
const m = /\.name\s*=\s*["']([^"']+)["']/.exec(readFileSync(join(ctx.cwd, spec), "utf-8"));
|
|
1104
|
+
names.add(m ? m[1] : spec.slice(0, -".gemspec".length));
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
if (names.size === 0)
|
|
1108
|
+
checks.push({ check: "rubygems-gem", status: "unknown", message: "no gem is built and there is no .gemspec here, so the gem can't be looked up" });
|
|
1109
|
+
else
|
|
1110
|
+
t.name = `rubygems ${label} ${[...names].join(", ")}`;
|
|
1111
|
+
for (const name of names) {
|
|
1112
|
+
const res = await answer(ctx, `${host}/api/v1/versions/${encodeURIComponent(name)}.json`, { method: "GET", headers: { accept: "application/json" } });
|
|
1113
|
+
checks.push(res.status === 200
|
|
1114
|
+
? { check: "rubygems-gem", status: "ok", message: `${label} has the gem ${name}` }
|
|
1115
|
+
: res.status === 404
|
|
1116
|
+
? { check: "rubygems-gem", status: "warn", message: `${label} has no gem ${name} yet; the first push creates it`, fix: decl.host ? undefined : `For trusted publishing, add a pending trusted publisher for ${name} on RubyGems.org.` }
|
|
1117
|
+
: { check: "rubygems-gem", status: "unknown", message: `${host}/api/v1/versions/${name}.json answered ${res.status}` });
|
|
1118
|
+
}
|
|
1119
|
+
const auth = rubygemsAuth(decl, ctx.env);
|
|
1120
|
+
if (auth === "token") {
|
|
1121
|
+
const tokenName = rubygemsTokenEnv(decl);
|
|
1122
|
+
checks.push(readCredential(ctx.env, [tokenName], ctx.redactor)
|
|
1123
|
+
? { check: "rubygems-token", status: "unknown", message: `the API key in ${tokenName} is set; ${label} has no read-only check of a key, so whether it may push shows at the push` }
|
|
1124
|
+
: missing(ctx, "rubygems-token", `${tokenName} is not set${decl.host ? "" : " and there is no OIDC ID token for trusted publishing"}`, `Set ${tokenName} to an API key with the push scope${decl.host ? "" : ", or publish with trusted publishing from a GitHub Actions job with id-token: write"}.`));
|
|
1125
|
+
return t;
|
|
1126
|
+
}
|
|
1127
|
+
if (!ctx.environment.ci && !ctx.env[RUBYGEMS_ID_TOKEN_ENV]) {
|
|
1128
|
+
checks.push({ check: "rubygems-trusted-publisher", status: "unknown", message: `whether RubyGems.org takes this workflow as a trusted publisher can only be tested by ${onlyTheWorkflow(ctx)}, with its OIDC token` });
|
|
1129
|
+
return t;
|
|
1130
|
+
}
|
|
1131
|
+
const tok = await idToken(ctx, RUBYGEMS_AUDIENCE, RUBYGEMS_ID_TOKEN_ENV);
|
|
1132
|
+
if ("none" in tok) {
|
|
1133
|
+
checks.push({ check: "rubygems-trusted-publisher", status: "fail", message: tok.none, fix: "Give the job permissions: id-token: write." });
|
|
1134
|
+
return t;
|
|
1135
|
+
}
|
|
1136
|
+
const ex = await answer(ctx, `${host}/api/v1/oidc/trusted_publisher/exchange_token`, { method: "POST", headers: { "content-type": "application/json", accept: "application/json" }, body: JSON.stringify({ jwt: tok.token }) });
|
|
1137
|
+
const value = ex.json?.rubygems_api_key;
|
|
1138
|
+
if (typeof value === "string")
|
|
1139
|
+
ctx.redactor.add(value);
|
|
1140
|
+
checks.push(ex.status >= 200 && ex.status < 300 && typeof value === "string"
|
|
1141
|
+
? { check: "rubygems-trusted-publisher", status: "ok", message: "RubyGems.org takes this workflow as a trusted publisher" }
|
|
1142
|
+
: { check: "rubygems-trusted-publisher", status: "fail", message: `RubyGems.org gave no API key for this run (${ex.status}${ex.text ? `: ${short(ex.text)}` : ""})`, fix: "Add this repository and workflow as a trusted publisher of the gem on RubyGems.org." });
|
|
1143
|
+
return t;
|
|
1144
|
+
}
|
|
943
1145
|
async function checkCargo(decl, ctx) {
|
|
944
1146
|
const { CRATES_IO_API, CRATES_IO_AUDIENCE, CRATES_IO_ID_TOKEN_ENV, CRATES_IO_INDEX, cargoAuth, cargoPublishOrder, cargoTokenEnv, cargoWorkspace, sparseIndexPath } = await import("./publish-cargo.js");
|
|
945
1147
|
const label = decl.registry ? `registry ${decl.registry}` : "crates.io";
|