@git.zone/cli 6.15.0 → 6.16.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.
@@ -22,6 +22,9 @@ import {
22
22
  } from "./helpers.giteaassets.js";
23
23
  import { assertGiteaAssetsGitDestination } from "../helpers.workflow.js";
24
24
  import {
25
+ defaultNpmVerificationWindowMinutes,
26
+ npmPublishWasAccepted,
27
+ planNpmAvailabilityProbes,
25
28
  probeAnonymousNpmArtifact,
26
29
  publishNpmArtifact,
27
30
  verifyStoredNpmArtifact,
@@ -105,6 +108,8 @@ export interface IReleasePublicationOptions {
105
108
  pushUrl?: string;
106
109
  recoveryAttemptId?: string;
107
110
  npmProbeOptions?: INpmArtifactProbeOptions;
111
+ /** Waiting budget for one accepted npm target before resume takes over. */
112
+ npmVerificationWindowMs?: number;
108
113
  tsdocker?: ITsdockerReleaseClient;
109
114
  giteaAssets?: Pick<
110
115
  GiteaAssetsClient,
@@ -231,7 +236,7 @@ const finishPublishingTarget = async (
231
236
  storeArg: ReleaseJournalStore,
232
237
  journalArg: TReleaseJournal,
233
238
  selectorArg: TReleaseTargetSelector,
234
- stateArg: "verified" | "failed" | "conflict",
239
+ stateArg: "accepted" | "verified" | "failed" | "conflict",
235
240
  errorArg: TReleaseErrorCode | null,
236
241
  ): Promise<TReleaseJournal> => {
237
242
  const attemptId = getTargetStatus(journalArg, selectorArg).attempt?.id;
@@ -324,8 +329,10 @@ const inspectRemoteRelease = async (
324
329
  const mainOid = refs.get("refs/heads/main");
325
330
  const tagOid = refs.get(tagRef);
326
331
  const tagCommitOid = refs.get(`${tagRef}^{}`);
332
+ // A published release is identified by its annotated tag. Main carrying
333
+ // later commits is normal history, so only the tag decides exactness; the
334
+ // branch itself is leased during publication.
327
335
  if (
328
- mainOid === journalArg.release.mainOid &&
329
336
  tagOid === journalArg.release.tagOid &&
330
337
  tagCommitOid === journalArg.release.mainOid
331
338
  ) {
@@ -524,7 +531,7 @@ const executeGitTarget = async (
524
531
  const probeNpm = async (
525
532
  journalArg: TReleaseJournal,
526
533
  registryArg: string,
527
- optionsArg: IReleasePublicationOptions,
534
+ probeOptionsArg: INpmArtifactProbeOptions | undefined,
528
535
  waitArg = false,
529
536
  packageNameArg?: string,
530
537
  ): Promise<INpmArtifactProbeResult> => {
@@ -534,16 +541,50 @@ const probeNpm = async (
534
541
  registryArg,
535
542
  artifact,
536
543
  journalArg.npm.tag,
537
- optionsArg.npmProbeOptions,
544
+ probeOptionsArg,
538
545
  )
539
546
  : probeAnonymousNpmArtifact(
540
547
  registryArg,
541
548
  artifact,
542
549
  journalArg.npm.tag,
543
- optionsArg.npmProbeOptions,
550
+ probeOptionsArg,
544
551
  );
545
552
  };
546
553
 
554
+ /** Waiting probes start fast and back off, because npm serves most versions within minutes. */
555
+ const npmAvailabilityDelayMs = 2_000;
556
+ const npmAvailabilityMaxDelayMs = 20_000;
557
+ const defaultNpmVerificationWindowMs =
558
+ defaultNpmVerificationWindowMinutes * 60_000;
559
+
560
+ const availabilityProbeOptions = (
561
+ optionsArg: IReleasePublicationOptions,
562
+ ): INpmArtifactProbeOptions => ({
563
+ ...planNpmAvailabilityProbes(
564
+ optionsArg.npmVerificationWindowMs ?? defaultNpmVerificationWindowMs,
565
+ npmAvailabilityDelayMs,
566
+ npmAvailabilityMaxDelayMs,
567
+ ),
568
+ ...optionsArg.npmProbeOptions,
569
+ });
570
+
571
+ const describeNpmTarget = (
572
+ registryArg: string,
573
+ packageNameArg?: string,
574
+ ): string =>
575
+ packageNameArg ? `${packageNameArg} on ${registryArg}` : registryArg;
576
+
577
+ const reportAcceptedNpmTarget = (
578
+ journalArg: TReleaseJournal,
579
+ registryArg: string,
580
+ packageNameArg?: string,
581
+ ): void => {
582
+ console.log(
583
+ `npm accepted ${describeNpmTarget(registryArg, packageNameArg)} but does not serve it yet. ` +
584
+ `Nothing is republished: run \`gitzone release resume ${journalArg.release.version} -y\` later to verify it.`,
585
+ );
586
+ };
587
+
547
588
  const markNpmProbeFailure = async (
548
589
  optionsArg: IReleasePublicationOptions,
549
590
  journalArg: TReleaseJournal,
@@ -579,7 +620,7 @@ const executeNpmRegistry = async (
579
620
  let probe = await probeNpm(
580
621
  journal,
581
622
  registryArg,
582
- optionsArg,
623
+ optionsArg.npmProbeOptions,
583
624
  false,
584
625
  packageNameArg,
585
626
  );
@@ -644,33 +685,44 @@ const executeNpmRegistry = async (
644
685
  throw new Error(`npm registry target is in conflict: ${registryArg}`);
645
686
  }
646
687
 
647
- // A component submission can succeed before npm makes it installable. Keep
648
- // that uncertainty durable without retaining a live publisher or resending
649
- // the accepted artifact on resume. Older root/Docker journal behavior stays
650
- // unchanged.
651
- if (
652
- hasReleasePackages(journal) &&
653
- status.state === "failed" &&
654
- status.attempts > 0 &&
655
- status.error === "verification-inconclusive" &&
656
- probe.status !== "exact" &&
657
- probe.status !== "conflict"
658
- ) {
688
+ // The registry took the upload before serving it. That uncertainty is
689
+ // durable: the accepted bytes are never sent again, and only an exact probe
690
+ // promotes the target.
691
+ if (status.state === "accepted") {
692
+ const settleAccepted = async (
693
+ probeArg: INpmArtifactProbeResult,
694
+ ): Promise<TReleaseJournal | undefined> => {
695
+ if (probeArg.status === "exact") {
696
+ return markUnclaimedTarget(
697
+ optionsArg.store,
698
+ journal,
699
+ selector,
700
+ ["accepted"],
701
+ "verified",
702
+ null,
703
+ );
704
+ }
705
+ if (probeArg.status !== "conflict") return undefined;
706
+ await markUnclaimedTarget(
707
+ optionsArg.store,
708
+ journal,
709
+ selector,
710
+ ["accepted"],
711
+ "conflict",
712
+ "artifact-conflict",
713
+ );
714
+ throw new Error(`npm registry contains conflicting bytes: ${registryArg}`);
715
+ };
716
+ const alreadyReadable = await settleAccepted(probe);
717
+ if (alreadyReadable) return alreadyReadable;
659
718
  if (deferVerificationArg) return journal;
660
719
  console.log(
661
- `Waiting for npm availability: ${packageNameArg} on ${registryArg}`,
720
+ `Waiting for npm availability: ${describeNpmTarget(registryArg, packageNameArg)}`,
662
721
  );
663
722
  probe = await probeNpm(
664
723
  journal,
665
724
  registryArg,
666
- {
667
- ...optionsArg,
668
- npmProbeOptions: {
669
- attempts: 91,
670
- delayMs: 10_000,
671
- ...optionsArg.npmProbeOptions,
672
- },
673
- },
725
+ availabilityProbeOptions(optionsArg),
674
726
  true,
675
727
  packageNameArg,
676
728
  );
@@ -679,26 +731,16 @@ const executeNpmRegistry = async (
679
731
  ? journal.release.mainOid
680
732
  : journal.git.expectedRemoteMainOid || undefined,
681
733
  );
682
- if (probe.status === "exact") {
683
- return markUnclaimedTarget(
684
- optionsArg.store,
685
- journal,
686
- selector,
687
- ["failed"],
688
- "verified",
689
- null,
690
- );
691
- }
692
- await markNpmProbeFailure(optionsArg, journal, selector, ["failed"], probe);
693
- throw new Error(
694
- `npm availability could not be verified: ${packageNameArg} on ${registryArg}`,
695
- );
734
+ const becameReadable = await settleAccepted(probe);
735
+ if (becameReadable) return becameReadable;
736
+ reportAcceptedNpmTarget(journal, registryArg, packageNameArg);
737
+ return journal;
696
738
  }
697
739
 
698
740
  probe = await probeNpm(
699
741
  journal,
700
742
  registryArg,
701
- optionsArg,
743
+ optionsArg.npmProbeOptions,
702
744
  false,
703
745
  packageNameArg,
704
746
  );
@@ -724,13 +766,9 @@ const executeNpmRegistry = async (
724
766
  );
725
767
  }
726
768
  if (probe.status !== "absent") {
727
- if (
728
- hasReleasePackages(journal) &&
729
- status.state === "failed" &&
730
- probe.status === "inconclusive"
731
- ) {
732
- // Preserve a prior command failure: a later network failure must not
733
- // turn it into evidence that the registry accepted the submission.
769
+ if (status.state === "failed" && probe.status === "inconclusive") {
770
+ // Preserve the recorded failure cause: a later network failure must not
771
+ // overwrite why the registry rejected the submission.
734
772
  throw new Error(`npm registry cannot be verified safely: ${registryArg}`);
735
773
  }
736
774
  await markNpmProbeFailure(
@@ -762,7 +800,7 @@ const executeNpmRegistry = async (
762
800
  probe = await probeNpm(
763
801
  journal,
764
802
  registryArg,
765
- optionsArg,
803
+ availabilityProbeOptions(optionsArg),
766
804
  !deferVerificationArg,
767
805
  packageNameArg,
768
806
  );
@@ -785,17 +823,26 @@ const executeNpmRegistry = async (
785
823
  );
786
824
  throw new Error(`npm registry published conflicting bytes: ${registryArg}`);
787
825
  }
788
- journal = await finishPublishingTarget(
826
+ if (npmPublishWasAccepted(publishResult)) {
827
+ journal = await finishPublishingTarget(
828
+ optionsArg.store,
829
+ journal,
830
+ selector,
831
+ "accepted",
832
+ null,
833
+ );
834
+ if (!deferVerificationArg)
835
+ reportAcceptedNpmTarget(journal, registryArg, packageNameArg);
836
+ return journal;
837
+ }
838
+ await finishPublishingTarget(
789
839
  optionsArg.store,
790
840
  journal,
791
841
  selector,
792
842
  "failed",
793
- publishResult.exitCode === 0
794
- ? "verification-inconclusive"
795
- : "command-failed",
843
+ "command-failed",
796
844
  );
797
- if (deferVerificationArg && publishResult.exitCode === 0) return journal;
798
- throw new Error(`npm publication could not be verified: ${registryArg}`);
845
+ throw new Error(`npm publication was rejected: ${registryArg}`);
799
846
  };
800
847
 
801
848
  const requireTsdocker = (
@@ -1691,11 +1738,7 @@ export const executeReleasePublication = async (
1691
1738
  // Success still requires every package/registry cell to verify exactly.
1692
1739
  if (hasReleasePackages(journal)) {
1693
1740
  for (const registry of journal.npm.registries) {
1694
- if (
1695
- registry.state !== "failed" ||
1696
- registry.error !== "verification-inconclusive"
1697
- )
1698
- continue;
1741
+ if (registry.state !== "accepted") continue;
1699
1742
  await optionsArg.ensurePublicationState(expectedRemoteMainOid);
1700
1743
  journal = await executeNpmRegistry(
1701
1744
  optionsArg,
@@ -1705,6 +1748,21 @@ export const executeReleasePublication = async (
1705
1748
  );
1706
1749
  }
1707
1750
  }
1751
+ const npmAwaitingAvailability = journal.npm.registries.some(
1752
+ (registryArg) => registryArg.state === "accepted",
1753
+ );
1754
+ if (
1755
+ journal.schemaVersion === 2 &&
1756
+ journal.docker.cleanup.state !== "verified" &&
1757
+ npmAwaitingAvailability
1758
+ ) {
1759
+ // Docker destinations follow verified npm publication, and an accepted
1760
+ // target is neither verified nor failed. Resume continues from here.
1761
+ console.log(
1762
+ "Docker promotion waits for the accepted npm target to become readable.",
1763
+ );
1764
+ return journal;
1765
+ }
1708
1766
  if (
1709
1767
  journal.schemaVersion === 2 &&
1710
1768
  journal.docker.cleanup.state !== "verified"
@@ -22,6 +22,7 @@ import {
22
22
  prepareReleaseIntegration,
23
23
  revalidatePreparedReleaseBranch,
24
24
  revalidateReleasePublicationState,
25
+ verifyReleaseHistoryRetained,
25
26
  releaseGitEnv,
26
27
  resolveReleaseMergeFlag,
27
28
  type IReleaseBranchContext,
@@ -36,6 +37,7 @@ import {
36
37
  resolveGitCommonDirectory,
37
38
  getReleaseArtifacts,
38
39
  hasReleasePackages,
40
+ isVerificationOnlyResume,
39
41
  releasePackageArtifactFile,
40
42
  type IReleasePackage,
41
43
  type IReleaseArtifact,
@@ -348,17 +350,35 @@ const runInternal = async (argvArg: any): Promise<void> => {
348
350
  store: journalContext.store,
349
351
  journal: journalContext.journal,
350
352
  pushUrl: releasePushUrl,
353
+ npmVerificationWindowMs: workflow.npmVerificationWindowMinutes * 60_000,
351
354
  tsdocker,
352
355
  ensurePublicationState,
353
356
  });
354
- // Only after a successful publication: a failed release keeps its test
355
- // logs so the failure can be diagnosed.
356
- if (workflow.cleanTestArtifacts) {
357
- await runTstestCleanup(smartshellInstance, releaseCwd);
358
- }
357
+ await cleanTestArtifactsForCompletedRelease(
358
+ smartshellInstance,
359
+ releaseCwd,
360
+ finalJournal,
361
+ workflow.cleanTestArtifacts,
362
+ );
359
363
  printReleaseJournalSummary(finalJournal);
360
364
  };
361
365
 
366
+ /**
367
+ * Test logs are release diagnostics, so only a journal that reached completion
368
+ * may drop them. A failure keeps them for the investigation, and a journal left
369
+ * incomplete — an npm target still awaiting availability, for instance — keeps
370
+ * them for the resume that finishes it; that resume then runs this cleanup.
371
+ */
372
+ export const cleanTestArtifactsForCompletedRelease = async (
373
+ smartshellArg: plugins.smartshell.Smartshell,
374
+ cwdArg: string,
375
+ journalArg: Pick<TReleaseJournal, "completedAt">,
376
+ cleanRequestedArg: boolean,
377
+ ): Promise<void> => {
378
+ if (!cleanRequestedArg || journalArg.completedAt === null) return;
379
+ await runTstestCleanup(smartshellArg, cwdArg);
380
+ };
381
+
362
382
  const assertFreshReleaseCapabilities = async (
363
383
  smartshellArg: plugins.smartshell.Smartshell,
364
384
  workflowArg: IResolvedReleaseWorkflow,
@@ -932,6 +952,7 @@ const runReleaseRecover = async (
932
952
  store: context.store,
933
953
  journal: context.journal,
934
954
  pushUrl: branch.pushUrl,
955
+ npmVerificationWindowMs: workflow.npmVerificationWindowMinutes * 60_000,
935
956
  tsdocker,
936
957
  ensurePublicationState: ensureState,
937
958
  });
@@ -1068,20 +1089,12 @@ const runReleaseResume = async (
1068
1089
  mergeRequested: false,
1069
1090
  planMode: false,
1070
1091
  });
1071
- if (branchContext.sourceOid !== journal.release.mainOid) {
1072
- throw new Error(
1073
- "Resume must run from the journaled release commit on main.",
1074
- );
1075
- }
1076
- const refs = await captureReleaseRefs(
1092
+ const { refs, verificationOnly } = await resolveResumeReleaseRefs(
1077
1093
  smartshellInstance,
1078
1094
  paths.cwd,
1079
- version,
1080
- journal.release.mainOid,
1095
+ journal,
1096
+ branchContext,
1081
1097
  );
1082
- if (refs.tagOid !== journal.release.tagOid) {
1083
- throw new Error("The local release tag no longer matches the journal.");
1084
- }
1085
1098
  const pushUrl = gitEnabled ? branchContext.pushUrl : undefined;
1086
1099
  if (
1087
1100
  gitEnabled &&
@@ -1109,7 +1122,22 @@ const runReleaseResume = async (
1109
1122
  const ensurePublicationState = async (
1110
1123
  expectedRemoteMainOidArg?: string,
1111
1124
  ): Promise<void> => {
1112
- await verifyReleaseRefs(smartshellInstance, paths.cwd, version, refs);
1125
+ await verifyReleaseRefs(
1126
+ smartshellInstance,
1127
+ paths.cwd,
1128
+ version,
1129
+ refs,
1130
+ verificationOnly,
1131
+ );
1132
+ if (verificationOnly) {
1133
+ // Nothing is published, so main's tip is free to have moved on.
1134
+ await verifyReleaseHistoryRetained(
1135
+ smartshellInstance,
1136
+ branchContext,
1137
+ journal.release.mainOid,
1138
+ );
1139
+ return;
1140
+ }
1113
1141
  await revalidateReleasePublicationState(
1114
1142
  smartshellInstance,
1115
1143
  branchContext,
@@ -1125,9 +1153,17 @@ const runReleaseResume = async (
1125
1153
  journal,
1126
1154
  pushUrl,
1127
1155
  recoveryAttemptId,
1156
+ npmVerificationWindowMs:
1157
+ resumeConfiguration.npmVerificationWindowMinutes * 60_000,
1128
1158
  tsdocker,
1129
1159
  ensurePublicationState,
1130
1160
  });
1161
+ await cleanTestArtifactsForCompletedRelease(
1162
+ smartshellInstance,
1163
+ paths.cwd,
1164
+ finalJournal,
1165
+ resumeConfiguration.cleanTestArtifacts,
1166
+ );
1131
1167
  printReleaseJournalSummary(finalJournal);
1132
1168
  };
1133
1169
 
@@ -1437,6 +1473,9 @@ const captureReleaseRefs = async (
1437
1473
  cwdArg: string,
1438
1474
  newVersionArg: string,
1439
1475
  expectedMainOidArg?: string,
1476
+ // Verification reads the release commit through its tag, so main is allowed
1477
+ // to carry later commits.
1478
+ mainMayBeAheadArg = false,
1440
1479
  ): Promise<IReleaseRefs> => {
1441
1480
  const mainOid = await resolveGitObjectOid(
1442
1481
  smartshellInstanceArg,
@@ -1453,15 +1492,17 @@ const captureReleaseRefs = async (
1453
1492
  cwdArg,
1454
1493
  `refs/tags/v${newVersionArg}^{commit}`,
1455
1494
  );
1495
+ const releaseOid =
1496
+ mainMayBeAheadArg && expectedMainOidArg ? expectedMainOidArg : mainOid;
1456
1497
  if (
1457
- (expectedMainOidArg && mainOid !== expectedMainOidArg) ||
1458
- tagCommitOid !== mainOid
1498
+ (expectedMainOidArg && releaseOid !== expectedMainOidArg) ||
1499
+ tagCommitOid !== releaseOid
1459
1500
  ) {
1460
1501
  throw new Error(
1461
1502
  "The release tag is not bound to the captured main release commit.",
1462
1503
  );
1463
1504
  }
1464
- return { mainOid, tagOid };
1505
+ return { mainOid: releaseOid, tagOid };
1465
1506
  };
1466
1507
 
1467
1508
  const verifyReleaseRefs = async (
@@ -1469,12 +1510,14 @@ const verifyReleaseRefs = async (
1469
1510
  cwdArg: string,
1470
1511
  newVersionArg: string,
1471
1512
  expectedRefsArg: IReleaseRefs,
1513
+ mainMayBeAheadArg = false,
1472
1514
  ): Promise<void> => {
1473
1515
  const currentRefs = await captureReleaseRefs(
1474
1516
  smartshellInstanceArg,
1475
1517
  cwdArg,
1476
1518
  newVersionArg,
1477
1519
  expectedRefsArg.mainOid,
1520
+ mainMayBeAheadArg,
1478
1521
  );
1479
1522
  if (
1480
1523
  currentRefs.mainOid !== expectedRefsArg.mainOid ||
@@ -1486,6 +1529,43 @@ const verifyReleaseRefs = async (
1486
1529
  }
1487
1530
  };
1488
1531
 
1532
+ /**
1533
+ * Resume reads the journaled release commit through its tag. Only a resume
1534
+ * that still has publication work left must run from that exact commit; a
1535
+ * verification-only resume accepts a main that already moved past it.
1536
+ */
1537
+ export const resolveResumeReleaseRefs = async (
1538
+ smartshellInstanceArg: plugins.smartshell.Smartshell,
1539
+ cwdArg: string,
1540
+ journalArg: TReleaseJournal,
1541
+ branchContextArg: IReleaseBranchContext,
1542
+ ): Promise<{ refs: IReleaseRefs; verificationOnly: boolean }> => {
1543
+ const verificationOnly = isVerificationOnlyResume(journalArg);
1544
+ if (branchContextArg.sourceOid !== journalArg.release.mainOid) {
1545
+ if (!verificationOnly) {
1546
+ throw new Error(
1547
+ "Resume must run from the journaled release commit on main.",
1548
+ );
1549
+ }
1550
+ await verifyReleaseHistoryRetained(
1551
+ smartshellInstanceArg,
1552
+ branchContextArg,
1553
+ journalArg.release.mainOid,
1554
+ );
1555
+ }
1556
+ const refs = await captureReleaseRefs(
1557
+ smartshellInstanceArg,
1558
+ cwdArg,
1559
+ journalArg.release.version,
1560
+ journalArg.release.mainOid,
1561
+ verificationOnly,
1562
+ );
1563
+ if (refs.tagOid !== journalArg.release.tagOid) {
1564
+ throw new Error("The local release tag no longer matches the journal.");
1565
+ }
1566
+ return { refs, verificationOnly };
1567
+ };
1568
+
1489
1569
  type TDockerCommandWorkflow = Pick<
1490
1570
  IResolvedReleaseWorkflow,
1491
1571
  | "dockerRegistry"