@intentius/chant 0.124.99 → 0.124.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/chant +3 -3
- package/dist/action-pins.d.ts +2 -0
- package/dist/action-pins.js +3 -0
- package/dist/ci-detect.d.ts +13 -0
- package/dist/ci-detect.js +12 -0
- package/dist/ci-system.d.ts +66 -0
- package/dist/ci-system.js +61 -0
- package/dist/cli/commands/carve-emit.js +2 -2
- package/dist/cli/commands/check-lexicon-plugin.d.ts +2 -2
- package/dist/cli/commands/check-lexicon-plugin.js +3 -3
- package/dist/cli/commands/check-lexicon.js +4 -4
- package/dist/cli/commands/init-lexicon/templates/project.d.ts +1 -1
- package/dist/cli/commands/init-lexicon/templates/project.js +4 -4
- package/dist/cli/commands/init.d.ts +13 -0
- package/dist/cli/commands/init.js +30 -2
- package/dist/cli/handlers/build.js +27 -0
- package/dist/cli/handlers/release-doctor.d.ts +12 -0
- package/dist/cli/handlers/release-doctor.js +118 -0
- package/dist/cli/handlers/release-init.d.ts +10 -0
- package/dist/cli/handlers/release-init.js +342 -0
- package/dist/cli/handlers/release.d.ts +50 -1
- package/dist/cli/handlers/release.js +688 -30
- package/dist/cli/handlers/run-generate.js +11 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +45 -97
- package/dist/cli/parse-args.js +55 -0
- package/dist/cli/registry.d.ts +18 -0
- package/dist/cli/release-commands/artifacts.d.ts +3 -0
- package/dist/cli/release-commands/artifacts.js +14 -0
- package/dist/cli/release-commands/candidates.d.ts +3 -0
- package/dist/cli/release-commands/candidates.js +16 -0
- package/dist/cli/release-commands/changed.d.ts +3 -0
- package/dist/cli/release-commands/changed.js +14 -0
- package/dist/cli/release-commands/compose.d.ts +3 -0
- package/dist/cli/release-commands/compose.js +16 -0
- package/dist/cli/release-commands/cut.d.ts +3 -0
- package/dist/cli/release-commands/cut.js +49 -0
- package/dist/cli/release-commands/doctor.d.ts +3 -0
- package/dist/cli/release-commands/doctor.js +14 -0
- package/dist/cli/release-commands/export.d.ts +3 -0
- package/dist/cli/release-commands/export.js +12 -0
- package/dist/cli/release-commands/images.d.ts +3 -0
- package/dist/cli/release-commands/images.js +13 -0
- package/dist/cli/release-commands/index.d.ts +8 -0
- package/dist/cli/release-commands/index.js +52 -0
- package/dist/cli/release-commands/init.d.ts +3 -0
- package/dist/cli/release-commands/init.js +16 -0
- package/dist/cli/release-commands/list.d.ts +3 -0
- package/dist/cli/release-commands/list.js +10 -0
- package/dist/cli/release-commands/next.d.ts +3 -0
- package/dist/cli/release-commands/next.js +13 -0
- package/dist/cli/release-commands/publish.d.ts +3 -0
- package/dist/cli/release-commands/publish.js +22 -0
- package/dist/cli/release-commands/stamp.d.ts +3 -0
- package/dist/cli/release-commands/stamp.js +15 -0
- package/dist/cli/release-commands/status.d.ts +3 -0
- package/dist/cli/release-commands/status.js +17 -0
- package/dist/cli/release-commands/tag.d.ts +3 -0
- package/dist/cli/release-commands/tag.js +12 -0
- package/dist/cli/release-commands/types.d.ts +20 -0
- package/dist/cli/release-commands/types.js +1 -0
- package/dist/cli/release-commands/verify.d.ts +3 -0
- package/dist/cli/release-commands/verify.js +15 -0
- package/dist/cli/release-commands/workflow.d.ts +3 -0
- package/dist/cli/release-commands/workflow.js +13 -0
- package/dist/codegen/pinned-upgrade.js +1 -1
- package/dist/components/capability-plugin.d.ts +1 -1
- package/dist/components/capability-plugin.js +1 -1
- package/dist/components/cli-support.d.ts +1 -1
- package/dist/components/cli-support.js +1 -1
- package/dist/config-environments.d.ts +8 -1
- package/dist/config-environments.js +2 -0
- package/dist/config.d.ts +299 -6
- package/dist/config.js +102 -5
- package/dist/dead-guards.d.ts +5 -1
- package/dist/dead-guards.js +34 -23
- package/dist/discovery/sandbox/driver.js +1 -1
- package/dist/discovery/specifier-resolve.js +1 -1
- package/dist/floor-table.d.ts +3 -1
- package/dist/floor-table.data.js +23 -3
- package/dist/floor-table.js +4 -3
- package/dist/forge-remote.d.ts +13 -0
- package/dist/forge-remote.js +15 -0
- package/dist/lexicon.d.ts +41 -2
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +62 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.js +270 -3
- package/dist/lifecycle/publish-attachments.d.ts +2 -1
- package/dist/lifecycle/publish-attachments.js +19 -2
- package/dist/lifecycle/publish-cargo.d.ts +99 -0
- package/dist/lifecycle/publish-cargo.js +412 -0
- package/dist/lifecycle/publish-credentials.d.ts +1 -1
- package/dist/lifecycle/publish-credentials.js +8 -0
- package/dist/lifecycle/publish-declaration.d.ts +199 -4
- package/dist/lifecycle/publish-declaration.js +200 -9
- package/dist/lifecycle/publish-forge.d.ts +45 -2
- package/dist/lifecycle/publish-forge.js +434 -34
- package/dist/lifecycle/publish-git-ssh.d.ts +15 -0
- package/dist/lifecycle/publish-git-ssh.js +30 -4
- package/dist/lifecycle/publish-github.d.ts +40 -2
- package/dist/lifecycle/publish-github.js +100 -3
- package/dist/lifecycle/publish-homebrew.d.ts +7 -9
- package/dist/lifecycle/publish-homebrew.js +34 -197
- package/dist/lifecycle/publish-index.d.ts +141 -0
- package/dist/lifecycle/publish-index.js +719 -0
- package/dist/lifecycle/publish-marketplace.js +77 -0
- package/dist/lifecycle/publish-mcp-registry.d.ts +66 -0
- package/dist/lifecycle/publish-mcp-registry.js +306 -0
- package/dist/lifecycle/publish-npm.js +165 -2
- package/dist/lifecycle/publish-oci.d.ts +34 -1
- package/dist/lifecycle/publish-oci.js +246 -7
- package/dist/lifecycle/publish-pypi.d.ts +136 -0
- package/dist/lifecycle/publish-pypi.js +657 -0
- package/dist/lifecycle/publish-record.d.ts +6 -3
- package/dist/lifecycle/publish-record.js +6 -3
- package/dist/lifecycle/publish-signing.d.ts +147 -0
- package/dist/lifecycle/publish-signing.js +257 -0
- package/dist/lifecycle/publish-targets.d.ts +27 -1
- package/dist/lifecycle/publish-targets.js +80 -0
- package/dist/lifecycle/publish-tauri.js +43 -0
- package/dist/lifecycle/publish-train-names.d.ts +54 -0
- package/dist/lifecycle/publish-train-names.js +118 -0
- package/dist/lifecycle/publish-verify.d.ts +121 -0
- package/dist/lifecycle/publish-verify.js +130 -0
- package/dist/lifecycle/query.js +8 -0
- package/dist/lifecycle/release-artifacts.d.ts +212 -0
- package/dist/lifecycle/release-artifacts.js +571 -0
- package/dist/lifecycle/release-changelog.d.ts +13 -1
- package/dist/lifecycle/release-changelog.js +35 -2
- package/dist/lifecycle/release-cut.d.ts +58 -3
- package/dist/lifecycle/release-cut.js +132 -34
- package/dist/lifecycle/release-doctor.d.ts +113 -0
- package/dist/lifecycle/release-doctor.js +996 -0
- package/dist/lifecycle/release-green.d.ts +86 -0
- package/dist/lifecycle/release-green.js +286 -0
- package/dist/lifecycle/release-init.d.ts +255 -0
- package/dist/lifecycle/release-init.js +859 -0
- package/dist/lifecycle/release-intents.d.ts +73 -0
- package/dist/lifecycle/release-intents.js +128 -0
- package/dist/lifecycle/release-next.d.ts +111 -0
- package/dist/lifecycle/release-next.js +252 -0
- package/dist/lifecycle/release-prerelease.d.ts +19 -0
- package/dist/lifecycle/release-prerelease.js +30 -0
- package/dist/lifecycle/release-publish.d.ts +256 -10
- package/dist/lifecycle/release-publish.js +246 -34
- package/dist/lifecycle/release-status-change.d.ts +226 -0
- package/dist/lifecycle/release-status-change.js +478 -0
- package/dist/lifecycle/release-status.d.ts +11 -0
- package/dist/lifecycle/release-status.js +1 -1
- package/dist/lifecycle/release-store.d.ts +73 -2
- package/dist/lifecycle/release-store.js +32 -1
- package/dist/lifecycle/release-tag.d.ts +142 -0
- package/dist/lifecycle/release-tag.js +323 -0
- package/dist/lifecycle/release-verify.d.ts +73 -1
- package/dist/lifecycle/release-verify.js +117 -2
- package/dist/lifecycle/release-version-formats.d.ts +73 -0
- package/dist/lifecycle/release-version-formats.js +570 -0
- package/dist/lifecycle/release-version.d.ts +58 -10
- package/dist/lifecycle/release-version.js +164 -36
- package/dist/lifecycle/release-workstation.d.ts +3 -2
- package/dist/lifecycle/release-workstation.js +3 -2
- package/dist/module-source.d.ts +2 -2
- package/dist/module-source.js +8 -8
- package/dist/op/generate-pipeline.js +1 -1
- package/dist/pr-forge-base.js +4 -2
- package/dist/pr-forge.d.ts +20 -2
- package/dist/pr-forge.js +46 -10
- package/dist/release-floors.d.ts +10 -1
- package/dist/release-floors.js +10 -1
- package/dist/tool-pins.d.ts +38 -0
- package/dist/tool-pins.js +54 -0
- package/dist/ts-loader.d.ts +1 -1
- package/dist/ts-loader.js +6 -6
- package/dist/wave-runtime.mjs +337 -334
- package/dist/workspace/ci-forge.d.ts +17 -0
- package/dist/workspace/ci-forge.js +17 -0
- package/dist/workspace/ci-init.js +1 -1
- package/dist/workspace/composites.schema.json +1 -0
- package/dist/workspace/declaration.d.ts +8 -0
- package/dist/workspace/declaration.js +12 -0
- package/dist/workspace/declaration.schema.json +8 -0
- package/dist/workspace/environments.d.ts +2 -0
- package/dist/workspace/environments.js +1 -1
- package/dist/workspace/identity-gate-rule.d.ts +61 -5
- package/dist/workspace/identity-gate-rule.js +81 -12
- package/dist/workspace/member-pipeline.d.ts +2 -1
- package/dist/workspace/member-pipeline.js +5 -2
- package/dist/workspace/reason-codes.d.ts +6 -0
- package/dist/workspace/reason-codes.js +8 -1
- package/dist/workspace/release-changed.d.ts +179 -0
- package/dist/workspace/release-changed.js +625 -0
- package/dist/workspace/release-changed.schema.json +206 -0
- package/dist/workspace/release-steps/artifacts.d.ts +7 -0
- package/dist/workspace/release-steps/artifacts.js +45 -0
- package/dist/workspace/release-steps/builds.d.ts +12 -0
- package/dist/workspace/release-steps/builds.js +38 -0
- package/dist/workspace/release-steps/doctor.d.ts +8 -0
- package/dist/workspace/release-steps/doctor.js +14 -0
- package/dist/workspace/release-steps/goreleaser.d.ts +16 -0
- package/dist/workspace/release-steps/goreleaser.js +36 -0
- package/dist/workspace/release-steps/green.d.ts +3 -0
- package/dist/workspace/release-steps/green.js +6 -0
- package/dist/workspace/release-steps/images.d.ts +22 -0
- package/dist/workspace/release-steps/images.js +59 -0
- package/dist/workspace/release-steps/index.d.ts +9 -0
- package/dist/workspace/release-steps/index.js +46 -0
- package/dist/workspace/release-steps/pypi.d.ts +15 -0
- package/dist/workspace/release-steps/pypi.js +21 -0
- package/dist/workspace/release-steps/qemu.d.ts +21 -0
- package/dist/workspace/release-steps/qemu.js +35 -0
- package/dist/workspace/release-steps/signing.d.ts +18 -0
- package/dist/workspace/release-steps/signing.js +30 -0
- package/dist/workspace/release-steps/stamp.d.ts +3 -0
- package/dist/workspace/release-steps/stamp.js +4 -0
- package/dist/workspace/release-steps/targets.d.ts +31 -0
- package/dist/workspace/release-steps/targets.js +40 -0
- package/dist/workspace/release-steps/types.d.ts +104 -0
- package/dist/workspace/release-steps/types.js +2 -0
- package/dist/workspace/release-steps/verify.d.ts +3 -0
- package/dist/workspace/release-steps/verify.js +4 -0
- package/dist/workspace/release-toolchains.d.ts +59 -0
- package/dist/workspace/release-toolchains.js +133 -0
- package/dist/workspace/release-train-workflow.d.ts +29 -0
- package/dist/workspace/release-train-workflow.js +85 -0
- package/dist/workspace/release-train.d.ts +3 -1
- package/dist/workspace/release-train.js +20 -3
- package/dist/workspace/release-workflow.d.ts +160 -61
- package/dist/workspace/release-workflow.js +539 -193
- package/dist/workspace/releases.schema.json +70 -1
- package/dist/workspace/search-contract.d.ts +1 -1
- package/dist/workspace/security.js +9 -2
- package/dist/workspace/train-cut.d.ts +182 -0
- package/dist/workspace/train-cut.js +482 -0
- package/dist/workspace/train-prepare.d.ts +61 -0
- package/dist/workspace/train-prepare.js +267 -0
- package/dist/workspace/train-publish.d.ts +177 -0
- package/dist/workspace/train-publish.js +575 -0
- package/dist/workspace/train-range-labels.d.ts +33 -0
- package/dist/workspace/train-range-labels.js +109 -0
- package/dist/workspace/trust/seal.d.ts +13 -3
- package/dist/workspace/trust/seal.js +14 -4
- package/dist/workspace/work-cli.d.ts +3 -2
- package/dist/workspace/work-cli.js +3 -2
- package/dist/workspace/workspace-ledger.d.ts +14 -1
- package/dist/workspace/workspace-ledger.js +33 -7
- package/package.json +26 -26
|
@@ -0,0 +1,996 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant release doctor` (#5161): before anything is cut, ask each target
|
|
3
|
+
* `release.publish` declares whether a publish from this environment can
|
|
4
|
+
* succeed, without changing anything on any registry.
|
|
5
|
+
*
|
|
6
|
+
* Each check ends in one of four states:
|
|
7
|
+
*
|
|
8
|
+
* - `ok`: the registry or forge said yes.
|
|
9
|
+
* - `fail`: it said no, or a credential the publish needs is not here. In CI
|
|
10
|
+
* a missing credential fails; on a workstation it is a warning, since the
|
|
11
|
+
* release job's environment is not this one.
|
|
12
|
+
* - `warn`: something the publish can live with, or evidence that points the
|
|
13
|
+
* wrong way without proving it, such as the workflow the last version was
|
|
14
|
+
* published from.
|
|
15
|
+
* - `unknown`: what can't be observed from here. npm matches a trusted
|
|
16
|
+
* publisher against the workflow that asks, so only a run of the release
|
|
17
|
+
* workflow can test the record; whether a record allows `npm dist-tag`, and
|
|
18
|
+
* what a job token may do, are not shown to anyone. The doctor says so
|
|
19
|
+
* rather than guessing.
|
|
20
|
+
*
|
|
21
|
+
* The probes are reads, apart from two exchanges that hand back a short-lived
|
|
22
|
+
* publishing token, which is masked and dropped: npm's OIDC exchange and Open
|
|
23
|
+
* VSX's trusted-publishing exchange, the same requests a publish makes first.
|
|
24
|
+
*
|
|
25
|
+
* Under `release.green: "forge-checks"` (#5149) the cut asks the forge for the
|
|
26
|
+
* commit's checks, so the doctor reads the checks of the checked-out commit
|
|
27
|
+
* with the token the cut would use (`green-forge-checks`). Whether that
|
|
28
|
+
* commit is green is the cut's question; the doctor only asks whether the
|
|
29
|
+
* forge answers.
|
|
30
|
+
*
|
|
31
|
+
* When the publish signs with Sigstore (#5164, ./publish-signing.ts), the
|
|
32
|
+
* doctor checks what signing needs from the job it runs in: the OIDC token
|
|
33
|
+
* cosign signs with (`signing-oidc`) and cosign 3 (`signing-cosign`).
|
|
34
|
+
*/
|
|
35
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
36
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
37
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
38
|
+
import { createRedactor, readCredential } from "./publish-credentials.js";
|
|
39
|
+
import { NEXT_RELEASE } from "../release-floors.js";
|
|
40
|
+
/** 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 = NEXT_RELEASE;
|
|
42
|
+
export const DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
|
|
43
|
+
function defaultRun(bin, args, opts) {
|
|
44
|
+
return new Promise((done) => {
|
|
45
|
+
let stdout = "";
|
|
46
|
+
let stderr = "";
|
|
47
|
+
const child = spawn(bin, args, { cwd: opts.cwd, env: opts.env, stdio: ["ignore", "pipe", "pipe"] });
|
|
48
|
+
child.stdout.on("data", (c) => (stdout += c.toString("utf-8")));
|
|
49
|
+
child.stderr.on("data", (c) => (stderr += c.toString("utf-8")));
|
|
50
|
+
child.on("error", (err) => done({ code: 127, stdout, stderr: err.message }));
|
|
51
|
+
child.on("close", (code) => done({ code: code ?? 1, stdout, stderr }));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** The CI this process runs in, and whether it can get an OIDC token, from its environment. */
|
|
55
|
+
export function doctorEnvironment(env, req) {
|
|
56
|
+
const ci = env.GITHUB_ACTIONS === "true" ? "github" : env.GITLAB_CI === "true" ? "gitlab" : env.CI ? "other" : null;
|
|
57
|
+
const oidc = ci === "github" ? Boolean(env.ACTIONS_ID_TOKEN_REQUEST_URL && env.ACTIONS_ID_TOKEN_REQUEST_TOKEN) : ci === "gitlab" ? Boolean(env.NPM_ID_TOKEN || env.SIGSTORE_ID_TOKEN || env.OVSX_ID_TOKEN) : Boolean(env.OVSX_ID_TOKEN);
|
|
58
|
+
// GITHUB_WORKFLOW_REF is `owner/name/.github/workflows/release.yml@refs/heads/main`.
|
|
59
|
+
const ref = env.GITHUB_WORKFLOW_REF ?? "";
|
|
60
|
+
const repository = env.GITHUB_REPOSITORY ?? (ci === "gitlab" ? (env.CI_PROJECT_PATH ?? null) : originRepository(req.cwd));
|
|
61
|
+
const workflow = ci === "github" && repository && ref.startsWith(`${repository}/`) ? ref.slice(repository.length + 1).replace(/@.*$/, "") : null;
|
|
62
|
+
return { ci, oidc, workflow, repository, releaseWorkflow: req.releaseWorkflow };
|
|
63
|
+
}
|
|
64
|
+
/** `owner/name` of the `origin` remote, or null. */
|
|
65
|
+
function originRepository(cwd) {
|
|
66
|
+
try {
|
|
67
|
+
const url = execFileSync("git", ["remote", "get-url", "origin"], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
68
|
+
const m = /[:/]([^/:]+\/[^/]+?)(?:\.git)?\/?$/.exec(url);
|
|
69
|
+
return m ? m[1] : null;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Check every declared target. Nothing is published, tagged or changed. */
|
|
76
|
+
export async function releaseDoctor(req) {
|
|
77
|
+
const env = req.env ?? process.env;
|
|
78
|
+
const deps = req.deps ?? {};
|
|
79
|
+
const environment = doctorEnvironment(env, { cwd: req.cwd, releaseWorkflow: req.releaseWorkflow });
|
|
80
|
+
const redactor = createRedactor(env);
|
|
81
|
+
const ctx = {
|
|
82
|
+
cwd: req.cwd,
|
|
83
|
+
env,
|
|
84
|
+
environment,
|
|
85
|
+
redactor,
|
|
86
|
+
fetch: deps.fetch ?? globalThis.fetch,
|
|
87
|
+
run: deps.run ?? defaultRun,
|
|
88
|
+
npm: deps.npm ?? "npm",
|
|
89
|
+
vsce: deps.vsce ?? "vsce",
|
|
90
|
+
cargo: deps.cargo ?? "cargo",
|
|
91
|
+
};
|
|
92
|
+
const targets = [];
|
|
93
|
+
for (const decl of req.publish) {
|
|
94
|
+
try {
|
|
95
|
+
targets.push(...(await checkTarget(decl, ctx)));
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
targets.push({ kind: decl.type, name: decl.type, checks: [{ check: `${decl.type}-check`, status: "unknown", message: `the check could not run: ${err instanceof Error ? err.message : String(err)}` }] });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (req.green === "forge-checks")
|
|
102
|
+
targets.push(await checkForgeChecks(ctx, req.commit));
|
|
103
|
+
const signing = await checkSigning(ctx, req.publish, req.signing, req.groups ?? new Set(), deps.signer);
|
|
104
|
+
if (signing)
|
|
105
|
+
targets.push(signing);
|
|
106
|
+
for (const t of targets)
|
|
107
|
+
for (const c of t.checks)
|
|
108
|
+
c.message = redactor.redact(c.message);
|
|
109
|
+
const counts = { ok: 0, warn: 0, fail: 0, unknown: 0 };
|
|
110
|
+
for (const t of targets)
|
|
111
|
+
for (const c of t.checks)
|
|
112
|
+
counts[c.status]++;
|
|
113
|
+
return { environment, targets, counts };
|
|
114
|
+
}
|
|
115
|
+
async function checkTarget(decl, ctx) {
|
|
116
|
+
switch (decl.type) {
|
|
117
|
+
case "npm":
|
|
118
|
+
return checkNpm(decl, ctx);
|
|
119
|
+
case "oci":
|
|
120
|
+
return [await checkOci(decl, ctx)];
|
|
121
|
+
case "forge":
|
|
122
|
+
return [await checkForge(decl, ctx)];
|
|
123
|
+
case "homebrew":
|
|
124
|
+
return [await checkHomebrew(decl, ctx)];
|
|
125
|
+
case "marketplace":
|
|
126
|
+
return [await checkMarketplace(decl, ctx)];
|
|
127
|
+
case "tauri-updater":
|
|
128
|
+
return [await checkTauri(decl, ctx)];
|
|
129
|
+
case "pypi":
|
|
130
|
+
return [await checkPypi(decl, ctx)];
|
|
131
|
+
case "cargo":
|
|
132
|
+
return [await checkCargo(decl, ctx)];
|
|
133
|
+
case "mcp-registry":
|
|
134
|
+
return [await checkMcpRegistry(decl, ctx)];
|
|
135
|
+
case "index":
|
|
136
|
+
return [await checkIndex(decl, ctx)];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* `release.green: "forge-checks"`: the forge and token the cut would ask, and
|
|
141
|
+
* whether that token reads the commit's checks and statuses.
|
|
142
|
+
*/
|
|
143
|
+
async function checkForgeChecks(ctx, commit) {
|
|
144
|
+
const checks = [];
|
|
145
|
+
const t = { kind: "green", name: "release.green forge-checks", checks };
|
|
146
|
+
const { forgeChecksReader, forgeChecksTarget, ForgeChecksUnavailableError } = await import("./release-green.js");
|
|
147
|
+
let target;
|
|
148
|
+
try {
|
|
149
|
+
target = await forgeChecksTarget(ctx.cwd, ctx.env);
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
if (!(err instanceof ForgeChecksUnavailableError))
|
|
153
|
+
throw err;
|
|
154
|
+
checks.push(missing(ctx, "green-forge-checks", err.message, err.fix ?? "Set release.green in chant.config.ts to \"chant\" or \"none\", or give the cut a forge token."));
|
|
155
|
+
return t;
|
|
156
|
+
}
|
|
157
|
+
let sha = commit;
|
|
158
|
+
if (!sha) {
|
|
159
|
+
try {
|
|
160
|
+
sha = execFileSync("git", ["rev-parse", "HEAD"], { cwd: ctx.cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
checks.push({ check: "green-forge-checks", status: "unknown", message: `the token comes from ${target.tokenSource}, and there is no commit here to read the checks of` });
|
|
164
|
+
return t;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
const verdict = await forgeChecksReader(target, ctx.env, ctx.fetch)(sha, null);
|
|
169
|
+
const n = verdict.checks.length;
|
|
170
|
+
checks.push({ check: "green-forge-checks", status: "ok", message: `the token from ${target.tokenSource} reads ${target.kind}'s checks on ${target.repo}: ${n} on ${sha.slice(0, 12)}${verdict.green ? ", all passed" : `; ${verdict.why}, which the cut will refuse unless it passes first`}` });
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
if (!(err instanceof ForgeChecksUnavailableError))
|
|
174
|
+
throw err;
|
|
175
|
+
checks.push({ check: "green-forge-checks", status: "fail", message: `the cut can't read the commit's checks: ${err.message}`, fix: err.fix ?? `Give the token from ${target.tokenSource} read access to ${target.repo}'s checks and statuses.` });
|
|
176
|
+
}
|
|
177
|
+
return t;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Sigstore signing (#5164), when `release.signing` or the `supply-chain`
|
|
181
|
+
* group turns it on and an `oci` or `forge` target signs: whether this job
|
|
182
|
+
* has the OIDC token the certificate is issued for, and cosign 3. Null when
|
|
183
|
+
* the publish does not sign.
|
|
184
|
+
*/
|
|
185
|
+
async function checkSigning(ctx, publish, config, groups, injected) {
|
|
186
|
+
const { resolveSigning, signingIdentity, cosignSigner } = await import("./publish-signing.js");
|
|
187
|
+
const setting = resolveSigning(config, groups);
|
|
188
|
+
if (!setting.on || !publish.some((d) => d.type === "oci" || d.type === "forge" || d.type === "pypi"))
|
|
189
|
+
return null;
|
|
190
|
+
const why = setting.from === "config" ? "release.signing" : "the supply-chain group";
|
|
191
|
+
const checks = [];
|
|
192
|
+
const id = signingIdentity(ctx.env);
|
|
193
|
+
if ("reason" in id) {
|
|
194
|
+
checks.push(missing(ctx, "signing-oidc", `${why} signs images and forge assets keylessly, and ${id.reason}`, "Publish from a CI job with an OIDC token (GitHub Actions: permissions: id-token: write; GitLab CI: SIGSTORE_ID_TOKEN under id_tokens with aud: sigstore), or set release.signing: false."));
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
checks.push({ check: "signing-oidc", status: "ok", message: `the certificate will name ${id.identity.identity}, issuer ${id.identity.issuer}` });
|
|
198
|
+
}
|
|
199
|
+
const signer = injected ?? cosignSigner(ctx.env, ctx.redactor);
|
|
200
|
+
const gone = signer.unavailable();
|
|
201
|
+
checks.push(gone ? missing(ctx, "signing-cosign", gone, "Install cosign 3 in the job, as chant release workflow does, or point CHANT_COSIGN at it.") : { check: "signing-cosign", status: "ok", message: `${signer.name} signs` });
|
|
202
|
+
return { kind: "signing", name: "Sigstore signing", checks };
|
|
203
|
+
}
|
|
204
|
+
/** A credential the publish needs and this environment lacks: a failure in CI, a warning on a workstation. */
|
|
205
|
+
function missing(ctx, check, what, fix) {
|
|
206
|
+
return ctx.environment.ci
|
|
207
|
+
? { check, status: "fail", message: `${what}, so a publish from this job fails`, fix }
|
|
208
|
+
: { check, status: "warn", message: `${what} in this shell; the release job needs it in its environment`, fix };
|
|
209
|
+
}
|
|
210
|
+
async function answer(ctx, url, init) {
|
|
211
|
+
const res = await ctx.fetch(url, { ...init, headers: { "user-agent": "chant", ...init.headers } });
|
|
212
|
+
const text = await res.text().catch(() => "");
|
|
213
|
+
let json = null;
|
|
214
|
+
try {
|
|
215
|
+
json = text ? JSON.parse(text) : null;
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
json = null;
|
|
219
|
+
}
|
|
220
|
+
return { status: res.status, text, json, header: (n) => res.headers.get(n) };
|
|
221
|
+
}
|
|
222
|
+
const short = (text) => (text.length > 200 ? `${text.slice(0, 200)}...` : text);
|
|
223
|
+
/** An OIDC ID token for `audience`: GitHub Actions' token service, else the variable named. Null when this run has none. */
|
|
224
|
+
async function idToken(ctx, audience, variable) {
|
|
225
|
+
const direct = readCredential(ctx.env, [variable], ctx.redactor);
|
|
226
|
+
if (direct)
|
|
227
|
+
return { token: direct.value };
|
|
228
|
+
if (!(ctx.env.ACTIONS_ID_TOKEN_REQUEST_URL && ctx.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN))
|
|
229
|
+
return { none: ctx.environment.ci === "github" ? "this job has no id-token: write permission" : `this run has no OIDC token (no GitHub Actions id-token, and ${variable} is not set)` };
|
|
230
|
+
ctx.redactor.add(ctx.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN);
|
|
231
|
+
const url = new URL(ctx.env.ACTIONS_ID_TOKEN_REQUEST_URL);
|
|
232
|
+
url.searchParams.set("audience", audience);
|
|
233
|
+
const res = await answer(ctx, url.toString(), { method: "GET", headers: { authorization: `Bearer ${ctx.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN}`, accept: "application/json" } });
|
|
234
|
+
const value = res.json?.value;
|
|
235
|
+
if (res.status !== 200 || typeof value !== "string" || !value)
|
|
236
|
+
return { none: `GitHub Actions gave no ID token for ${audience} (it answered ${res.status})` };
|
|
237
|
+
ctx.redactor.add(value);
|
|
238
|
+
return { token: value };
|
|
239
|
+
}
|
|
240
|
+
/** The sentence for a check only a run of the release workflow can make, naming it when it is known. */
|
|
241
|
+
function onlyTheWorkflow(ctx) {
|
|
242
|
+
return ctx.environment.releaseWorkflow ? `a run of ${ctx.environment.releaseWorkflow}` : "a run of the release workflow";
|
|
243
|
+
}
|
|
244
|
+
function npmPackageInfo(cwd, path) {
|
|
245
|
+
const abs = isAbsolute(path) ? path : resolve(cwd, path);
|
|
246
|
+
if (path.endsWith(".tgz")) {
|
|
247
|
+
if (!existsSync(abs))
|
|
248
|
+
return { path, name: null, private: false, why: `${path} is not built yet, so its name can't be read` };
|
|
249
|
+
try {
|
|
250
|
+
const manifest = JSON.parse(execFileSync("tar", ["-xzOf", abs, "package/package.json"], { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }));
|
|
251
|
+
return { path, name: typeof manifest.name === "string" ? manifest.name : null, private: manifest.private === true };
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
return { path, name: null, private: false, why: `${path} holds no package/package.json chant can read` };
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const file = join(abs, "package.json");
|
|
258
|
+
if (!existsSync(file))
|
|
259
|
+
return { path, name: null, private: false, why: `${path} has no package.json` };
|
|
260
|
+
try {
|
|
261
|
+
const manifest = JSON.parse(readFileSync(file, "utf-8"));
|
|
262
|
+
return { path, name: typeof manifest.name === "string" ? manifest.name : null, private: manifest.private === true, ...(typeof manifest.name === "string" ? {} : { why: `${path}/package.json names no package` }) };
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
return { path, name: null, private: false, why: `${path}/package.json does not parse: ${err instanceof Error ? err.message : String(err)}` };
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/** The registry the npm target publishes to: the declared one, else npm's own config, else npmjs. */
|
|
269
|
+
async function npmRegistry(decl, ctx) {
|
|
270
|
+
if (decl.registry)
|
|
271
|
+
return decl.registry.replace(/\/+$/, "");
|
|
272
|
+
const r = await ctx.run(ctx.npm, ["config", "get", "registry"], { cwd: ctx.cwd, env: ctx.env }).catch(() => null);
|
|
273
|
+
const out = r && r.code === 0 ? r.stdout.trim() : "";
|
|
274
|
+
return (/^https?:\/\//.test(out) ? out : DEFAULT_NPM_REGISTRY).replace(/\/+$/, "");
|
|
275
|
+
}
|
|
276
|
+
/** The repository and workflow file a version's SLSA provenance names, when npm has one from GitHub Actions. */
|
|
277
|
+
async function provenanceWorkflow(ctx, url) {
|
|
278
|
+
const res = await answer(ctx, url, { method: "GET", headers: { accept: "application/json" } });
|
|
279
|
+
if (res.status !== 200)
|
|
280
|
+
return null;
|
|
281
|
+
const attestations = res.json?.attestations ?? [];
|
|
282
|
+
for (const a of attestations) {
|
|
283
|
+
const payload = a.bundle?.dsseEnvelope?.payload;
|
|
284
|
+
if (typeof payload !== "string" || !String(a.predicateType ?? "").startsWith("https://slsa.dev/provenance/"))
|
|
285
|
+
continue;
|
|
286
|
+
try {
|
|
287
|
+
const statement = JSON.parse(Buffer.from(payload, "base64").toString("utf-8"));
|
|
288
|
+
const w = statement.predicate?.buildDefinition?.externalParameters?.workflow;
|
|
289
|
+
if (typeof w?.repository === "string" && typeof w.path === "string")
|
|
290
|
+
return { repository: w.repository.replace(/^https:\/\/github\.com\//, ""), path: w.path };
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
// A statement chant can't read is no evidence.
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
async function checkNpm(decl, ctx) {
|
|
299
|
+
const registry = await npmRegistry(decl, ctx);
|
|
300
|
+
const host = new URL(registry).host;
|
|
301
|
+
const npmjs = host === "registry.npmjs.org";
|
|
302
|
+
const run = (args) => ctx.run(ctx.npm, [...args, "--registry", registry], { cwd: ctx.cwd, env: ctx.env }).catch((err) => ({ code: 127, stdout: "", stderr: err instanceof Error ? err.message : String(err) }));
|
|
303
|
+
// npm's own credentials, the same for every package: a token in its config.
|
|
304
|
+
const whoami = await run(["whoami"]);
|
|
305
|
+
const user = whoami.code === 0 ? whoami.stdout.trim() : null;
|
|
306
|
+
const out = [];
|
|
307
|
+
for (const path of decl.packages) {
|
|
308
|
+
const info = npmPackageInfo(ctx.cwd, path);
|
|
309
|
+
const checks = [];
|
|
310
|
+
const t = { kind: "npm", name: `npm ${info.name ?? path}`, checks };
|
|
311
|
+
out.push(t);
|
|
312
|
+
if (!info.name) {
|
|
313
|
+
checks.push({ check: "npm-package", status: path.endsWith(".tgz") ? "unknown" : "fail", message: info.why ?? `${path} names no package` });
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (info.private) {
|
|
317
|
+
checks.push({ check: "npm-package", status: "fail", message: `${info.name} is private: true in its package.json, and npm refuses to publish it`, fix: "Remove private: true, or take the package out of the npm target." });
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
const name = info.name;
|
|
321
|
+
const packument = await answer(ctx, `${registry}/${name.replace("/", "%2f")}`, { method: "GET", headers: { accept: "application/json" } });
|
|
322
|
+
const doc = packument.json;
|
|
323
|
+
const exists = packument.status === 200 && doc !== null;
|
|
324
|
+
if (packument.status === 404) {
|
|
325
|
+
checks.push({
|
|
326
|
+
check: "npm-registry",
|
|
327
|
+
status: user ? "warn" : "fail",
|
|
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 the first version with a token (npm login, or the npm config the job reads), then add the trusted publisher on ${npmjs ? "npmjs.com under the package's Settings" : "the registry"}.`,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
else if (!exists) {
|
|
333
|
+
checks.push({ check: "npm-registry", status: "unknown", message: `${registry} answered ${packument.status} for ${name}, so whether it exists can't be told${packument.text ? `: ${short(packument.text)}` : ""}` });
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
const latest = doc["dist-tags"]?.latest ?? null;
|
|
337
|
+
checks.push({ check: "npm-registry", status: "ok", message: `${name} is on ${registry}${latest ? `, latest ${latest}` : ""}` });
|
|
338
|
+
// Evidence from outside: how the latest version was published. Not the record itself, which only the package's owners can read.
|
|
339
|
+
const version = latest ? doc.versions?.[latest] : undefined;
|
|
340
|
+
if (version) {
|
|
341
|
+
const trusted = version._npmUser?.trustedPublisher !== undefined;
|
|
342
|
+
const url = typeof version.dist?.attestations?.url === "string" ? version.dist.attestations.url : null;
|
|
343
|
+
const from = url ? await provenanceWorkflow(ctx, url).catch(() => null) : null;
|
|
344
|
+
const expected = ctx.environment.releaseWorkflow;
|
|
345
|
+
const repo = ctx.environment.repository;
|
|
346
|
+
if (from) {
|
|
347
|
+
const sameRepo = repo === null || from.repository.toLowerCase() === repo.toLowerCase();
|
|
348
|
+
const sameFile = expected === null || from.path === expected;
|
|
349
|
+
checks.push({
|
|
350
|
+
check: "npm-last-publisher",
|
|
351
|
+
status: sameRepo && sameFile ? "ok" : "warn",
|
|
352
|
+
message: `${name}@${latest} was published ${trusted ? "by trusted publishing " : ""}from ${from.repository}, ${from.path}, by its provenance${sameRepo && sameFile ? "" : `, and this release publishes from ${repo ?? "this repository"}, ${expected ?? "its release workflow"}`}. This is the last publish, not the trusted-publisher record, which npm shows only to the package's owners`,
|
|
353
|
+
...(sameRepo && sameFile ? {} : { fix: `On ${npmjs ? "npmjs.com, the package's Settings, Trusted Publisher" : "the registry"}, name ${repo ?? "this repository"} and the workflow file ${expected ? expected.split("/").pop() : "of the release"}.` }),
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
checks.push({ check: "npm-last-publisher", status: "unknown", message: `${name}@${latest} carries no GitHub Actions provenance, so where it was published from can't be read${trusted ? "; it was published by trusted publishing" : ""}` });
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
// The trusted-publisher record: only a run of the workflow it names can test it.
|
|
362
|
+
const env = ctx.environment;
|
|
363
|
+
if (!env.ci) {
|
|
364
|
+
checks.push({ check: "npm-trusted-publisher", status: "unknown", message: `whether ${name}'s trusted publisher names this workflow can only be tested by ${onlyTheWorkflow(ctx)}: npm matches the record against the workflow whose OIDC token asks, and a workstation has none` });
|
|
365
|
+
}
|
|
366
|
+
else if (env.ci === "github" && env.workflow && env.releaseWorkflow && env.workflow !== env.releaseWorkflow) {
|
|
367
|
+
checks.push({ check: "npm-trusted-publisher", status: "unknown", message: `this run is ${env.workflow}, and npm matches the trusted publisher against the workflow file that asks, so an exchange here says nothing about ${env.releaseWorkflow}` });
|
|
368
|
+
}
|
|
369
|
+
else if (exists) {
|
|
370
|
+
const id = await idToken(ctx, `npm:${host}`, "NPM_ID_TOKEN");
|
|
371
|
+
if ("none" in id) {
|
|
372
|
+
checks.push(user ? { check: "npm-trusted-publisher", status: "unknown", message: `no trusted-publisher exchange: ${id.none}. npm's config signs in as ${user}, which the publish uses instead` } : { check: "npm-trusted-publisher", status: "fail", message: `${id.none}, and npm's config has no token, so nothing here can publish ${name}`, fix: "Give the job permissions: id-token: write (GitLab: an NPM_ID_TOKEN under id_tokens), or a token in the npm config it reads." });
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
const ex = await answer(ctx, `${registry}/-/npm/v1/oidc/token/exchange/package/${name.replace("/", "%2f")}`, { method: "POST", headers: { authorization: `Bearer ${id.token}` } });
|
|
376
|
+
const token = ex.json?.token;
|
|
377
|
+
if (typeof token === "string")
|
|
378
|
+
ctx.redactor.add(token);
|
|
379
|
+
const reason = ex.json?.message ?? ex.json?.error ?? short(ex.text);
|
|
380
|
+
if (ex.status >= 200 && ex.status < 300)
|
|
381
|
+
checks.push({ check: "npm-trusted-publisher", status: "ok", message: `npm exchanged this run's OIDC token for a publishing token for ${name}: its trusted publisher names this workflow` });
|
|
382
|
+
else if (ex.status >= 400 && ex.status < 500)
|
|
383
|
+
checks.push({
|
|
384
|
+
check: "npm-trusted-publisher",
|
|
385
|
+
status: user ? "warn" : "fail",
|
|
386
|
+
message: `npm refused this run's OIDC token for ${name} (${ex.status}: ${String(reason)})${user ? `; the publish falls back to npm's config, signed in as ${user}` : ""}`,
|
|
387
|
+
fix: `On ${npmjs ? "npmjs.com, the package's Settings, Trusted Publisher" : "the registry"}, name ${env.repository ?? "this repository"} and the workflow file ${env.workflow ?? env.releaseWorkflow ?? "of this run"}, with no environment unless the job names one.`,
|
|
388
|
+
});
|
|
389
|
+
else
|
|
390
|
+
checks.push({ check: "npm-trusted-publisher", status: "fail", message: `${registry} gave no usable answer to the OIDC exchange for ${name} (${ex.status}), so the record could not be checked`, fix: "Run the doctor again once the registry answers." });
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
// Credentials in npm's config, and whether they may write the package.
|
|
394
|
+
if (user && exists) {
|
|
395
|
+
const access = await run(["access", "list", "collaborators", name, "--json"]);
|
|
396
|
+
let rights;
|
|
397
|
+
try {
|
|
398
|
+
rights = JSON.parse(access.stdout)[user];
|
|
399
|
+
}
|
|
400
|
+
catch {
|
|
401
|
+
rights = undefined;
|
|
402
|
+
}
|
|
403
|
+
checks.push(rights === "read-write"
|
|
404
|
+
? { check: "npm-token", status: "ok", message: `npm's config signs in as ${user}, who may write ${name}` }
|
|
405
|
+
: rights
|
|
406
|
+
? { check: "npm-token", status: "fail", message: `npm's config signs in as ${user}, who may only ${rights} ${name}`, fix: `Make ${user} a maintainer of ${name}, or publish with trusted publishing.` }
|
|
407
|
+
: { check: "npm-token", status: "unknown", message: `npm's config signs in as ${user}; ${registry} did not say what ${user} may do to ${name}, and a granular token's own scope is not shown` });
|
|
408
|
+
}
|
|
409
|
+
else if (!user && !env.oidc) {
|
|
410
|
+
checks.push(missing(ctx, "npm-token", "npm's config has no token and the run has no OIDC token", "npm login on a workstation; in CI, permissions: id-token: write for trusted publishing, or a token in the npm config the job reads."));
|
|
411
|
+
}
|
|
412
|
+
// The reveal moves a dist-tag, unless the target publishes straight to latest.
|
|
413
|
+
if (decl.stage !== false && exists) {
|
|
414
|
+
const viaToken = checks.some((c) => c.check === "npm-token" && c.status === "ok");
|
|
415
|
+
checks.push(viaToken
|
|
416
|
+
? { check: "npm-dist-tag", status: "ok", message: `the reveal moves latest with npm dist-tag add, and ${user} may write ${name}` }
|
|
417
|
+
: {
|
|
418
|
+
check: "npm-dist-tag",
|
|
419
|
+
status: "unknown",
|
|
420
|
+
message: `the reveal moves latest with npm dist-tag add; over trusted publishing that needs "Allow npm dist-tag" on ${name}'s record, which npm does not show, so the reveal is the first thing to try it`,
|
|
421
|
+
fix: "When the record does not allow it, declare stage: false on the npm target to publish straight to latest.",
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return out;
|
|
426
|
+
}
|
|
427
|
+
// OCI
|
|
428
|
+
/** The scopes a registry token grants, when the token is a JWT with an `access` claim, as Docker Hub's is. */
|
|
429
|
+
function jwtAccess(token, name) {
|
|
430
|
+
const parts = token.split(".");
|
|
431
|
+
if (parts.length !== 3)
|
|
432
|
+
return null;
|
|
433
|
+
try {
|
|
434
|
+
const claims = JSON.parse(Buffer.from(parts[1].replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf-8"));
|
|
435
|
+
if (!Array.isArray(claims.access))
|
|
436
|
+
return null;
|
|
437
|
+
return claims.access.filter((a) => a.type === "repository" && a.name === name).flatMap((a) => a.actions ?? []);
|
|
438
|
+
}
|
|
439
|
+
catch {
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
async function checkOci(decl, ctx) {
|
|
444
|
+
const { parseRepository, ociCredential } = await import("./publish-oci.js");
|
|
445
|
+
const repo = parseRepository(decl.repository);
|
|
446
|
+
const checks = [];
|
|
447
|
+
const t = { kind: "oci", name: `oci ${decl.repository}`, checks };
|
|
448
|
+
const cred = ociCredential(decl, repo, { env: ctx.env, redactor: ctx.redactor });
|
|
449
|
+
const local = /^http:/.test(repo.base);
|
|
450
|
+
const vars = `${decl.usernameEnv ?? "OCI_USERNAME"} and ${decl.passwordEnv ?? "OCI_PASSWORD"}`;
|
|
451
|
+
if (cred)
|
|
452
|
+
checks.push({ check: "oci-credentials", status: "ok", message: `credentials for ${repo.host} come from ${cred.password.from}` });
|
|
453
|
+
else if (local)
|
|
454
|
+
checks.push({ check: "oci-credentials", status: "warn", message: `no credentials for ${repo.host}: neither ${vars} nor a docker config entry, so the push is anonymous` });
|
|
455
|
+
else
|
|
456
|
+
checks.push(missing(ctx, "oci-credentials", `no credentials for ${repo.host}: neither ${vars} nor a docker config entry`, `Set ${vars}, or docker login ${repo.host}.`));
|
|
457
|
+
const basic = cred ? `Basic ${Buffer.from(`${cred.username}:${cred.password.value}`).toString("base64")}` : null;
|
|
458
|
+
if (basic)
|
|
459
|
+
ctx.redactor.add(basic.slice(6));
|
|
460
|
+
const ping = await answer(ctx, `${repo.base}/v2/`, { method: "GET", headers: {} });
|
|
461
|
+
const challenge = ping.header("www-authenticate") ?? "";
|
|
462
|
+
if (ping.status === 200) {
|
|
463
|
+
checks.push({ check: "oci-push", status: "unknown", message: `${repo.base} asks for no credentials, so whether it takes a push shows only at the push` });
|
|
464
|
+
}
|
|
465
|
+
else if (ping.status === 401 && /^basic/i.test(challenge)) {
|
|
466
|
+
if (!basic)
|
|
467
|
+
return t;
|
|
468
|
+
const again = await answer(ctx, `${repo.base}/v2/`, { method: "GET", headers: { authorization: basic } });
|
|
469
|
+
checks.push(again.status === 200
|
|
470
|
+
? { check: "oci-push", status: "unknown", message: `${repo.base} takes the credentials; a Basic registry does not say whether they may push to ${repo.name} before a push` }
|
|
471
|
+
: { check: "oci-push", status: "fail", message: `${repo.base} refused the credentials (${again.status})`, fix: `Check ${vars}.` });
|
|
472
|
+
}
|
|
473
|
+
else if (ping.status === 401 && /^bearer/i.test(challenge)) {
|
|
474
|
+
const params = Object.fromEntries([...challenge.matchAll(/(\w+)="([^"]*)"/g)].map((m) => [m[1].toLowerCase(), m[2]]));
|
|
475
|
+
if (!params.realm) {
|
|
476
|
+
checks.push({ check: "oci-push", status: "unknown", message: `${repo.base} sent a Bearer challenge with no realm` });
|
|
477
|
+
return t;
|
|
478
|
+
}
|
|
479
|
+
const u = new URL(params.realm);
|
|
480
|
+
if (params.service)
|
|
481
|
+
u.searchParams.set("service", params.service);
|
|
482
|
+
u.searchParams.set("scope", `repository:${repo.name}:pull,push`);
|
|
483
|
+
const res = await answer(ctx, u.toString(), { method: "GET", headers: basic ? { authorization: basic } : {} });
|
|
484
|
+
const token = res.json?.token ?? res.json?.access_token;
|
|
485
|
+
if (typeof token === "string")
|
|
486
|
+
ctx.redactor.add(token);
|
|
487
|
+
if (res.status !== 200 || typeof token !== "string") {
|
|
488
|
+
checks.push({ check: "oci-push", status: basic ? "fail" : "unknown", message: `the token service of ${repo.host} answered ${res.status}${basic ? " to these credentials" : " with no credentials"}${res.text ? `: ${short(res.text)}` : ""}`, ...(basic ? { fix: `Check ${vars}.` } : {}) });
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
const actions = jwtAccess(token, repo.name);
|
|
492
|
+
checks.push(actions === null
|
|
493
|
+
? { check: "oci-push", status: "unknown", message: `${repo.host} handed out a token for ${repo.name}, and its token does not say what it grants; whether it may push shows only at the push${repo.host === "ghcr.io" ? " (with the job's token, the workflow needs packages: write)" : ""}` }
|
|
494
|
+
: actions.includes("push")
|
|
495
|
+
? { check: "oci-push", status: "ok", message: `${repo.host} grants push on ${repo.name}` }
|
|
496
|
+
: { check: "oci-push", status: "fail", message: `${repo.host} grants ${actions.length > 0 ? actions.join(", ") : "nothing"} on ${repo.name}, not push`, fix: `Give the credentials write access to ${repo.name}.` });
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
checks.push({ check: "oci-push", status: "unknown", message: `${repo.base}/v2/ answered ${ping.status}, which says nothing about a push` });
|
|
501
|
+
}
|
|
502
|
+
return t;
|
|
503
|
+
}
|
|
504
|
+
// Forges
|
|
505
|
+
/** What a token may do on a GitHub or Forgejo repository, from `GET /repos/{repo}`. */
|
|
506
|
+
async function repoAccess(ctx, req) {
|
|
507
|
+
const headers = req.forge === "github" ? { authorization: `Bearer ${req.token}`, accept: "application/vnd.github+json" } : { authorization: `token ${req.token}`, accept: "application/json" };
|
|
508
|
+
const res = await answer(ctx, `${req.api}/repos/${req.repo}`, { method: "GET", headers });
|
|
509
|
+
if (res.status === 401)
|
|
510
|
+
return { check: req.check, status: "fail", message: `${req.api} refused the token in ${req.tokenFrom} (401)`, fix: `Check ${req.tokenFrom}.` };
|
|
511
|
+
if (res.status === 404 || res.status === 403)
|
|
512
|
+
return { check: req.check, status: "fail", message: `the token in ${req.tokenFrom} can't see ${req.repo} on ${req.api} (${res.status})`, fix: `Give the token access to ${req.repo}, or fix repo in the target.` };
|
|
513
|
+
if (res.status !== 200)
|
|
514
|
+
return { check: req.check, status: "unknown", message: `${req.api}/repos/${req.repo} answered ${res.status}` };
|
|
515
|
+
const push = res.json?.permissions?.push;
|
|
516
|
+
if (push === true)
|
|
517
|
+
return { check: req.check, status: "ok", message: `the token in ${req.tokenFrom} may write ${req.repo}` };
|
|
518
|
+
if (push === false)
|
|
519
|
+
return { check: req.check, status: "fail", message: `the token in ${req.tokenFrom} may read ${req.repo} and not write it`, fix: `Give the token write access to ${req.repo}${req.forge === "github" ? " (contents: write)" : ""}.` };
|
|
520
|
+
const scopes = res.header("x-oauth-scopes");
|
|
521
|
+
if (scopes !== null) {
|
|
522
|
+
const list = scopes.split(",").map((s) => s.trim());
|
|
523
|
+
return list.includes("repo") || list.includes("public_repo")
|
|
524
|
+
? { check: req.check, status: "ok", message: `the token in ${req.tokenFrom} has the ${list.includes("repo") ? "repo" : "public_repo"} scope and sees ${req.repo}` }
|
|
525
|
+
: { check: req.check, status: "fail", message: `the token in ${req.tokenFrom} sees ${req.repo} with scopes ${scopes || "none"}, and writing a release needs repo or public_repo`, fix: "Give the token the repo scope." };
|
|
526
|
+
}
|
|
527
|
+
return {
|
|
528
|
+
check: req.check,
|
|
529
|
+
status: "unknown",
|
|
530
|
+
message: `the token in ${req.tokenFrom} sees ${req.repo}; ${req.api} does not say what this kind of token may write${ctx.environment.ci === "github" && req.tokenFrom === "GITHUB_TOKEN" ? ", and a job token gets contents: write from the workflow's permissions" : ""}`,
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
async function checkForge(decl, ctx) {
|
|
534
|
+
const { forgeApi, forgeTokenEnv } = await import("./publish-forge.js");
|
|
535
|
+
const checks = [];
|
|
536
|
+
const t = { kind: "forge", name: `forge ${decl.forge} ${decl.repo}`, checks };
|
|
537
|
+
const api = forgeApi(decl, ctx.env);
|
|
538
|
+
if (!api) {
|
|
539
|
+
checks.push({ check: "forge-api", status: "fail", message: "a Forgejo target has no API root: api is not declared and GITHUB_API_URL is not set", fix: "Declare api on the target, such as https://forgejo.example.com/api/v1." });
|
|
540
|
+
return t;
|
|
541
|
+
}
|
|
542
|
+
const names = forgeTokenEnv(decl);
|
|
543
|
+
const token = readCredential(ctx.env, names, ctx.redactor);
|
|
544
|
+
if (!token) {
|
|
545
|
+
checks.push(missing(ctx, "forge-token", `none of ${names.join(", ")} is set`, `Set ${names[0]}${decl.forge === "github" ? "; in GitHub Actions, GITHUB_TOKEN: ${{ github.token }} in the job's env" : ""}.`));
|
|
546
|
+
return t;
|
|
547
|
+
}
|
|
548
|
+
checks.push({ check: "forge-token", status: "ok", message: `the token comes from ${token.from}` });
|
|
549
|
+
if (decl.forge === "gitlab") {
|
|
550
|
+
checks.push(await gitlabAccess(ctx, api, decl.repo, token));
|
|
551
|
+
return t;
|
|
552
|
+
}
|
|
553
|
+
checks.push(await repoAccess(ctx, { forge: decl.forge, api, repo: decl.repo, token: token.value, check: "forge-access", tokenFrom: token.from }));
|
|
554
|
+
return t;
|
|
555
|
+
}
|
|
556
|
+
/** What a GitLab token may do on a project: its scopes, and its access level there. A job token is not introspectable. */
|
|
557
|
+
async function gitlabAccess(ctx, api, project, token) {
|
|
558
|
+
if (token.from === "CI_JOB_TOKEN")
|
|
559
|
+
return { check: "forge-access", status: "unknown", message: "the token is the job's CI_JOB_TOKEN, whose rights are the job's and can't be read; GitLab lets it create releases and upload to the generic package registry of its own project" };
|
|
560
|
+
const headers = { "private-token": token.value };
|
|
561
|
+
const self = await answer(ctx, `${api}/personal_access_tokens/self`, { method: "GET", headers });
|
|
562
|
+
if (self.status === 401)
|
|
563
|
+
return { check: "forge-access", status: "fail", message: `${api} refused the token in ${token.from} (401)`, fix: `Check ${token.from}; it may have expired.` };
|
|
564
|
+
const scopes = self.json?.scopes;
|
|
565
|
+
if (self.status === 200 && Array.isArray(scopes) && !scopes.includes("api")) {
|
|
566
|
+
return { check: "forge-access", status: "fail", message: `the token in ${token.from} has scopes ${scopes.join(", ") || "none"}, and releases and the package registry need api`, fix: "Give the token the api scope." };
|
|
567
|
+
}
|
|
568
|
+
const proj = await answer(ctx, `${api}/projects/${encodeURIComponent(project)}`, { method: "GET", headers });
|
|
569
|
+
if (proj.status === 404 || proj.status === 403)
|
|
570
|
+
return { check: "forge-access", status: "fail", message: `the token in ${token.from} can't see project ${project} (${proj.status})`, fix: `Give the token's user access to ${project}, or fix repo in the target.` };
|
|
571
|
+
const perms = proj.json?.permissions;
|
|
572
|
+
const level = Math.max(perms?.project_access?.access_level ?? 0, perms?.group_access?.access_level ?? 0);
|
|
573
|
+
if (proj.status === 200 && perms && level >= 30)
|
|
574
|
+
return { check: "forge-access", status: "ok", message: `the token in ${token.from}${Array.isArray(scopes) ? " has the api scope and" : ""} is Developer or above on ${project}` };
|
|
575
|
+
if (proj.status === 200 && perms && level > 0)
|
|
576
|
+
return { check: "forge-access", status: "fail", message: `the token in ${token.from} has access level ${level} on ${project}, and creating a release needs Developer (30)`, fix: `Raise the token's role on ${project} to Developer.` };
|
|
577
|
+
return { check: "forge-access", status: "unknown", message: `${api} did not say what the token in ${token.from} may do on ${project} (${proj.status})` };
|
|
578
|
+
}
|
|
579
|
+
async function checkHomebrew(decl, ctx) {
|
|
580
|
+
const { HOMEBREW_TOKEN_ENV } = await import("./publish-homebrew.js");
|
|
581
|
+
const { githubApi } = await import("./publish-github.js");
|
|
582
|
+
const checks = [];
|
|
583
|
+
const t = { kind: "homebrew", name: `homebrew ${decl.tap}`, checks };
|
|
584
|
+
if (decl.sshKeyEnv) {
|
|
585
|
+
const key = readCredential(ctx.env, [decl.sshKeyEnv], ctx.redactor);
|
|
586
|
+
if (!key)
|
|
587
|
+
checks.push(missing(ctx, "homebrew-credentials", `${decl.sshKeyEnv} is not set`, `Set ${decl.sshKeyEnv} to a deploy key of ${decl.tap} with write access.`));
|
|
588
|
+
else
|
|
589
|
+
checks.push({ check: "homebrew-access", status: "unknown", message: `the SSH key in ${decl.sshKeyEnv} is set; whether it is a deploy key with write access shows only when it pushes` });
|
|
590
|
+
return t;
|
|
591
|
+
}
|
|
592
|
+
const name = decl.tokenEnv ?? HOMEBREW_TOKEN_ENV;
|
|
593
|
+
const token = readCredential(ctx.env, [name], ctx.redactor);
|
|
594
|
+
if (!token) {
|
|
595
|
+
checks.push(missing(ctx, "homebrew-credentials", `${name} is not set`, `Set ${name} to a token that may push to ${decl.tap}.`));
|
|
596
|
+
return t;
|
|
597
|
+
}
|
|
598
|
+
checks.push(await repoAccess(ctx, { forge: "github", api: githubApi(decl.api, ctx.env), repo: decl.tap, token: token.value, check: "homebrew-access", tokenFrom: token.from }));
|
|
599
|
+
return t;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* An index target (#5158): the token is set, and may do what the target's
|
|
603
|
+
* mode needs. `commit`: write the repository. `pull-request`: read the
|
|
604
|
+
* index, push a branch to the fork (or make the fork), and open a pull
|
|
605
|
+
* request, read from the fork's `permissions.push` and a classic token's
|
|
606
|
+
* scopes. A fine-grained or app token's rights on a repository its owner
|
|
607
|
+
* does not own are not shown.
|
|
608
|
+
*/
|
|
609
|
+
async function checkIndex(decl, ctx) {
|
|
610
|
+
const { indexSettings } = await import("./publish-index.js");
|
|
611
|
+
const { githubApi } = await import("./publish-github.js");
|
|
612
|
+
const checks = [];
|
|
613
|
+
let s;
|
|
614
|
+
try {
|
|
615
|
+
s = indexSettings(decl);
|
|
616
|
+
}
|
|
617
|
+
catch (err) {
|
|
618
|
+
const e = err;
|
|
619
|
+
return { kind: "index", name: `index ${decl.name}`, checks: [{ check: "index-config", status: "fail", message: e.message ?? String(err), ...(e.fix ? { fix: e.fix } : {}) }] };
|
|
620
|
+
}
|
|
621
|
+
const t = { kind: "index", name: `index ${s.name} in ${s.repo}${s.mode === "pull-request" ? " (pull request)" : ""}`, checks };
|
|
622
|
+
if (s.sshKeyEnv) {
|
|
623
|
+
const key = readCredential(ctx.env, [s.sshKeyEnv], ctx.redactor);
|
|
624
|
+
if (!key)
|
|
625
|
+
checks.push(missing(ctx, "index-credentials", `${s.sshKeyEnv} is not set`, `Set ${s.sshKeyEnv} to a deploy key of ${s.repo} with write access.`));
|
|
626
|
+
else
|
|
627
|
+
checks.push({ check: "index-access", status: "unknown", message: `the SSH key in ${s.sshKeyEnv} is set; whether it is a deploy key with write access shows only when it pushes` });
|
|
628
|
+
return t;
|
|
629
|
+
}
|
|
630
|
+
const token = readCredential(ctx.env, [s.tokenEnv], ctx.redactor);
|
|
631
|
+
if (!token) {
|
|
632
|
+
checks.push(missing(ctx, "index-credentials", `${s.tokenEnv} is not set`, s.mode === "commit" ? `Set ${s.tokenEnv} to a token that may push to ${s.repo}.` : `Set ${s.tokenEnv} to a classic token with public_repo, which may fork ${s.repo}, push to the fork and open a pull request.`));
|
|
633
|
+
return t;
|
|
634
|
+
}
|
|
635
|
+
const api = githubApi(decl.api, ctx.env);
|
|
636
|
+
if (s.mode === "commit") {
|
|
637
|
+
checks.push(await repoAccess(ctx, { forge: "github", api, repo: s.repo, token: token.value, check: "index-access", tokenFrom: token.from }));
|
|
638
|
+
return t;
|
|
639
|
+
}
|
|
640
|
+
const headers = { authorization: `Bearer ${token.value}`, accept: "application/vnd.github+json" };
|
|
641
|
+
const up = await answer(ctx, `${api}/repos/${s.repo}`, { method: "GET", headers });
|
|
642
|
+
if (up.status === 401) {
|
|
643
|
+
checks.push({ check: "index-upstream", status: "fail", message: `${api} refused the token in ${token.from} (401)`, fix: `Check ${token.from}; it may have expired.` });
|
|
644
|
+
return t;
|
|
645
|
+
}
|
|
646
|
+
if (up.status !== 200) {
|
|
647
|
+
checks.push({ check: "index-upstream", status: "fail", message: `the token in ${token.from} can't see ${s.repo} on ${api} (${up.status})`, fix: `Fix repo in the target, or give the token access to ${s.repo}.` });
|
|
648
|
+
return t;
|
|
649
|
+
}
|
|
650
|
+
checks.push({ check: "index-upstream", status: "ok", message: `the token in ${token.from} sees ${s.repo}` });
|
|
651
|
+
const scopes = up.header("x-oauth-scopes");
|
|
652
|
+
const list = scopes === null ? null : scopes.split(",").map((x) => x.trim()).filter(Boolean);
|
|
653
|
+
const classic = list !== null && (list.includes("repo") || list.includes("public_repo"));
|
|
654
|
+
const fork = s.fork ?? null;
|
|
655
|
+
if (fork !== null) {
|
|
656
|
+
checks.push(await repoAccess(ctx, { forge: "github", api, repo: fork, token: token.value, check: "index-fork", tokenFrom: token.from }));
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
const me = await answer(ctx, `${api}/user`, { method: "GET", headers });
|
|
660
|
+
const login = me.json?.login;
|
|
661
|
+
if (me.status !== 200 || typeof login !== "string") {
|
|
662
|
+
checks.push({ check: "index-fork", status: "unknown", message: `${api}/user did not name the token's user (${me.status}), so its fork of ${s.repo} can't be found; the publish asks GitHub for it` });
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
const repoName = s.repo.split("/")[1];
|
|
666
|
+
const theirs = await answer(ctx, `${api}/repos/${login}/${repoName}`, { method: "GET", headers });
|
|
667
|
+
const body = theirs.json;
|
|
668
|
+
if (theirs.status === 200 && body?.fork === true && body.permissions?.push !== false) {
|
|
669
|
+
checks.push({ check: "index-fork", status: "ok", message: `${login}/${repoName} is ${login}'s fork of ${s.repo}, and the token may push its branch there` });
|
|
670
|
+
}
|
|
671
|
+
else if (theirs.status === 200 && body?.fork !== true) {
|
|
672
|
+
checks.push({ check: "index-fork", status: "warn", message: `${login}/${repoName} is a repository of ${login} that is not a fork, so GitHub names the fork it makes otherwise`, fix: `Fork ${s.repo} and set fork in the target to it.` });
|
|
673
|
+
}
|
|
674
|
+
else if (classic) {
|
|
675
|
+
checks.push({ check: "index-fork", status: "ok", message: `${login} has no fork of ${s.repo}; the publish makes one, which the token's ${list.includes("repo") ? "repo" : "public_repo"} scope allows` });
|
|
676
|
+
}
|
|
677
|
+
else if (list !== null) {
|
|
678
|
+
checks.push({ check: "index-fork", status: "fail", message: `${login} has no fork of ${s.repo}, and the token in ${token.from} has scopes ${scopes || "none"}, which can't make one`, fix: "Give the token the public_repo scope, or fork the index and set fork in the target." });
|
|
679
|
+
}
|
|
680
|
+
else {
|
|
681
|
+
checks.push({ check: "index-fork", status: "unknown", message: `${login} has no fork of ${s.repo}; whether this kind of token may make one shows only when the publish asks` });
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
checks.push(classic
|
|
686
|
+
? { check: "index-pull-request", status: "ok", message: `the token in ${token.from} has the ${list.includes("repo") ? "repo" : "public_repo"} scope, which may open a pull request on ${s.repo}` }
|
|
687
|
+
: list !== null
|
|
688
|
+
? { check: "index-pull-request", status: "fail", message: `the token in ${token.from} has scopes ${scopes || "none"}, and opening a pull request on ${s.repo} needs public_repo or repo`, fix: "Give the token the public_repo scope." }
|
|
689
|
+
: {
|
|
690
|
+
check: "index-pull-request",
|
|
691
|
+
status: "unknown",
|
|
692
|
+
message: `GitHub does not say what this kind of token may do on ${s.repo}, which its owner may not own; opening the pull request shows whether it can`,
|
|
693
|
+
});
|
|
694
|
+
return t;
|
|
695
|
+
}
|
|
696
|
+
async function checkTauri(decl, ctx) {
|
|
697
|
+
const { githubApi } = await import("./publish-github.js");
|
|
698
|
+
const checks = [];
|
|
699
|
+
const t = { kind: "tauri-updater", name: `tauri-updater ${decl.repo}`, checks };
|
|
700
|
+
const name = decl.tokenEnv ?? "GITHUB_TOKEN";
|
|
701
|
+
const token = readCredential(ctx.env, [name], ctx.redactor);
|
|
702
|
+
if (!token) {
|
|
703
|
+
checks.push(missing(ctx, "tauri-token", `${name} is not set`, `Set ${name}.`));
|
|
704
|
+
return t;
|
|
705
|
+
}
|
|
706
|
+
checks.push(await repoAccess(ctx, { forge: "github", api: githubApi(decl.api, ctx.env), repo: decl.repo, token: token.value, check: "tauri-access", tokenFrom: token.from }));
|
|
707
|
+
return t;
|
|
708
|
+
}
|
|
709
|
+
// MCP Registry
|
|
710
|
+
/**
|
|
711
|
+
* The `server.json` is read and its name checked against the namespace the
|
|
712
|
+
* auth can claim, the registry is asked whether it serves and holds the
|
|
713
|
+
* server, and under GitHub OIDC in CI the exchange for a registry token is
|
|
714
|
+
* made, which proves the registry takes this run for the name's owner. The
|
|
715
|
+
* version is not checked: the cut stamps the label into the file.
|
|
716
|
+
*/
|
|
717
|
+
async function checkMcpRegistry(decl, ctx) {
|
|
718
|
+
const { MCP_REGISTRY, MCP_GITHUB_TOKEN_ENV, MCP_REGISTRY_TOKEN_ENV, mcpRegistryAudience } = await import("./publish-mcp-registry.js");
|
|
719
|
+
const registry = (decl.registry ?? MCP_REGISTRY).replace(/\/+$/, "");
|
|
720
|
+
const path = decl.server ?? "server.json";
|
|
721
|
+
const checks = [];
|
|
722
|
+
const t = { kind: "mcp-registry", name: `mcp-registry ${path}`, checks };
|
|
723
|
+
const abs = isAbsolute(path) ? path : resolve(ctx.cwd, path);
|
|
724
|
+
if (!existsSync(abs)) {
|
|
725
|
+
checks.push({ check: "mcp-registry-server", status: "fail", message: `${path} does not exist in ${ctx.cwd}`, fix: "Add the server.json, with the name and the packages it publishes." });
|
|
726
|
+
return t;
|
|
727
|
+
}
|
|
728
|
+
let name;
|
|
729
|
+
try {
|
|
730
|
+
const m = JSON.parse(readFileSync(abs, "utf-8"));
|
|
731
|
+
if (typeof m.name !== "string" || !m.name)
|
|
732
|
+
throw new Error("it has no name");
|
|
733
|
+
name = m.name;
|
|
734
|
+
}
|
|
735
|
+
catch (err) {
|
|
736
|
+
checks.push({ check: "mcp-registry-server", status: "fail", message: `${path} is not a server.json: ${err instanceof Error ? err.message : String(err)}`, fix: "Fix the file." });
|
|
737
|
+
return t;
|
|
738
|
+
}
|
|
739
|
+
t.name = `mcp-registry ${name}`;
|
|
740
|
+
const auth = decl.auth ?? "github-oidc";
|
|
741
|
+
const owner = ctx.environment.repository?.split("/")[0]?.toLowerCase() ?? null;
|
|
742
|
+
const namespace = /^io\.github\.([^/]+)\//i.exec(name)?.[1]?.toLowerCase() ?? null;
|
|
743
|
+
if (auth === "github-oidc" && namespace === null) {
|
|
744
|
+
checks.push({ check: "mcp-registry-namespace", status: "fail", message: `${name} is not under io.github.<owner>/, the only namespace a GitHub OIDC login can claim`, fix: `Name the server io.github.${owner ?? "<owner>"}/<name>, or publish with registry-token after a DNS or HTTP login.` });
|
|
745
|
+
}
|
|
746
|
+
else if (auth === "github-oidc" && owner !== null && namespace !== owner) {
|
|
747
|
+
checks.push({ check: "mcp-registry-namespace", status: "fail", message: `${name} is under io.github.${namespace}/, and this repository's owner is ${owner}`, fix: `Name the server io.github.${owner}/<name>.` });
|
|
748
|
+
}
|
|
749
|
+
else {
|
|
750
|
+
checks.push({ check: "mcp-registry-namespace", status: "ok", message: `${name} is a namespace the ${auth} login can claim` });
|
|
751
|
+
}
|
|
752
|
+
const held = await answer(ctx, `${registry}/v0.1/servers/${encodeURIComponent(name)}/versions`, { method: "GET", headers: {} });
|
|
753
|
+
checks.push(held.status === 200
|
|
754
|
+
? { check: "mcp-registry-server-listed", status: "ok", message: `${name} is on ${registry}` }
|
|
755
|
+
: held.status === 404
|
|
756
|
+
? { check: "mcp-registry-server-listed", status: "ok", message: `${name} is not on ${registry} yet; the first publish adds it` }
|
|
757
|
+
: { check: "mcp-registry-server-listed", status: "unknown", message: `${registry} answered ${held.status} for ${name}'s versions` });
|
|
758
|
+
if (auth !== "github-oidc") {
|
|
759
|
+
const names = [decl.tokenEnv ?? (auth === "github-token" ? MCP_GITHUB_TOKEN_ENV : MCP_REGISTRY_TOKEN_ENV)];
|
|
760
|
+
const token = readCredential(ctx.env, names, ctx.redactor);
|
|
761
|
+
if (!token) {
|
|
762
|
+
checks.push(missing(ctx, "mcp-registry-token", `${names[0]} is not set`, `Set ${names[0]}.`));
|
|
763
|
+
}
|
|
764
|
+
else if (auth === "github-token") {
|
|
765
|
+
const ex = await answer(ctx, `${registry}/v0.1/auth/github-at`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ github_token: token.value }) });
|
|
766
|
+
const value = ex.json?.registry_token;
|
|
767
|
+
if (typeof value === "string")
|
|
768
|
+
ctx.redactor.add(value);
|
|
769
|
+
checks.push(ex.status === 200 && typeof value === "string" ? { check: "mcp-registry-auth", status: "ok", message: `the registry takes the token from ${token.from}` } : { check: "mcp-registry-auth", status: "fail", message: `the registry gave no token for the one in ${token.from} (${ex.status}${ex.text ? `: ${short(ex.text)}` : ""})`, fix: "Check the GitHub token, and that its owner may publish the server's namespace." });
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
checks.push({ check: "mcp-registry-auth", status: "unknown", message: `the token in ${token.from} is set; a registry token is checked only when it publishes` });
|
|
773
|
+
}
|
|
774
|
+
return t;
|
|
775
|
+
}
|
|
776
|
+
if (!ctx.environment.ci) {
|
|
777
|
+
checks.push({ check: "mcp-registry-auth", status: "unknown", message: `whether the registry takes this workflow as the owner of ${name} can only be tested by ${onlyTheWorkflow(ctx)}, with its OIDC token` });
|
|
778
|
+
return t;
|
|
779
|
+
}
|
|
780
|
+
const audience = mcpRegistryAudience(registry);
|
|
781
|
+
// The target reads only GitHub Actions' token service, so no variable stands in for it.
|
|
782
|
+
const tok = await idToken(ctx, audience, "");
|
|
783
|
+
if ("none" in tok) {
|
|
784
|
+
checks.push({ check: "mcp-registry-auth", status: "fail", message: ctx.environment.ci === "github" ? tok.none : "this publish gets its OIDC token from GitHub Actions, and this run is not one", fix: "Give the job permissions: id-token: write." });
|
|
785
|
+
return t;
|
|
786
|
+
}
|
|
787
|
+
const ex = await answer(ctx, `${registry}/v0.1/auth/github-oidc`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ oidc_token: tok.token }) });
|
|
788
|
+
const value = ex.json?.registry_token;
|
|
789
|
+
if (typeof value === "string")
|
|
790
|
+
ctx.redactor.add(value);
|
|
791
|
+
checks.push(ex.status === 200 && typeof value === "string"
|
|
792
|
+
? { check: "mcp-registry-auth", status: "ok", message: `the registry takes this run's GitHub OIDC token` }
|
|
793
|
+
: { check: "mcp-registry-auth", status: "fail", message: `the registry gave no token for this run's OIDC token (${ex.status}${ex.text ? `: ${short(ex.text)}` : ""})`, fix: "Publish from a GitHub Actions job with id-token: write." });
|
|
794
|
+
return t;
|
|
795
|
+
}
|
|
796
|
+
// Marketplaces
|
|
797
|
+
/** The extension's publisher and name: from the `.vsix` when it is built, else from the member's package.json. */
|
|
798
|
+
async function extensionIdentity(decl, ctx) {
|
|
799
|
+
const abs = isAbsolute(decl.vsix) ? decl.vsix : resolve(ctx.cwd, decl.vsix);
|
|
800
|
+
if (existsSync(abs)) {
|
|
801
|
+
const { vsixIdentity } = await import("./publish-marketplace.js");
|
|
802
|
+
try {
|
|
803
|
+
const id = vsixIdentity(readFileSync(abs), decl.vsix);
|
|
804
|
+
return { publisher: id.publisher, name: id.name, from: decl.vsix };
|
|
805
|
+
}
|
|
806
|
+
catch {
|
|
807
|
+
return null;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
const pkg = join(ctx.cwd, "package.json");
|
|
811
|
+
if (!existsSync(pkg))
|
|
812
|
+
return null;
|
|
813
|
+
try {
|
|
814
|
+
const m = JSON.parse(readFileSync(pkg, "utf-8"));
|
|
815
|
+
return typeof m.publisher === "string" && typeof m.name === "string" ? { publisher: m.publisher, name: m.name, from: "package.json" } : null;
|
|
816
|
+
}
|
|
817
|
+
catch {
|
|
818
|
+
return null;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
async function checkMarketplace(decl, ctx) {
|
|
822
|
+
const { OPEN_VSX_REGISTRY, VSCODE_GALLERY, OVSX_ID_TOKEN_ENV, marketplaceTokenEnv } = await import("./publish-marketplace.js");
|
|
823
|
+
const label = decl.marketplace === "vscode" ? "the VS Code Marketplace" : "Open VSX";
|
|
824
|
+
const registry = (decl.registry ?? (decl.marketplace === "vscode" ? VSCODE_GALLERY : OPEN_VSX_REGISTRY)).replace(/\/+$/, "");
|
|
825
|
+
const checks = [];
|
|
826
|
+
const t = { kind: "marketplace", name: `marketplace ${decl.marketplace}`, checks };
|
|
827
|
+
const id = await extensionIdentity(decl, ctx);
|
|
828
|
+
if (!id) {
|
|
829
|
+
checks.push({ check: "marketplace-identity", status: "unknown", message: `${decl.vsix} is not built, and the member's package.json names no publisher and name, so the extension can't be looked up` });
|
|
830
|
+
return t;
|
|
831
|
+
}
|
|
832
|
+
t.name = `marketplace ${decl.marketplace} ${id.publisher}.${id.name}`;
|
|
833
|
+
const auth = decl.auth ?? "token";
|
|
834
|
+
if (decl.marketplace === "openvsx") {
|
|
835
|
+
const ns = await answer(ctx, `${registry}/api/${encodeURIComponent(id.publisher)}`, { method: "GET", headers: {} });
|
|
836
|
+
checks.push(ns.status === 200
|
|
837
|
+
? { check: "marketplace-namespace", status: "ok", message: `the namespace ${id.publisher} is on ${registry}` }
|
|
838
|
+
: ns.status === 404
|
|
839
|
+
? { check: "marketplace-namespace", status: "fail", message: `${registry} has no namespace ${id.publisher}`, fix: `Create it: ovsx create-namespace ${id.publisher}.` }
|
|
840
|
+
: { check: "marketplace-namespace", status: "unknown", message: `${registry}/api/${id.publisher} answered ${ns.status}` });
|
|
841
|
+
if (auth === "trusted-publishing") {
|
|
842
|
+
if (!ctx.environment.ci && !ctx.env[OVSX_ID_TOKEN_ENV]) {
|
|
843
|
+
checks.push({ check: "marketplace-trusted-publisher", status: "unknown", message: `whether Open VSX takes this workflow as a trusted publisher of ${id.publisher}.${id.name} can only be tested by ${onlyTheWorkflow(ctx)}, with its OIDC token` });
|
|
844
|
+
return t;
|
|
845
|
+
}
|
|
846
|
+
const tok = await idToken(ctx, registry, OVSX_ID_TOKEN_ENV);
|
|
847
|
+
if ("none" in tok) {
|
|
848
|
+
checks.push({ check: "marketplace-trusted-publisher", status: "fail", message: tok.none, fix: `Give the job permissions: id-token: write, or put an ID token in ${OVSX_ID_TOKEN_ENV}.` });
|
|
849
|
+
return t;
|
|
850
|
+
}
|
|
851
|
+
const ex = await answer(ctx, `${registry}/api/-/trusted-publishing/token`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ namespace: id.publisher, extension: id.name, token: tok.token }) });
|
|
852
|
+
const value = ex.json?.value;
|
|
853
|
+
if (typeof value === "string")
|
|
854
|
+
ctx.redactor.add(value);
|
|
855
|
+
checks.push(ex.status >= 200 && ex.status < 300 && typeof value === "string"
|
|
856
|
+
? { check: "marketplace-trusted-publisher", status: "ok", message: `Open VSX takes this workflow as a trusted publisher of ${id.publisher}.${id.name}` }
|
|
857
|
+
: { check: "marketplace-trusted-publisher", status: "fail", message: `Open VSX gave no trusted-publishing token for ${id.publisher}.${id.name} (${ex.status}${ex.text ? `: ${short(ex.text)}` : ""})`, fix: `Register this workflow at ${registry}/user-settings/trusted-publishers.` });
|
|
858
|
+
return t;
|
|
859
|
+
}
|
|
860
|
+
const names = marketplaceTokenEnv(decl);
|
|
861
|
+
const token = readCredential(ctx.env, names, ctx.redactor);
|
|
862
|
+
checks.push(token ? { check: "marketplace-token", status: "unknown", message: `the token in ${token.from} is set; Open VSX has no read-only check of a token, so whether it may publish to ${id.publisher} shows at the upload` } : missing(ctx, "marketplace-token", `${names[0]} is not set`, `Set ${names[0]} to an Open VSX access token.`));
|
|
863
|
+
return t;
|
|
864
|
+
}
|
|
865
|
+
// The VS Code Marketplace: vsce verify-pat asks the marketplace for the identity's role on the publisher and changes nothing.
|
|
866
|
+
let env = { ...ctx.env };
|
|
867
|
+
let args = ["verify-pat", id.publisher];
|
|
868
|
+
if (auth === "azure-credential") {
|
|
869
|
+
delete env.VSCE_PAT;
|
|
870
|
+
args = [...args, "--azure-credential"];
|
|
871
|
+
}
|
|
872
|
+
else {
|
|
873
|
+
const names = marketplaceTokenEnv(decl);
|
|
874
|
+
const token = readCredential(ctx.env, names, ctx.redactor);
|
|
875
|
+
if (!token) {
|
|
876
|
+
checks.push(missing(ctx, "marketplace-token", `${names[0]} is not set`, `Set ${names[0]} to a personal access token with the Marketplace (Manage) scope.`));
|
|
877
|
+
return t;
|
|
878
|
+
}
|
|
879
|
+
env = { ...env, VSCE_PAT: token.value };
|
|
880
|
+
}
|
|
881
|
+
const r = await ctx.run(ctx.vsce, args, { cwd: ctx.cwd, env }).catch((err) => ({ code: 127, stdout: "", stderr: err instanceof Error ? err.message : String(err) }));
|
|
882
|
+
const said = short((r.stderr || r.stdout).trim().split("\n").at(-1) ?? "");
|
|
883
|
+
checks.push(r.code === 0
|
|
884
|
+
? { check: "marketplace-access", status: "ok", message: `${label} takes the ${auth === "azure-credential" ? "Entra identity" : "token"} for publisher ${id.publisher}` }
|
|
885
|
+
: r.code === 127
|
|
886
|
+
? { check: "marketplace-access", status: ctx.environment.ci ? "fail" : "unknown", message: `vsce could not be run, so the ${auth === "azure-credential" ? "identity" : "token"} was not checked: ${said}`, fix: "npm install -g @vscode/vsce" }
|
|
887
|
+
: { check: "marketplace-access", status: "fail", message: `vsce verify-pat refused publisher ${id.publisher}: ${said}`, fix: auth === "azure-credential" ? `Add the job's Entra identity to the publisher ${id.publisher} as a member.` : `Give the token the Marketplace (Manage) scope for ${id.publisher}.` });
|
|
888
|
+
return t;
|
|
889
|
+
}
|
|
890
|
+
// Python and Rust registries (#5167)
|
|
891
|
+
async function checkPypi(decl, ctx) {
|
|
892
|
+
const { PYPI_ID_TOKEN_ENV, normalizeProjectName, pypiAuth, pypiIndex, pypiProjectName, pypiTokenEnv } = await import("./publish-pypi.js");
|
|
893
|
+
const index = pypiIndex(decl);
|
|
894
|
+
const checks = [];
|
|
895
|
+
const name = pypiProjectName(ctx.cwd, decl.files);
|
|
896
|
+
const t = { kind: "pypi", name: `pypi ${index.label}${name ? ` ${name}` : ""}`, checks };
|
|
897
|
+
let exists = null;
|
|
898
|
+
if (!name) {
|
|
899
|
+
checks.push({ check: "pypi-project", status: "unknown", message: "no distribution is built and pyproject.toml names no [project] name, so the project can't be looked up" });
|
|
900
|
+
}
|
|
901
|
+
else {
|
|
902
|
+
const res = await answer(ctx, `${index.simple}${normalizeProjectName(name)}/`, { method: "GET", headers: { accept: "application/vnd.pypi.simple.v1+json" } });
|
|
903
|
+
exists = res.status === 200 ? true : res.status === 404 ? false : null;
|
|
904
|
+
checks.push(exists === true
|
|
905
|
+
? { check: "pypi-project", status: "ok", message: `${index.label} has the project ${name}` }
|
|
906
|
+
: exists === false
|
|
907
|
+
? { check: "pypi-project", status: "warn", message: `${index.label} has no project ${name} yet; the first upload creates it`, fix: index.site ? `For trusted publishing, add a pending publisher for ${name} at ${index.site}/manage/account/publishing/.` : undefined }
|
|
908
|
+
: { check: "pypi-project", status: "unknown", message: `${index.simple}${normalizeProjectName(name)}/ answered ${res.status}` });
|
|
909
|
+
}
|
|
910
|
+
const auth = pypiAuth(decl, ctx.env);
|
|
911
|
+
if (auth === "token") {
|
|
912
|
+
const tokenName = pypiTokenEnv(decl);
|
|
913
|
+
const token = readCredential(ctx.env, [tokenName], ctx.redactor);
|
|
914
|
+
checks.push(token
|
|
915
|
+
? { check: "pypi-token", status: "unknown", message: `the token in ${tokenName} is set; ${index.label} has no read-only check of a token, so whether it may upload shows at the upload` }
|
|
916
|
+
: missing(ctx, "pypi-token", `${tokenName} is not set${index.site ? " and there is no OIDC ID token for trusted publishing" : ""}`, `Set ${tokenName} to an API token for the project${index.site ? ", or publish with trusted publishing from a CI job with an OIDC ID token" : ""}.`));
|
|
917
|
+
return t;
|
|
918
|
+
}
|
|
919
|
+
if (!ctx.environment.ci && !ctx.env[PYPI_ID_TOKEN_ENV]) {
|
|
920
|
+
checks.push({ check: "pypi-trusted-publisher", status: "unknown", message: `whether ${index.label} takes this workflow as a trusted publisher can only be tested by ${onlyTheWorkflow(ctx)}, with its OIDC token` });
|
|
921
|
+
return t;
|
|
922
|
+
}
|
|
923
|
+
const aud = await answer(ctx, `${index.site}/_/oidc/audience`, { method: "GET", headers: { accept: "application/json" } });
|
|
924
|
+
const audience = aud.json?.audience;
|
|
925
|
+
if (typeof audience !== "string") {
|
|
926
|
+
checks.push({ check: "pypi-trusted-publisher", status: "fail", message: `${index.site}/_/oidc/audience answered ${aud.status}, so trusted publishing can't start` });
|
|
927
|
+
return t;
|
|
928
|
+
}
|
|
929
|
+
const tok = await idToken(ctx, audience, PYPI_ID_TOKEN_ENV);
|
|
930
|
+
if ("none" in tok) {
|
|
931
|
+
checks.push({ check: "pypi-trusted-publisher", status: "fail", message: tok.none, fix: `Give the job permissions: id-token: write, or declare ${PYPI_ID_TOKEN_ENV} under the GitLab job's id_tokens with the audience ${audience}.` });
|
|
932
|
+
return t;
|
|
933
|
+
}
|
|
934
|
+
const ex = await answer(ctx, `${index.site}/_/oidc/mint-token`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ token: tok.token }) });
|
|
935
|
+
const value = ex.json?.token;
|
|
936
|
+
if (typeof value === "string")
|
|
937
|
+
ctx.redactor.add(value);
|
|
938
|
+
checks.push(ex.status >= 200 && ex.status < 300 && typeof value === "string"
|
|
939
|
+
? { check: "pypi-trusted-publisher", status: "ok", message: `${index.label} takes this workflow as a trusted publisher` }
|
|
940
|
+
: { 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
|
+
return t;
|
|
942
|
+
}
|
|
943
|
+
async function checkCargo(decl, ctx) {
|
|
944
|
+
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
|
+
const label = decl.registry ? `registry ${decl.registry}` : "crates.io";
|
|
946
|
+
const checks = [];
|
|
947
|
+
const t = { kind: "cargo", name: `cargo ${label}`, checks };
|
|
948
|
+
const manifest = resolve(ctx.cwd, decl.manifest ?? "Cargo.toml");
|
|
949
|
+
let names = [];
|
|
950
|
+
try {
|
|
951
|
+
const crates = cargoPublishOrder(await cargoWorkspace(ctx.cargo, manifest, ctx.cwd, ctx.env, (bin, args, cwd, env) => ctx.run(bin, args, { cwd, env })), decl);
|
|
952
|
+
names = crates.map((c) => c.name);
|
|
953
|
+
t.name = `cargo ${label} ${names.join(", ")}`;
|
|
954
|
+
checks.push({ check: "cargo-crates", status: "ok", message: `publishes ${crates.map((c) => `${c.name}@${c.version}`).join(", ")}, in that order` });
|
|
955
|
+
}
|
|
956
|
+
catch (err) {
|
|
957
|
+
const code = err.code;
|
|
958
|
+
checks.push({ check: "cargo-crates", status: code === "publish-cargo-missing" ? (ctx.environment.ci ? "fail" : "unknown") : "fail", message: err instanceof Error ? err.message : String(err), ...(err.fix ? { fix: err.fix } : {}) });
|
|
959
|
+
}
|
|
960
|
+
const index = (decl.index ?? CRATES_IO_INDEX).replace(/^sparse\+/, "").replace(/\/*$/, "/");
|
|
961
|
+
const fresh = [];
|
|
962
|
+
for (const n of names) {
|
|
963
|
+
const res = await answer(ctx, `${index}${sparseIndexPath(n)}`, { method: "GET", headers: {} });
|
|
964
|
+
if (res.status === 404)
|
|
965
|
+
fresh.push(n);
|
|
966
|
+
}
|
|
967
|
+
if (fresh.length > 0)
|
|
968
|
+
checks.push({ check: "cargo-new-crates", status: "warn", message: `${fresh.join(", ")} ${fresh.length === 1 ? "is" : "are"} not on ${label} yet; the first version of a crate needs a token that may publish new crates, and trusted publishing can't make one` });
|
|
969
|
+
const auth = cargoAuth(decl, ctx.env);
|
|
970
|
+
if (auth === "token") {
|
|
971
|
+
const tokenName = cargoTokenEnv(decl);
|
|
972
|
+
const token = readCredential(ctx.env, [tokenName], ctx.redactor);
|
|
973
|
+
checks.push(token ? { check: "cargo-token", status: "unknown", message: `the token in ${tokenName} is set; ${label} has no read-only check of a token, so whether it may publish shows at the publish` } : missing(ctx, "cargo-token", `${tokenName} is not set`, `Set ${tokenName} to a token of ${label}.`));
|
|
974
|
+
return t;
|
|
975
|
+
}
|
|
976
|
+
if (!ctx.environment.ci && !ctx.env[CRATES_IO_ID_TOKEN_ENV]) {
|
|
977
|
+
checks.push({ check: "cargo-trusted-publisher", status: "unknown", message: `whether crates.io takes this workflow as a trusted publisher can only be tested by ${onlyTheWorkflow(ctx)}, with its OIDC token` });
|
|
978
|
+
return t;
|
|
979
|
+
}
|
|
980
|
+
const tok = await idToken(ctx, CRATES_IO_AUDIENCE, CRATES_IO_ID_TOKEN_ENV);
|
|
981
|
+
if ("none" in tok) {
|
|
982
|
+
checks.push({ check: "cargo-trusted-publisher", status: "fail", message: tok.none, fix: "Give the job permissions: id-token: write." });
|
|
983
|
+
return t;
|
|
984
|
+
}
|
|
985
|
+
const api = (decl.api ?? CRATES_IO_API).replace(/\/+$/, "");
|
|
986
|
+
const ex = await answer(ctx, `${api}/api/v1/trusted_publishing/tokens`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ jwt: tok.token }) });
|
|
987
|
+
const value = ex.json?.token;
|
|
988
|
+
if (typeof value === "string") {
|
|
989
|
+
ctx.redactor.add(value);
|
|
990
|
+
await answer(ctx, `${api}/api/v1/trusted_publishing/tokens`, { method: "DELETE", headers: { authorization: `Bearer ${value}` } }).catch(() => null);
|
|
991
|
+
}
|
|
992
|
+
checks.push(ex.status >= 200 && ex.status < 300 && typeof value === "string"
|
|
993
|
+
? { check: "cargo-trusted-publisher", status: "ok", message: "crates.io takes this workflow as a trusted publisher; the token it gave was revoked" }
|
|
994
|
+
: { check: "cargo-trusted-publisher", status: "fail", message: `crates.io gave no token for this run (${ex.status}${ex.text ? `: ${short(ex.text)}` : ""})`, fix: "Add this repository and workflow as a trusted publisher in each crate's settings on crates.io." });
|
|
995
|
+
return t;
|
|
996
|
+
}
|