package-registry-manager 0.25.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +5 -0
  2. package/package.json +3 -3
  3. package/src/audit-config.mjs +96 -0
  4. package/src/bootstrap-recovery.mjs +163 -0
  5. package/src/cpp-distribution.mjs +164 -0
  6. package/src/credential-cycle.mjs +8 -3
  7. package/src/credential-requirements.mjs +105 -0
  8. package/src/default-browser.mjs +1 -1
  9. package/src/default-scope.mjs +1 -1
  10. package/src/discovery.mjs +289 -24
  11. package/src/distribution-channel.mjs +87 -0
  12. package/src/exec.mjs +20 -0
  13. package/src/extra-flows.mjs +122 -2
  14. package/src/flows.mjs +19 -3
  15. package/src/generated-artifact.mjs +48 -0
  16. package/src/github.mjs +4 -0
  17. package/src/identity-conflicts.mjs +130 -0
  18. package/src/manifest-proposal.mjs +1 -1
  19. package/src/model.mjs +6 -0
  20. package/src/npm-release.mjs +68 -0
  21. package/src/nuget-ci.mjs +238 -0
  22. package/src/nuget-migration.mjs +275 -0
  23. package/src/nuget-page.mjs +100 -0
  24. package/src/nuget-policy.mjs +198 -0
  25. package/src/nuget-publish.py +145 -0
  26. package/src/nuget-setup.mjs +169 -0
  27. package/src/nuget-workflow.mjs +54 -0
  28. package/src/organization-scan.mjs +41 -2
  29. package/src/pack-review.mjs +122 -0
  30. package/src/package-coverage.mjs +33 -9
  31. package/src/plan.mjs +35 -9
  32. package/src/prerequisites.mjs +1 -1
  33. package/src/profile.mjs +1 -1
  34. package/src/publication-state.mjs +299 -0
  35. package/src/publishers.mjs +78 -12
  36. package/src/publishing-policy.mjs +7 -1
  37. package/src/publishing-state.mjs +74 -1
  38. package/src/python.mjs +1 -1
  39. package/src/registry-state.mjs +118 -3
  40. package/src/release-runs.mjs +3 -4
  41. package/src/setup-batch.mjs +48 -2
  42. package/src/setup.mjs +82 -120
  43. package/src/sign-in-import.mjs +132 -40
  44. package/src/skips.mjs +9 -1
  45. package/src/source-code.mjs +1 -1
  46. package/src/tokens.mjs +32 -4
  47. package/src/workflow-migration.mjs +15 -2
  48. package/src/workflow-proposal.mjs +6 -2
@@ -1,4 +1,4 @@
1
- import { publishingPolicy } from "./publishing-state.mjs";
1
+ import { authenticationFacts, publishingPolicy } from "./publishing-state.mjs";
2
2
  import { readFile, realpath, stat } from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { stripComments, commandPosition } from "./source-code.mjs";
@@ -15,10 +15,16 @@ export const TRUSTED_REGISTRIES = Object.freeze([
15
15
 
16
16
  export const JOB_PATTERNS = new Map([
17
17
  ["rubygems", /\bgem\s+push\b|rubygems\/release-gem/],
18
- ["nuget", /\bdotnet\s+nuget\s+push\b|\bnuget\s+push\b/],
18
+ [
19
+ "nuget",
20
+ /\bdotnet\s+nuget\s+push\b|PRM_NUGET_OIDC|\bnuget\s+push\b|PRM_NUGET_OIDC/,
21
+ ],
19
22
  ["jsr", /\bdeno\s+publish\b|\bjsr\s+publish\b/],
20
23
  ["docker-hub", /docker\/login-action|\bdocker\s+(?:login|push)\b/],
21
- ["maven-central", /\bmvn\s+(?:-\S+\s+)*deploy\b|\bgradle(?:w)?\s+publish\b/],
24
+ [
25
+ "maven-central",
26
+ /(?:\.\/|\b)mvnw?\s+(?:-\S+\s+)*deploy\b|(?:\.\/|\b)gradlew?\s+(?:-\S+\s+)*publish\b/,
27
+ ],
22
28
  ["vscode-marketplace", /\bvsce\s+publish\b/],
23
29
  ["open-vsx", /\bovsx\s+publish\b/],
24
30
  [
@@ -39,6 +45,20 @@ export const JOB_PATTERNS = new Map([
39
45
  ],
40
46
  ]);
41
47
 
48
+ /**
49
+ * Registries without an upload command: a release is a tag, a GitHub release
50
+ * asset or a registry update hook. The evidence is matched anywhere in the
51
+ * job's executable lines, as the URL is usually an argument.
52
+ */
53
+ export const RELEASE_EVIDENCE = new Map([
54
+ ["packagist", /packagist\.org\/api\/(?:update|create)-package/],
55
+ [
56
+ "go-modules",
57
+ /\bgh\s+release\s+create\b|\bgit\s+push\b[^\n]*\btags?\b|proxy\.golang\.org/,
58
+ ],
59
+ ["cmake", /\bgh\s+release\s+(?:create|upload)\b/],
60
+ ]);
61
+
42
62
  // Scripts usually pass the subcommand as a separate argument, as in
43
63
  // `spawnSync("npm", ["publish"])` or `Command::new("cargo")` followed by
44
64
  // `.arg("publish")` within the next few lines.
@@ -149,11 +169,28 @@ export function parseWorkflow(contents) {
149
169
  export async function detectPublisher(root, workflows, registry) {
150
170
  const result = await detectPublisherDetails(root, workflows, registry);
151
171
  if (
152
- ["crates-io", "npm", "pypi"].includes(registry) &&
172
+ ["crates-io", "npm", "pypi", "nuget"].includes(registry) &&
153
173
  (result.workflow || result.candidates.length)
154
174
  ) {
155
- result.policy = await publishingPolicies(root, workflows, registry);
156
- if (result.policy !== "oidc-with-token-fallback") {
175
+ const { policy, gates } = await publishingPolicies(
176
+ root,
177
+ workflows,
178
+ registry,
179
+ );
180
+ result.policy = policy;
181
+ if (gates.length) {
182
+ result.gate = gates[0].gate;
183
+ if (gates.some((facts) => facts.passwordAlwaysToken)) {
184
+ result.warnings.push(
185
+ `the publish password expression \`vars.${result.gate.variable} == 'true' && '' || secrets.*\` always selects the token ('' is falsy in GitHub expressions); the variable cannot switch to OIDC`,
186
+ );
187
+ }
188
+ }
189
+ if (result.policy === "variable-gated-oidc-with-token-fallback") {
190
+ result.warnings.push(
191
+ `publishing selects OIDC only when the repository variable ${result.gate?.variable ?? "gate"} is 'true' and otherwise uses the token; register the trusted publisher, verify it, then set the variable`,
192
+ );
193
+ } else if (result.policy !== "oidc-with-token-fallback") {
157
194
  result.warnings.push(
158
195
  `publishing authentication is ${result.policy}; migrate to OIDC with token fallback`,
159
196
  );
@@ -170,6 +207,7 @@ async function publishingPolicies(root, workflows, registry) {
170
207
  ]),
171
208
  );
172
209
  const policies = [];
210
+ const gates = [];
173
211
  const visit = async (name, callerGrant, seen = new Set()) => {
174
212
  if (seen.has(name) || !parsed.has(name)) {
175
213
  return;
@@ -193,6 +231,13 @@ async function publishingPolicies(root, workflows, registry) {
193
231
  if (called) {
194
232
  await visit(called, grant, new Set([...seen, name]));
195
233
  } else if (await jobPublishes(root, workflow, job, registry)) {
234
+ const facts = authenticationFacts(
235
+ [...workflow.header, ...job.lines].join("\n"),
236
+ registry,
237
+ );
238
+ if (facts.gate) {
239
+ gates.push(facts);
240
+ }
196
241
  policies.push(
197
242
  publishingPolicy(
198
243
  [[...workflow.header, ...job.lines].join("\n")],
@@ -209,11 +254,13 @@ async function publishingPolicies(root, workflows, registry) {
209
254
  }
210
255
  }
211
256
  const unique = [...new Set(policies)];
212
- return unique.length === 1
213
- ? unique[0]
214
- : unique.length
215
- ? "mixed-authentication"
216
- : "authentication-unverified";
257
+ const policy =
258
+ unique.length === 1
259
+ ? unique[0]
260
+ : unique.length
261
+ ? "mixed-authentication"
262
+ : "authentication-unverified";
263
+ return { policy, gates };
217
264
  }
218
265
 
219
266
  async function detectPublisherDetails(root, workflows, registry) {
@@ -239,6 +286,7 @@ async function detectPublisherDetails(root, workflows, registry) {
239
286
  job.lines.find((line) => LOCAL_WORKFLOW.test(line)) ?? "",
240
287
  )?.[1];
241
288
  const callee = called ? parsedWorkflows.get(called) : null;
289
+ const chain = [];
242
290
  const environments = callee
243
291
  ? await calledEnvironments(
244
292
  root,
@@ -246,6 +294,7 @@ async function detectPublisherDetails(root, workflows, registry) {
246
294
  called,
247
295
  registry,
248
296
  new Set([workflow.name]),
297
+ chain,
249
298
  )
250
299
  : (await jobPublishes(root, parsed, job, registry))
251
300
  ? [
@@ -262,6 +311,7 @@ async function detectPublisherDetails(root, workflows, registry) {
262
311
  found.push({
263
312
  workflow: workflow.name,
264
313
  job: job.name,
314
+ callees: chain,
265
315
  idToken:
266
316
  grantsIdToken(childBlock(job.lines, indent, "permissions")) ??
267
317
  workflowGrant ??
@@ -320,8 +370,10 @@ function described(workflow, found) {
320
370
  `the publishing jobs in ${workflow} use different environments (${environments.map((item) => item ?? "none").join(", ")}); pass --environment <name> to choose one`,
321
371
  );
322
372
  }
373
+ const callees = [...new Set(jobs.flatMap((item) => item.callees ?? []))];
323
374
  return {
324
375
  workflow,
376
+ ...(callees.length ? { callees } : {}),
325
377
  jobs: [...new Set(jobs.map((item) => item.job))],
326
378
  environment: environments.length === 1 ? environments[0] : null,
327
379
  candidates: [],
@@ -369,7 +421,14 @@ export function registryTokenSecrets(registry) {
369
421
  return TOKEN_SECRETS.get(registry) ?? [];
370
422
  }
371
423
 
372
- async function calledEnvironments(root, workflows, name, registry, visited) {
424
+ async function calledEnvironments(
425
+ root,
426
+ workflows,
427
+ name,
428
+ registry,
429
+ visited,
430
+ chain = [],
431
+ ) {
373
432
  if (visited.has(name)) {
374
433
  return [];
375
434
  }
@@ -389,9 +448,12 @@ async function calledEnvironments(root, workflows, name, registry, visited) {
389
448
  LOCAL_WORKFLOW.exec(called)[1],
390
449
  registry,
391
450
  seen,
451
+ chain,
392
452
  )),
393
453
  );
394
454
  } else if (await jobPublishes(root, parsed, job, registry)) {
455
+ // Exact reusable-workflow identity: each callee job that publishes.
456
+ chain.push(`${[...seen].slice(1).join(" -> ")} -> ${job.name}`);
395
457
  environments.push(
396
458
  environmentName(
397
459
  childBlock(job.lines, childIndent(job.lines), "environment"),
@@ -406,6 +468,10 @@ async function calledEnvironments(root, workflows, name, registry, visited) {
406
468
  export async function jobPublishes(root, parsed, job, registry) {
407
469
  const pattern = JOB_PATTERNS.get(registry);
408
470
  const executable = executableLines(job.lines);
471
+ const evidence = RELEASE_EVIDENCE.get(registry);
472
+ if (evidence) {
473
+ return evidence.test(executable.join("\n"));
474
+ }
409
475
  if (publishingLine(executable, pattern)) {
410
476
  return true;
411
477
  }
@@ -20,7 +20,12 @@ export const AUTH_FAILURE_PATTERNS = Object.freeze({
20
20
  "403.*Forbidden",
21
21
  ],
22
22
  rubygems: ["API key.*(?:invalid|expired)", "invalid-publisher"],
23
- nuget: ["API key.*(?:invalid|expired)", "invalid-publisher"],
23
+ nuget: [
24
+ "API key.*(?:invalid|expired)",
25
+ "invalid-publisher",
26
+ "(?:401.*Unauthorized|403.*Forbidden)",
27
+ "NuGet/login.*(?:failed|rejected)",
28
+ ],
24
29
  jsr: ["invalid-publisher", "publishing.*(?:unauthorized|permission)"],
25
30
  "docker-hub": [
26
31
  "unauthorized: authentication required",
@@ -43,4 +48,5 @@ export const AUTH_FAILURE_PATTERNS = Object.freeze({
43
48
 
44
49
  export const RELEASE_FAILURE_PATTERNS = Object.freeze([
45
50
  ...new Set(Object.values(AUTH_FAILURE_PATTERNS).flat()),
51
+ "npm owner setup required for",
46
52
  ]);
@@ -1,6 +1,20 @@
1
1
  /** Describe release authentication, independently from the last registry publication. */
2
2
  export function publishingPolicy(contents, registry, grantOverride) {
3
3
  const text = contents.join("\n");
4
+ if (registry === "nuget") {
5
+ const oidc =
6
+ (grantOverride ??
7
+ /id-token:\s*write|permissions:\s*write-all/.test(text)) &&
8
+ /NuGet\/login@/.test(text);
9
+ const fallback = /PRM_NUGET_FALLBACK:\s*\$\{\{\s*secrets\.[\w]+/.test(text);
10
+ return oidc && fallback && /continue-on-error:\s*true/.test(text)
11
+ ? "oidc-with-token-fallback"
12
+ : oidc
13
+ ? "oidc-only"
14
+ : /secrets\.[\w]+/.test(text)
15
+ ? "token-only"
16
+ : "authentication-unverified";
17
+ }
4
18
  const token =
5
19
  /secrets\.(?:CARGO_(?:REGISTRY_)?TOKEN|NPM_(?:AUTH_)?TOKEN|NODE_AUTH_TOKEN|PYPI_(?:API_)?TOKEN)/.test(
6
20
  text,
@@ -26,7 +40,16 @@ export function publishingPolicy(contents, registry, grantOverride) {
26
40
  /continue-on-error:\s*true/.test(text)
27
41
  : /outcome == 'failure'/.test(text) &&
28
42
  /continue-on-error:\s*true/.test(text);
29
- if (oidc && token && fallback) {
43
+ const facts = authenticationFacts(text, registry);
44
+ if (facts.passwordAlwaysToken) {
45
+ // `vars.FLAG == 'true' && '' || secrets.TOKEN` always yields the token:
46
+ // '' is falsy in GitHub expressions, so the flag never selects OIDC.
47
+ return token ? "token-only" : "authentication-unverified";
48
+ }
49
+ if (grant && token && facts.gate && facts.shellFallback) {
50
+ return "variable-gated-oidc-with-token-fallback";
51
+ }
52
+ if ((oidc && token && fallback) || (oidc && token && facts.npmNative)) {
30
53
  return "oidc-with-token-fallback";
31
54
  }
32
55
  return oidc
@@ -35,3 +58,53 @@ export function publishingPolicy(contents, registry, grantOverride) {
35
58
  ? "token-only"
36
59
  : "authentication-unverified";
37
60
  }
61
+
62
+ /**
63
+ * Actual credential-selection semantics of a publishing job, kept apart from
64
+ * publisher registration and historical trusted uploads.
65
+ */
66
+ export function authenticationFacts(contents, registry) {
67
+ const text = Array.isArray(contents) ? contents.join("\n") : contents;
68
+ const facts = {
69
+ gate: null,
70
+ shellFallback: false,
71
+ passwordAlwaysToken: false,
72
+ npmNative: false,
73
+ };
74
+ const steps = text.split(/(?=^[ \t]*- )/m);
75
+ const auth = steps.find((step) =>
76
+ registry === "crates-io"
77
+ ? /crates-io-auth-action@/.test(step)
78
+ : registry === "nuget"
79
+ ? /NuGet\/login@/.test(step)
80
+ : false,
81
+ );
82
+ const gate = auth
83
+ ? /\bif:.*\bvars\.(\w+)\s*==\s*['"]true['"]/.exec(auth)?.[1]
84
+ : null;
85
+ if (gate) {
86
+ facts.gate = { variable: gate, value: "true" };
87
+ }
88
+ facts.shellFallback = /\$\{\w*OIDC\w*:-\$\w+\}/.test(text);
89
+ if (registry === "pypi") {
90
+ const password = /^\s*password\s*:\s*(.+)$/m.exec(text)?.[1] ?? "";
91
+ const flag =
92
+ /vars\.(\w+)\s*==\s*['"]true['"]\s*&&\s*''\s*\|\|\s*secrets\.\w+/.exec(
93
+ password,
94
+ );
95
+ if (flag) {
96
+ facts.passwordAlwaysToken = true;
97
+ facts.gate = { variable: flag[1], value: "true", ineffective: true };
98
+ }
99
+ }
100
+ if (registry === "npm") {
101
+ // npm 11.5.1+ tries the OIDC exchange itself and falls back to the
102
+ // configured token, so a job with both needs no separate fallback step.
103
+ facts.npmNative = steps.some(
104
+ (step) =>
105
+ /\bnpm\s+publish\b/.test(step) &&
106
+ /NODE_AUTH_TOKEN\s*:\s*\$\{\{\s*secrets\./.test(step),
107
+ );
108
+ }
109
+ return facts;
110
+ }
package/src/python.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { readdir, mkdtemp, rm } from "node:fs/promises";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
- import { exec } from "command-stream";
4
+ import { exec } from "./exec.mjs";
5
5
 
6
6
  // requires-python describes interpreter releases. Reject unsupported or
7
7
  // prerelease syntax rather than silently choosing an incompatible executable.
@@ -1,3 +1,8 @@
1
+ import {
2
+ distributionState,
3
+ normalizedNugetVersion,
4
+ versionEvidence,
5
+ } from "./publication-state.mjs";
1
6
  import { cratesPermit, delay, retryDelay } from "./request-policy.mjs";
2
7
  import {
3
8
  compareRepositories,
@@ -14,6 +19,18 @@ export const USER_AGENT =
14
19
  "package-registry-manager (+https://github.com/link-foundation/package-registry-manager)";
15
20
 
16
21
  const ENDPOINTS = {
22
+ "maven-central": [
23
+ "PACKAGE_REGISTRY_MANAGER_MAVEN_API",
24
+ "https://repo.maven.apache.org/maven2",
25
+ ],
26
+ "go-modules": [
27
+ "PACKAGE_REGISTRY_MANAGER_GO_PROXY",
28
+ "https://proxy.golang.org",
29
+ ],
30
+ packagist: [
31
+ "PACKAGE_REGISTRY_MANAGER_PACKAGIST_API",
32
+ "https://repo.packagist.org",
33
+ ],
17
34
  npm: ["PACKAGE_REGISTRY_MANAGER_NPM_REGISTRY", "https://registry.npmjs.org"],
18
35
  "crates-io": [
19
36
  "PACKAGE_REGISTRY_MANAGER_CRATES_IO_API",
@@ -58,6 +75,12 @@ export function registryStateUrl(packageInfo, env = process.env) {
58
75
  }
59
76
  const base = registryEndpoint(registry, env);
60
77
  switch (registry) {
78
+ case "maven-central":
79
+ return `${base}/${name.replaceAll(".", "/").replace(":", "/")}/maven-metadata.xml`;
80
+ case "go-modules":
81
+ return `${base}/${name.replace(/[A-Z]/g, (c) => `!${c.toLowerCase()}`)}/@v/list`;
82
+ case "packagist":
83
+ return `${base}/p2/${name.split("/").map(encodeURIComponent).join("/")}.json`;
61
84
  case "npm":
62
85
  return `${base}/${npmName(name)}/latest`;
63
86
  case "crates-io":
@@ -121,6 +144,15 @@ export async function probeRegistryState(inspection, options = {}) {
121
144
  }
122
145
  for (const key of [
123
146
  "registry_http_status",
147
+ "latest_version",
148
+ "manifest_version_exists",
149
+ "version_evidence_url",
150
+ "registry_evidence_url",
151
+ "version_state",
152
+ "registry_state_reason",
153
+ "tagged_release_exists",
154
+ "registry_owners",
155
+ "registry_repository",
124
156
  "publisher_settings_reason",
125
157
  ]) {
126
158
  if (state[key] !== undefined) {
@@ -191,10 +223,20 @@ export async function probePackage(packageInfo, options = {}) {
191
223
  const env = options.env ?? process.env;
192
224
  const url = registryStateUrl(packageInfo, env);
193
225
  if (!url) {
194
- return {};
226
+ return {
227
+ registry_state_reason:
228
+ "public registry lookup is unsupported; publication is unverified",
229
+ };
230
+ }
231
+ if (["maven-central", "go-modules"].includes(packageInfo.registry)) {
232
+ return distributionState(
233
+ packageInfo,
234
+ options,
235
+ registryEndpoint(packageInfo.registry, env),
236
+ );
195
237
  }
196
238
  let httpStatus;
197
- const document = await getJson(url, {
239
+ let document = await getJson(url, {
198
240
  ...options,
199
241
  onError: (error) => {
200
242
  httpStatus = error.http_status;
@@ -204,11 +246,69 @@ export async function probePackage(packageInfo, options = {}) {
204
246
  if (document === undefined) {
205
247
  return httpStatus ? { registry_http_status: httpStatus } : {};
206
248
  }
249
+ let latestMissing = false;
250
+ if (
251
+ document === null &&
252
+ packageInfo.registry === "npm" &&
253
+ packageInfo.version
254
+ ) {
255
+ const exactUrl = `${url.slice(0, -"latest".length)}${encodeURIComponent(packageInfo.version)}`;
256
+ document = await getJson(exactUrl, options);
257
+ latestMissing = true;
258
+ if (document && document.version !== packageInfo.version) {
259
+ return {
260
+ registry_state_reason: "invalid exact npm metadata",
261
+ registry_evidence_url: exactUrl,
262
+ };
263
+ }
264
+ }
265
+ if (document === undefined) {
266
+ return {
267
+ registry_state_reason:
268
+ "exact-version lookup failed; name presence is unknown",
269
+ };
270
+ }
207
271
  if (document === null) {
208
272
  return packageInfo.registry === "docker-hub"
209
273
  ? { exists: false }
210
274
  : { exists: false, trusted: false };
211
275
  }
276
+ if (
277
+ packageInfo.registry === "packagist" &&
278
+ (!Array.isArray(document.packages?.[packageInfo.name]) ||
279
+ document.packages[packageInfo.name].some(
280
+ (v) => typeof v.version !== "string",
281
+ ))
282
+ ) {
283
+ return {
284
+ registry_state_reason: "invalid Packagist metadata",
285
+ registry_evidence_url: url,
286
+ };
287
+ }
288
+ if (
289
+ packageInfo.registry === "nuget" &&
290
+ (!Array.isArray(document.versions) ||
291
+ document.versions.some(
292
+ (version) =>
293
+ typeof version !== "string" ||
294
+ normalizedNugetVersion(version) === undefined,
295
+ ))
296
+ ) {
297
+ return {
298
+ registry_state_reason: "invalid NuGet metadata",
299
+ registry_evidence_url: url,
300
+ };
301
+ }
302
+ const audit = await versionEvidence(
303
+ packageInfo,
304
+ document,
305
+ url,
306
+ options,
307
+ getJson,
308
+ );
309
+ if (latestMissing) {
310
+ delete audit.latest_version;
311
+ }
212
312
  switch (packageInfo.registry) {
213
313
  case "npm": {
214
314
  const attestations = document.dist?.attestations?.url;
@@ -217,6 +317,7 @@ export async function probePackage(packageInfo, options = {}) {
217
317
  : undefined;
218
318
  const sources = provenanceRepositories(provenance);
219
319
  return {
320
+ ...audit,
220
321
  exists: true,
221
322
  trusted: Boolean(document._npmUser?.trustedPublisher),
222
323
  version: document.version,
@@ -237,6 +338,7 @@ export async function probePackage(packageInfo, options = {}) {
237
338
  return {
238
339
  publisher_settings_reason:
239
340
  "publisher settings require an authenticated crates.io session; public provenance is independent",
341
+ ...audit,
240
342
  exists: true,
241
343
  trusted: Boolean(latest?.trustpub_data),
242
344
  provenance_repositories: publisherIdentities(latest?.trustpub_data).map(
@@ -250,13 +352,26 @@ export async function probePackage(packageInfo, options = {}) {
250
352
  case "pypi": {
251
353
  const provenance = await pypiProvenance(document, options);
252
354
  return {
355
+ ...audit,
253
356
  exists: true,
254
357
  trusted: Boolean(provenance),
255
358
  provenance_repositories: provenanceRepositories(provenance),
256
359
  };
257
360
  }
361
+ case "nuget":
362
+ return { ...audit, exists: document.versions.length > 0 };
363
+ case "packagist": {
364
+ const versions = document.packages?.[packageInfo.name];
365
+ if (!Array.isArray(versions)) {
366
+ return {
367
+ registry_state_reason: "invalid Packagist metadata",
368
+ registry_evidence_url: url,
369
+ };
370
+ }
371
+ return { ...audit, exists: versions.length > 0 };
372
+ }
258
373
  default:
259
- return { exists: true };
374
+ return { ...audit, exists: true };
260
375
  }
261
376
  }
262
377
 
@@ -101,10 +101,9 @@ export async function selectReleaseRun(session) {
101
101
  if (details.code !== 0) {
102
102
  throw new Error("could not read the failed release jobs");
103
103
  }
104
- if (
105
- failedPublishingJob(JSON.parse(String(details.stdout || "{}")).jobs ?? [])
106
- ) {
107
- session.releaseSelection = { run, publishFailure: true, branch };
104
+ const jobs = JSON.parse(String(details.stdout || "{}")).jobs ?? [];
105
+ if (failedPublishingJob(jobs)) {
106
+ session.releaseSelection = { run, publishFailure: true, branch, jobs };
108
107
  return session.releaseSelection;
109
108
  }
110
109
  }
@@ -1,3 +1,4 @@
1
+ import { validateIdentities } from "./identity-conflicts.mjs";
1
2
  import { rm } from "node:fs/promises";
2
3
  import { protectLegacyProfile } from "./profile.mjs";
3
4
  import { SetupSession, prompt } from "./setup.mjs";
@@ -34,7 +35,14 @@ export async function executePlan(plan, options) {
34
35
 
35
36
  /** Runs all plans with one browser session and defers sign-out until the end. */
36
37
  export async function executePlans(plans, options, summary = true) {
37
- options = { ...options, rotatedSecrets: options.rotatedSecrets ?? new Map() };
38
+ validateIdentities(plans);
39
+ options = {
40
+ ...options,
41
+ rotatedSecrets: options.rotatedSecrets ?? new Map(),
42
+ recoveryChanges: new Map(),
43
+ recoveryQueue: [],
44
+ nugetQueue: [],
45
+ };
38
46
  if (plans.length === 0) {
39
47
  throw new Error("no publishable package manifests were found");
40
48
  }
@@ -139,7 +147,9 @@ export async function executePlans(plans, options, summary = true) {
139
147
  ];
140
148
  let automation = options.automation ?? null;
141
149
  const deferred = new Map();
150
+ const importedProfiles = new Set();
142
151
  const outcomes = [];
152
+ const sessions = [];
143
153
  let failure;
144
154
  let preserveNpmSession = false;
145
155
  try {
@@ -152,6 +162,7 @@ export async function executePlans(plans, options, summary = true) {
152
162
  automation,
153
163
  domains,
154
164
  });
165
+ sessions.push(session);
155
166
  try {
156
167
  await session.run();
157
168
  outcomes.push({
@@ -174,9 +185,15 @@ export async function executePlans(plans, options, summary = true) {
174
185
  } finally {
175
186
  preserveNpmSession ||= session.conditions.has("npm-name-refused");
176
187
  const steps = await session.cleanup({
177
- deferAuth: plans.length > 1,
188
+ deferAuth:
189
+ plans.length > 1 ||
190
+ session.recoveryQueued ||
191
+ options.nugetQueue.includes(session),
178
192
  closeBrowser: false,
179
193
  });
194
+ for (const profile of session.importProfiles ?? []) {
195
+ importedProfiles.add(profile);
196
+ }
180
197
  automation = session.automation;
181
198
  for (const step of steps) {
182
199
  deferred.set(`${plan.registry}:${step.id}`, { session, step });
@@ -186,6 +203,32 @@ export async function executePlans(plans, options, summary = true) {
186
203
  break;
187
204
  }
188
205
  }
206
+ if (!failure) {
207
+ for (const session of options.nugetQueue) {
208
+ session.options = { ...session.options, nugetQueue: undefined };
209
+ await session.runStep({ id: "verify-nuget-release" });
210
+ }
211
+ const recovered = new Set();
212
+ for (const { session, step } of options.recoveryQueue) {
213
+ const key = `${session.plan.repository.root}:${session.releaseSelection.run.databaseId}`;
214
+ session.options = { ...session.options, recoveryQueue: undefined };
215
+ session.automation = automation;
216
+ if (!recovered.has(key)) {
217
+ await session.runStep(step);
218
+ recovered.add(key);
219
+ }
220
+ for (const pending of session.pendingReleaseSteps ?? []) {
221
+ if (!pending.when || session.conditions.has(pending.when)) {
222
+ await session.runStep(pending);
223
+ }
224
+ }
225
+ }
226
+ for (const [index, session] of sessions.entries()) {
227
+ if (session.outcome) {
228
+ Object.assign(outcomes[index], session.outcome);
229
+ }
230
+ }
231
+ }
189
232
  } finally {
190
233
  for (const { session, step } of deferred.values()) {
191
234
  if (preserveNpmSession && step.id === "sign-out") {
@@ -206,6 +249,9 @@ export async function executePlans(plans, options, summary = true) {
206
249
  }
207
250
  }
208
251
  await automation?.close();
252
+ for (const profile of importedProfiles) {
253
+ await rm(profile, { recursive: true, force: true });
254
+ }
209
255
  for (const plan of plans.slice(outcomes.length)) {
210
256
  outcomes.push({
211
257
  registry: plan.registry,