package-registry-manager 0.22.7 → 0.22.9

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.
@@ -1,3 +1,4 @@
1
+ import { selectReleaseRun } from "./release-runs.mjs";
1
2
  import { pageFetchScript } from "./crates-api.mjs";
2
3
  import {
3
4
  publisherIdentities,
@@ -306,31 +307,11 @@ export async function runRepositoryRepair(session, step) {
306
307
  throw new Error("verify repository repairs before retrying release jobs");
307
308
  }
308
309
  const expected = repositorySlug(session.plan.repository);
309
- const result = await session.capture({
310
- command: {
311
- program: "gh",
312
- args: [
313
- "run",
314
- "list",
315
- "--repo",
316
- expected,
317
- "--workflow",
318
- session.plan.trusted_publisher.workflow,
319
- "--limit",
320
- "1",
321
- "--json",
322
- "databaseId,conclusion,headSha",
323
- ],
324
- },
325
- cwd: ".",
326
- });
327
- if (result.code !== 0) {
328
- throw new Error("could not inspect release jobs after repository repair");
329
- }
330
- const [run] = JSON.parse(result.stdout || "[]");
331
- if (run?.conclusion !== "failure") {
310
+ const { run, publishFailure, branch } = await selectReleaseRun(session);
311
+ if (!publishFailure) {
332
312
  return;
333
313
  }
314
+ console.log(` Selected failed release run: ${run.url}`);
334
315
  const { verifyRemoteManifest } = await import("./manifest-proposal.mjs");
335
316
  const corrected =
336
317
  Boolean(run.headSha) &&
@@ -363,10 +344,17 @@ export async function runRepositoryRepair(session, step) {
363
344
  session.plan.trusted_publisher.workflow,
364
345
  "--repo",
365
346
  expected,
347
+ "--ref",
348
+ branch,
366
349
  ],
367
350
  };
351
+ if (corrected) {
352
+ session.values ??= {};
353
+ session.values.failed_run_id = String(run.databaseId);
354
+ }
368
355
  await session.command({
369
356
  ...step,
357
+ id: corrected ? "rerun-release" : "retry-repaired-release",
370
358
  kind: "command",
371
359
  command,
372
360
  cwd: ".",
@@ -37,8 +37,27 @@ export async function executePlans(plans, options, summary = true) {
37
37
  if (plans.length === 0) {
38
38
  throw new Error("no publishable package manifests were found");
39
39
  }
40
+ const ready = [];
41
+ let blocked;
40
42
  for (const plan of plans) {
41
- validatePlan(plan, options.execute);
43
+ try {
44
+ validatePlan(plan, options.execute);
45
+ ready.push(plan);
46
+ } catch (error) {
47
+ if (!options.accountScan) {
48
+ throw error;
49
+ }
50
+ blocked ??= error;
51
+ console.error(
52
+ `${plan.repository.github_owner}/${plan.repository.github_repository}: ${plan.registry}: ${plan.package.name}: blocked: ${error.message}`,
53
+ );
54
+ }
55
+ }
56
+ if (blocked) {
57
+ if (ready.length) {
58
+ await executePlans(ready, options, summary);
59
+ }
60
+ throw blocked;
42
61
  }
43
62
  for (const plan of plans) {
44
63
  if (plan.mode === "complete") {
@@ -68,6 +87,32 @@ export async function executePlans(plans, options, summary = true) {
68
87
  plan.steps.some((step) => step.id === "add-publishing-workflow"),
69
88
  );
70
89
  if (missing.length) {
90
+ if (options.accountScan) {
91
+ const outcomes = [];
92
+ for (const root of new Set(missing.map((plan) => plan.repository.root))) {
93
+ const group = missing.filter((plan) => plan.repository.root === root);
94
+ const result = await (options.offerWorkflow ?? offerWorkflow)(group, {
95
+ ...options,
96
+ repository: root,
97
+ inspection: undefined,
98
+ prompt: options.prompt ?? prompt,
99
+ });
100
+ outcomes.push(
101
+ ...group.map((plan) => ({
102
+ registry: plan.registry,
103
+ package: plan.package.name,
104
+ repository: `${plan.repository.github_owner}/${plan.repository.github_repository}`,
105
+ ...result,
106
+ })),
107
+ );
108
+ }
109
+ const ready = plans.filter((plan) => !missing.includes(plan));
110
+ if (ready.length) {
111
+ outcomes.push(...(await executePlans(ready, options, false)));
112
+ }
113
+ printSummary(outcomes, summary);
114
+ return outcomes;
115
+ }
71
116
  const result = await offerWorkflow(missing, {
72
117
  ...options,
73
118
  prompt: options.prompt ?? prompt,
@@ -99,6 +144,9 @@ export async function executePlans(plans, options, summary = true) {
99
144
  for (const plan of plans) {
100
145
  const session = new SetupSession(plan, {
101
146
  ...options,
147
+ repository: options.accountScan
148
+ ? plan.repository.root
149
+ : options.repository,
102
150
  automation,
103
151
  domains,
104
152
  });
@@ -107,6 +155,7 @@ export async function executePlans(plans, options, summary = true) {
107
155
  outcomes.push({
108
156
  registry: plan.registry,
109
157
  package: plan.package.name,
158
+ repository: `${plan.repository.github_owner}/${plan.repository.github_repository}`,
110
159
  status: plan.steps.length === 0 ? "complete" : "configured",
111
160
  ...session.outcome,
112
161
  });
@@ -119,7 +168,7 @@ export async function executePlans(plans, options, summary = true) {
119
168
  package: plan.package.name,
120
169
  status: "failed",
121
170
  });
122
- failure = error;
171
+ failure ??= error;
123
172
  } finally {
124
173
  const steps = await session.cleanup({
125
174
  deferAuth: plans.length > 1,
@@ -130,7 +179,7 @@ export async function executePlans(plans, options, summary = true) {
130
179
  deferred.set(`${plan.registry}:${step.id}`, { session, step });
131
180
  }
132
181
  }
133
- if (failure) {
182
+ if (failure && !options.accountScan) {
134
183
  break;
135
184
  }
136
185
  }
@@ -168,7 +217,7 @@ function printSummary(outcomes, enabled) {
168
217
  console.log("\nSetup summary:");
169
218
  for (const item of outcomes) {
170
219
  console.log(
171
- `- ${item.registry}: ${item.package}: ${item.status}${item.url ? ` (${item.url})` : ""}`,
220
+ `- ${item.repository ? `${item.repository}: ` : ""}${item.registry}: ${item.package}: ${item.status}${item.secret_scope ? `; ${item.secret_scope} secret` : ""}${item.fallback_reason ? `; ${item.fallback_reason}` : ""}${item.url ? ` (${item.url})` : ""}`,
172
221
  );
173
222
  }
174
223
  }
package/src/setup.mjs CHANGED
@@ -33,6 +33,7 @@ import { packageDirectory } from "./plan.mjs";
33
33
  import { twoFactorMode } from "./prerequisites.mjs";
34
34
  import { getJson, probePackage } from "./registry-state.mjs";
35
35
  import { launchBrowser, signInDomains } from "./sign-in-import.mjs";
36
+ import { PUBLISH_REJECTED, selectReleaseRun } from "./release-runs.mjs";
36
37
  import { runRepositoryRepair } from "./repository-repair.mjs";
37
38
  import {
38
39
  publisherIdentities,
@@ -54,8 +55,6 @@ const QUIET_CHECKS = new Set(["check-sign-in", "check-pages"]);
54
55
  const LISTED_PUBLISHER = /^\s*(?:id|type|file):\s*\S|"(?:id|type|file)"\s*:/m;
55
56
  /** What `npm trust github` prints once the registry stored the publisher. */
56
57
  const TRUST_CREATED = /Trust configuration created successfully/i;
57
- /** npm's answer when a workflow publishes without an attached trusted publisher. */
58
- const PUBLISH_REJECTED = /\bE404\b|404 Not Found|invalid-publisher/i;
59
58
  /** Where `--browser` opens URLs that need no automation. */
60
59
  export const BROWSER_MODES = ["default", "automated"];
61
60
 
@@ -245,6 +244,9 @@ export class SetupSession {
245
244
  }
246
245
 
247
246
  async check(step) {
247
+ if (step.id === "inspect-release-run") {
248
+ return this.inspectReleaseRun();
249
+ }
248
250
  const result = INTERACTIVE_CHECKS.has(step.id)
249
251
  ? await this.runProcess(step, false)
250
252
  : await this.capture(step);
@@ -273,14 +275,12 @@ export class SetupSession {
273
275
  case "check-2fa":
274
276
  case "verify-2fa":
275
277
  return this.checkTwoFactor(step, result);
276
- case "inspect-release-run":
277
- return this.inspectReleaseRun(result);
278
278
  case "read-release-failure":
279
279
  if (result.code !== 0) {
280
280
  console.error("warning: could not read the failed release log");
281
281
  } else if (PUBLISH_REJECTED.test(output)) {
282
282
  console.log(
283
- " It failed at publish: npm rejected the workflow (E404/invalid-publisher) because no trusted publisher is attached yet. After attaching trust, its failed jobs can be re-run.",
283
+ " It failed at publish: the registry rejected the workflow's trusted publishing identity (OIDC/E404/invalid-publisher). After attaching trust, its failed jobs can be re-run.",
284
284
  );
285
285
  this.conditions.add("release-failed-publish");
286
286
  } else {
@@ -380,19 +380,24 @@ export class SetupSession {
380
380
  return pagesSettingsUrl(`${github_owner}/${github_repository}`);
381
381
  }
382
382
 
383
- inspectReleaseRun(result) {
384
- if (result.code !== 0) {
385
- console.error("warning: could not list the release workflow runs");
383
+ async inspectReleaseRun() {
384
+ let selection;
385
+ try {
386
+ selection = await selectReleaseRun(this);
387
+ } catch (error) {
388
+ console.error(`warning: ${error.message}`);
386
389
  return;
387
390
  }
388
- const [run] = JSON.parse(String(result.stdout || "[]"));
391
+ const { run, publishFailure } = selection;
389
392
  if (!run) {
390
393
  console.log(" The release workflow has not run yet.");
391
394
  return;
392
395
  }
393
396
  const outcome = run.conclusion || run.status;
394
- console.log(` The latest release run ${outcome}: ${run.url}`);
395
- if (run.conclusion === "failure") {
397
+ console.log(
398
+ ` The ${publishFailure ? "selected failed" : "latest"} release run ${outcome}: ${run.url}`,
399
+ );
400
+ if (publishFailure) {
396
401
  this.values.failed_run_id = String(run.databaseId);
397
402
  this.conditions.add("release-failed");
398
403
  }
@@ -488,6 +493,11 @@ export class SetupSession {
488
493
  this.values.worktree = path.join(this.temporary, "worktree");
489
494
  this.values.pack_destination = this.temporary;
490
495
  }
496
+ if (step.id === "rerun-release" && this.releaseSelection?.run) {
497
+ console.log(
498
+ ` Re-running failed release jobs: ${this.releaseSelection.run.url}`,
499
+ );
500
+ }
491
501
  // Pack output is captured so npm's warnings can be reviewed.
492
502
  const result =
493
503
  step.id === "pack"
@@ -681,6 +691,7 @@ export class SetupSession {
681
691
  * `--browser-import default|auto` itself, once it knows a sign-in is missing.
682
692
  */
683
693
  async automatedPage(browser = this.options.browserOptions, quiet = false) {
694
+ quiet ||= this.options.quietBrowser;
684
695
  if (!this.automation) {
685
696
  const domains = this.options.domains ?? signInDomains(this.plan.registry);
686
697
  this.automation = await connectAutomation({