@git.zone/cli 7.2.3 → 7.2.5

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.
@@ -19,6 +19,7 @@ import {
19
19
  hashReleaseDestination,
20
20
  } from "./helpers.npmartifact.js";
21
21
  import { getReleaseNpmPublicationOrder } from "./helpers.npmpackages.js";
22
+ import { formatCommandFailure } from "./helpers.commandfailure.js";
22
23
  import {
23
24
  canonicalReleaseJson,
24
25
  type IReleaseQualificationRequest,
@@ -52,7 +53,16 @@ const releaseGit = async (
52
53
  timeoutKillGraceMs: 5_000,
53
54
  });
54
55
  if (result.exitCode !== 0)
55
- throw new Error(`Release Git validation failed: ${args[0]}.`);
56
+ throw new Error(
57
+ formatCommandFailure(
58
+ `Release Git validation failed: ${args[0]}.`,
59
+ result,
60
+ {
61
+ command: `git ${args[0]}`,
62
+ timeoutMs: 60_000,
63
+ },
64
+ ),
65
+ );
56
66
  return result.stdout.trim();
57
67
  };
58
68
 
@@ -417,7 +427,17 @@ export const withIsolatedReleaseCheckout = async <T>(
417
427
  },
418
428
  );
419
429
  if (install.exitCode !== 0)
420
- throw new Error("Release checkout dependency installation failed.");
430
+ throw new Error(
431
+ formatCommandFailure(
432
+ "Release checkout dependency installation failed.",
433
+ install,
434
+ {
435
+ command: "pnpm install --frozen-lockfile",
436
+ timeoutMs: 10 * 60_000,
437
+ output: "combined",
438
+ },
439
+ ),
440
+ );
421
441
  }
422
442
  if (options.testCommand)
423
443
  await run(options.smartshell, checkout, options.testCommand, "tests");
@@ -505,5 +525,11 @@ const run = async (
505
525
  console.log(`\nRunning the release ${phase} in the release checkout`);
506
526
  const result = await smartshell.exec(command, { cwd });
507
527
  if (result.exitCode !== 0)
508
- throw new Error(`Release ${phase} failed in the release checkout.`);
528
+ throw new Error(
529
+ formatCommandFailure(
530
+ `Release ${phase} failed in the release checkout.`,
531
+ result,
532
+ { command, output: "combined" },
533
+ ),
534
+ );
509
535
  };
@@ -35,6 +35,7 @@ import {
35
35
  type INpmArtifactProbeResult,
36
36
  } from "./helpers.npmartifact.js";
37
37
  import { isAbsentGitOid, releaseGitEnv } from "./helpers.releasebranch.js";
38
+ import { describeCommandFailure } from "./helpers.commandfailure.js";
38
39
  import {
39
40
  TsdockerReleaseCommandError,
40
41
  TsdockerReleaseRequestCleanupError,
@@ -97,8 +98,17 @@ type TGitProbeStatus = "pending" | "exact" | "conflict" | "inconclusive";
97
98
 
98
99
  interface IGitProbeResult {
99
100
  status: TGitProbeStatus;
101
+ /** Why an inconclusive probe could not read the remote refs. */
102
+ failure?: string;
100
103
  }
101
104
 
105
+ /** Appends why a probe could not read the remote refs, when it knows. */
106
+ const withGitProbeFailure = (
107
+ messageArg: string,
108
+ probeArg: IGitProbeResult,
109
+ ): string =>
110
+ probeArg.failure ? `${messageArg} ${probeArg.failure}` : messageArg;
111
+
102
112
  export interface IReleasePublicationOptions {
103
113
  pnpmCapability?: IPnpmReleaseCapability;
104
114
  smartshell: plugins.smartshell.Smartshell;
@@ -319,7 +329,13 @@ const inspectRemoteRelease = async (
319
329
  },
320
330
  );
321
331
  if (result.exitCode !== 0) {
322
- return { status: "inconclusive" };
332
+ return {
333
+ status: "inconclusive",
334
+ failure: describeCommandFailure(result, {
335
+ command: "git ls-remote",
336
+ timeoutMs: gitProbeTimeoutMs,
337
+ }),
338
+ };
323
339
  }
324
340
  const refs = new Map<string, string>();
325
341
  for (const line of result.stdout.split("\n")) {
@@ -388,7 +404,10 @@ const executeGitTarget = async (
388
404
  throw new Error("Previously verified Git release refs no longer match.");
389
405
  }
390
406
  throw new Error(
391
- "Previously verified Git release refs cannot currently be verified.",
407
+ withGitProbeFailure(
408
+ "Previously verified Git release refs cannot currently be verified.",
409
+ probe,
410
+ ),
392
411
  );
393
412
  }
394
413
 
@@ -415,7 +434,12 @@ const executeGitTarget = async (
415
434
  throw new Error("Remote Git refs conflict with the release journal.");
416
435
  }
417
436
  if (probe.status === "inconclusive") {
418
- throw new Error("Remote Git publication state is inconclusive.");
437
+ throw new Error(
438
+ withGitProbeFailure(
439
+ "Remote Git publication state is inconclusive.",
440
+ probe,
441
+ ),
442
+ );
419
443
  }
420
444
  journal = await recoverPublishingTarget(
421
445
  optionsArg.store,
@@ -468,7 +492,12 @@ const executeGitTarget = async (
468
492
  "failed",
469
493
  "verification-inconclusive",
470
494
  );
471
- throw new Error("Remote Git publication state is inconclusive.");
495
+ throw new Error(
496
+ withGitProbeFailure(
497
+ "Remote Git publication state is inconclusive.",
498
+ probe,
499
+ ),
500
+ );
472
501
  }
473
502
 
474
503
  await optionsArg.ensurePublicationState(expectedRemoteMainOid);
@@ -525,7 +554,19 @@ const executeGitTarget = async (
525
554
  "failed",
526
555
  pushResult.exitCode === 0 ? "verification-inconclusive" : "command-failed",
527
556
  );
528
- throw new Error("Git publication did not produce verifiable remote refs.");
557
+ const pushFailure =
558
+ pushResult.exitCode === 0
559
+ ? ""
560
+ : ` ${describeCommandFailure(pushResult, {
561
+ command: "git push",
562
+ timeoutMs: gitPushTimeoutMs,
563
+ })}`;
564
+ throw new Error(
565
+ withGitProbeFailure(
566
+ `Git publication did not produce verifiable remote refs.${pushFailure}`,
567
+ probe,
568
+ ),
569
+ );
529
570
  };
530
571
 
531
572
  const probeNpm = async (
@@ -842,7 +883,11 @@ const executeNpmRegistry = async (
842
883
  "failed",
843
884
  "command-failed",
844
885
  );
845
- throw new Error(`npm publication was rejected: ${registryArg}`);
886
+ throw new Error(
887
+ publishResult.failure
888
+ ? `npm publication was rejected: ${registryArg} ${publishResult.failure}`
889
+ : `npm publication was rejected: ${registryArg}`,
890
+ );
846
891
  };
847
892
 
848
893
  const requireTsdocker = (
@@ -1,5 +1,6 @@
1
1
  import * as plugins from "./mod.plugins.js";
2
2
  import { getProjectTsdockerBinPath } from "../helpers.tsdocker.js";
3
+ import { formatCommandFailure } from "./helpers.commandfailure.js";
3
4
  import { supportsTsdockerMinimumVersion } from "../helpers.workflow.js";
4
5
  import type {
5
6
  IReleaseCapabilitiesResult,
@@ -143,27 +144,40 @@ const parseProtocolOutput = (
143
144
  resultArg: plugins.smartshell.IExecResult,
144
145
  commandArg: TReleaseProtocolCommand,
145
146
  ): unknown => {
147
+ const withFailure = (messageArg: string): string =>
148
+ formatCommandFailure(messageArg, resultArg, {
149
+ command: `tsdocker ${commandArg}`,
150
+ timeoutMs: commandTimeouts[commandArg],
151
+ });
146
152
  if (resultArg.timedOut) {
147
153
  throw new TsdockerReleaseCommandError(
148
154
  commandArg,
149
155
  "COMMAND_TIMEOUT",
150
- `tSDocker ${commandArg} timed out with an unresolved outcome.`,
156
+ withFailure(
157
+ `tSDocker ${commandArg} timed out with an unresolved outcome.`,
158
+ ),
151
159
  );
152
160
  }
153
161
  if (resultArg.signal) {
154
162
  throw new TsdockerReleaseCommandError(
155
163
  commandArg,
156
164
  "COMMAND_SIGNALLED",
157
- `tSDocker ${commandArg} was terminated with an unresolved outcome.`,
165
+ withFailure(
166
+ `tSDocker ${commandArg} was terminated with an unresolved outcome.`,
167
+ ),
158
168
  );
159
169
  }
160
170
  if (resultArg.stderr !== "") {
161
171
  throw new TsdockerReleaseCommandError(
162
172
  commandArg,
163
173
  "INVALID_PROTOCOL_OUTPUT",
164
- `tSDocker ${commandArg} wrote non-protocol stderr output.`,
174
+ withFailure(`tSDocker ${commandArg} wrote non-protocol stderr output.`),
165
175
  );
166
176
  }
177
+ // Past this point stderr is empty, so a failure detail names only the exit
178
+ // code, which is worth naming whenever the protocol output is unusable.
179
+ const withExitCode = (messageArg: string): string =>
180
+ resultArg.exitCode === 0 ? messageArg : withFailure(messageArg);
167
181
  if (
168
182
  Buffer.byteLength(resultArg.stdout) > responseByteLimit ||
169
183
  !resultArg.stdout.endsWith("\n")
@@ -171,7 +185,9 @@ const parseProtocolOutput = (
171
185
  throw new TsdockerReleaseCommandError(
172
186
  commandArg,
173
187
  "INVALID_PROTOCOL_OUTPUT",
174
- `tSDocker ${commandArg} returned an invalid response envelope.`,
188
+ withExitCode(
189
+ `tSDocker ${commandArg} returned an invalid response envelope.`,
190
+ ),
175
191
  );
176
192
  }
177
193
 
@@ -182,14 +198,14 @@ const parseProtocolOutput = (
182
198
  throw new TsdockerReleaseCommandError(
183
199
  commandArg,
184
200
  "INVALID_PROTOCOL_OUTPUT",
185
- `tSDocker ${commandArg} returned invalid JSON.`,
201
+ withExitCode(`tSDocker ${commandArg} returned invalid JSON.`),
186
202
  );
187
203
  }
188
204
  if (canonicalReleaseJsonDocument(parsed) !== resultArg.stdout) {
189
205
  throw new TsdockerReleaseCommandError(
190
206
  commandArg,
191
207
  "INVALID_PROTOCOL_OUTPUT",
192
- `tSDocker ${commandArg} returned noncanonical JSON.`,
208
+ withExitCode(`tSDocker ${commandArg} returned noncanonical JSON.`),
193
209
  );
194
210
  }
195
211
  if (resultArg.exitCode !== 0) {
@@ -209,7 +225,9 @@ const parseProtocolOutput = (
209
225
  throw new TsdockerReleaseCommandError(
210
226
  commandArg,
211
227
  "INVALID_PROTOCOL_OUTPUT",
212
- `tSDocker ${commandArg} failed without a valid protocol error.`,
228
+ withFailure(
229
+ `tSDocker ${commandArg} failed without a valid protocol error.`,
230
+ ),
213
231
  );
214
232
  }
215
233
  }
@@ -260,17 +278,24 @@ export class TsdockerReleaseClient implements ITsdockerReleaseClient {
260
278
  timeoutKillGraceMs: 5_000,
261
279
  },
262
280
  );
281
+ const versionMessage =
282
+ "Docker release journal schema 2 requires one matching project-local @git.zone/tsdocker package and binary.";
263
283
  if (
264
284
  versionResult.exitCode !== 0 ||
265
285
  versionResult.timedOut ||
266
286
  versionResult.signal ||
267
- versionResult.stderr !== "" ||
268
- versionResult.stdout.trim() !== installedVersion
287
+ versionResult.stderr !== ""
269
288
  ) {
270
289
  throw new Error(
271
- "Docker release journal schema 2 requires one matching project-local @git.zone/tsdocker package and binary.",
290
+ formatCommandFailure(versionMessage, versionResult, {
291
+ command: "tsdocker --version",
292
+ timeoutMs: 30_000,
293
+ }),
272
294
  );
273
295
  }
296
+ if (versionResult.stdout.trim() !== installedVersion) {
297
+ throw new Error(versionMessage);
298
+ }
274
299
 
275
300
  const parsed = await this.run("release-capabilities");
276
301
  return plugins.tsdockerReleaseProtocol.assertReleaseCapabilitiesResult(
@@ -65,6 +65,7 @@ import {
65
65
  planReleaseNpmPackages,
66
66
  } from "./helpers.npmpackages.js";
67
67
  import { executeReleasePublication } from "./helpers.releasepublication.js";
68
+ import { formatCommandFailure } from "./helpers.commandfailure.js";
68
69
  import { runTstestCleanup } from "../helpers.tstest.js";
69
70
  import {
70
71
  assertPackageReleaseRecovery,
@@ -1356,7 +1357,12 @@ async function runCommandStep(
1356
1357
  console.log(`\n${label}`);
1357
1358
  const result = await smartshellInstance.exec(command, { cwd: cwdArg });
1358
1359
  if (result.exitCode !== 0) {
1359
- throw new Error(`${label} failed. Aborting release.`);
1360
+ throw new Error(
1361
+ formatCommandFailure(`${label} failed. Aborting release.`, result, {
1362
+ command,
1363
+ output: "combined",
1364
+ }),
1365
+ );
1360
1366
  }
1361
1367
  logger.log("success", `${label} passed.`);
1362
1368
  }
@@ -1376,6 +1382,15 @@ async function verifyCleanTree(
1376
1382
  timeoutKillGraceMs: 5_000,
1377
1383
  },
1378
1384
  );
1385
+ if (statusResult.exitCode !== 0) {
1386
+ throw new Error(
1387
+ formatCommandFailure(
1388
+ "Unable to inspect the release worktree.",
1389
+ statusResult,
1390
+ { command: "git status", timeoutMs: 60_000 },
1391
+ ),
1392
+ );
1393
+ }
1379
1394
  if (statusResult.stdout.trim() !== "") {
1380
1395
  throw new Error(errorMessage);
1381
1396
  }
@@ -1434,7 +1449,12 @@ async function runReleaseCommitStep(
1434
1449
  timeoutKillGraceMs: 5_000,
1435
1450
  });
1436
1451
  if (addResult.exitCode !== 0) {
1437
- throw new Error("Staging release metadata failed.");
1452
+ throw new Error(
1453
+ formatCommandFailure("Staging release metadata failed.", addResult, {
1454
+ command: "git add",
1455
+ timeoutMs: 60_000,
1456
+ }),
1457
+ );
1438
1458
  }
1439
1459
  const result = await smartshellInstance.execSpawn(
1440
1460
  "git",
@@ -1447,7 +1467,13 @@ async function runReleaseCommitStep(
1447
1467
  },
1448
1468
  );
1449
1469
  if (result.exitCode !== 0) {
1450
- throw new Error("Release commit failed.");
1470
+ throw new Error(
1471
+ formatCommandFailure("Release commit failed.", result, {
1472
+ command: "git commit",
1473
+ timeoutMs: 60_000,
1474
+ output: "combined",
1475
+ }),
1476
+ );
1451
1477
  }
1452
1478
  const branchResult = await smartshellInstance.execSpawn(
1453
1479
  "git",
@@ -1460,10 +1486,16 @@ async function runReleaseCommitStep(
1460
1486
  timeoutKillGraceMs: 5_000,
1461
1487
  },
1462
1488
  );
1463
- if (
1464
- branchResult.exitCode !== 0 ||
1465
- branchResult.stdout.trim() !== "refs/heads/main"
1466
- ) {
1489
+ if (branchResult.exitCode !== 0) {
1490
+ throw new Error(
1491
+ formatCommandFailure(
1492
+ "The release commit was not created on main.",
1493
+ branchResult,
1494
+ { command: "git symbolic-ref", timeoutMs: 60_000 },
1495
+ ),
1496
+ );
1497
+ }
1498
+ if (branchResult.stdout.trim() !== "refs/heads/main") {
1467
1499
  throw new Error("The release commit was not created on main.");
1468
1500
  }
1469
1501
  const headOid = await resolveGitObjectOid(
@@ -1508,7 +1540,12 @@ async function runTagStep(
1508
1540
  },
1509
1541
  );
1510
1542
  if (result.exitCode !== 0) {
1511
- throw new Error("Release tag failed.");
1543
+ throw new Error(
1544
+ formatCommandFailure("Release tag failed.", result, {
1545
+ command: "git tag",
1546
+ timeoutMs: 60_000,
1547
+ }),
1548
+ );
1512
1549
  }
1513
1550
  }
1514
1551
 
@@ -1534,7 +1571,16 @@ const resolveGitObjectOid = async (
1534
1571
  },
1535
1572
  );
1536
1573
  const oid = result.stdout.trim();
1537
- if (result.exitCode !== 0 || !/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i.test(oid)) {
1574
+ if (result.exitCode !== 0) {
1575
+ throw new Error(
1576
+ formatCommandFailure(
1577
+ `Unable to resolve release Git object ${revisionArg}.`,
1578
+ result,
1579
+ { command: "git rev-parse", timeoutMs: 60_000 },
1580
+ ),
1581
+ );
1582
+ }
1583
+ if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i.test(oid)) {
1538
1584
  throw new Error(`Unable to resolve release Git object ${revisionArg}.`);
1539
1585
  }
1540
1586
  return oid;