@git.zone/cli 6.14.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.
@@ -4,7 +4,6 @@ import { logger } from "../gitzone.logging.js";
4
4
  import type { ICliMode } from "../helpers.climode.js";
5
5
  import { getCliMode, printJson } from "../helpers.climode.js";
6
6
  import {
7
- inferVersionTypeFromPending,
8
7
  movePendingToVersion,
9
8
  readPendingChangelog,
10
9
  } from "../helpers.changelog.js";
@@ -23,6 +22,7 @@ import {
23
22
  prepareReleaseIntegration,
24
23
  revalidatePreparedReleaseBranch,
25
24
  revalidateReleasePublicationState,
25
+ verifyReleaseHistoryRetained,
26
26
  releaseGitEnv,
27
27
  resolveReleaseMergeFlag,
28
28
  type IReleaseBranchContext,
@@ -37,6 +37,7 @@ import {
37
37
  resolveGitCommonDirectory,
38
38
  getReleaseArtifacts,
39
39
  hasReleasePackages,
40
+ isVerificationOnlyResume,
40
41
  releasePackageArtifactFile,
41
42
  type IReleasePackage,
42
43
  type IReleaseArtifact,
@@ -71,6 +72,15 @@ import {
71
72
  type ITsdockerReleaseClient,
72
73
  type IReleaseQualificationRequest,
73
74
  } from "./helpers.tsdockerprotocol.js";
75
+ import {
76
+ assertResolvedCurrentVersion,
77
+ describeAppliedVersionFloor,
78
+ describeReleaseVersion,
79
+ resolveReleaseVersion,
80
+ toReleaseVersionFloorRecord,
81
+ type IReleaseVersionFloorRecord,
82
+ type IReleaseVersionResolution,
83
+ } from "./helpers.releaseversion.js";
74
84
 
75
85
  export { buildReleaseGitPushArgs } from "./helpers.releasepublication.js";
76
86
 
@@ -139,7 +149,23 @@ const runInternal = async (argvArg: any): Promise<void> => {
139
149
  workflow.giteaAssets,
140
150
  branchContext.pushUrl || "",
141
151
  );
142
- printReleasePlan(workflow, branchContext);
152
+ const pending = await readPendingChangelog(
153
+ plugins.path.join(branchContext.sourceCwd, workflow.changelogFile),
154
+ workflow.changelogPendingSection,
155
+ );
156
+ const projectType = await commitHelpers.detectProjectType(
157
+ branchContext.sourceCwd,
158
+ );
159
+ const versionResolution = resolveReleaseVersion({
160
+ currentVersion: await commitHelpers.readCurrentVersion(
161
+ projectType,
162
+ branchContext.sourceCwd,
163
+ ),
164
+ pendingChangelog: pending.block,
165
+ levelOverride: readReleaseLevelOverride(argvArg),
166
+ versionFloor: workflow.versionFloor,
167
+ });
168
+ printReleasePlan(workflow, branchContext, versionResolution);
143
169
  if (
144
170
  workflow.targets.includes("npm") &&
145
171
  workflow.npmPackageSource === "tspublish"
@@ -164,26 +190,11 @@ const runInternal = async (argvArg: any): Promise<void> => {
164
190
  preflightTsdocker,
165
191
  );
166
192
 
167
- const pending = await readPendingChangelog(
168
- plugins.path.join(branchContext.sourceCwd, workflow.changelogFile),
169
- workflow.changelogPendingSection,
170
- );
171
193
  if (pending.isEmpty && !argvArg["allow-empty"] && !argvArg.allowEmpty) {
172
194
  throw new Error("No pending changelog entries. Nothing to release.");
173
195
  }
174
196
 
175
- const versionType = resolveVersionType(argvArg, pending.block);
176
- const projectType = await commitHelpers.detectProjectType(
177
- branchContext.sourceCwd,
178
- );
179
- const currentVersion = await commitHelpers.readCurrentVersion(
180
- projectType,
181
- branchContext.sourceCwd,
182
- );
183
- const plannedVersion = commitHelpers.calculateNewVersion(
184
- currentVersion,
185
- versionType,
186
- );
197
+ const newVersion = versionResolution.version;
187
198
  if (workflow.giteaAssets) {
188
199
  const { tokenEnv, manifestPath, ...destination } = workflow.giteaAssets;
189
200
  const token = process.env[tokenEnv];
@@ -193,7 +204,7 @@ const runInternal = async (argvArg: any): Promise<void> => {
193
204
  );
194
205
  await new GiteaAssetsClient({
195
206
  destination,
196
- tag: `v${plannedVersion}`,
207
+ tag: `v${newVersion}`,
197
208
  commit: branchContext.sourceOid,
198
209
  token,
199
210
  }).preflight();
@@ -203,7 +214,7 @@ const runInternal = async (argvArg: any): Promise<void> => {
203
214
  createDockerQualificationRequest(
204
215
  workflow,
205
216
  branchContext.sourceCwd,
206
- plannedVersion,
217
+ newVersion,
207
218
  branchContext.sourceOid,
208
219
  ),
209
220
  );
@@ -217,7 +228,7 @@ const runInternal = async (argvArg: any): Promise<void> => {
217
228
  }
218
229
  const confirmed =
219
230
  await plugins.smartinteract.SmartInteract.getCliConfirmation(
220
- `Release v${plannedVersion} (${versionType}) now?`,
231
+ `Release v${newVersion} now?`,
221
232
  true,
222
233
  );
223
234
  if (!confirmed) {
@@ -226,7 +237,6 @@ const runInternal = async (argvArg: any): Promise<void> => {
226
237
  }
227
238
  }
228
239
 
229
- let newVersion = plannedVersion;
230
240
  branchContext = await prepareReleaseIntegration(
231
241
  smartshellInstance,
232
242
  branchContext,
@@ -255,7 +265,7 @@ const runInternal = async (argvArg: any): Promise<void> => {
255
265
  expectedRemoteMainOid = integration.expectedRemoteMainOid;
256
266
  }
257
267
 
258
- newVersion = await runVersionStep(projectType, versionType, releaseCwd);
268
+ await runVersionStep(projectType, versionResolution, releaseCwd);
259
269
  await runChangelogStep(workflow, newVersion, releaseCwd);
260
270
  const releaseCommitOid = await runReleaseCommitStep(
261
271
  smartshellInstance,
@@ -327,6 +337,7 @@ const runInternal = async (argvArg: any): Promise<void> => {
327
337
  releasePushUrl,
328
338
  expectedRemoteMainOid,
329
339
  version: newVersion,
340
+ versionFloor: toReleaseVersionFloorRecord(versionResolution),
330
341
  refs: releaseRefs,
331
342
  dockerRequest,
332
343
  tsdocker,
@@ -339,17 +350,35 @@ const runInternal = async (argvArg: any): Promise<void> => {
339
350
  store: journalContext.store,
340
351
  journal: journalContext.journal,
341
352
  pushUrl: releasePushUrl,
353
+ npmVerificationWindowMs: workflow.npmVerificationWindowMinutes * 60_000,
342
354
  tsdocker,
343
355
  ensurePublicationState,
344
356
  });
345
- // Only after a successful publication: a failed release keeps its test
346
- // logs so the failure can be diagnosed.
347
- if (workflow.cleanTestArtifacts) {
348
- await runTstestCleanup(smartshellInstance, releaseCwd);
349
- }
357
+ await cleanTestArtifactsForCompletedRelease(
358
+ smartshellInstance,
359
+ releaseCwd,
360
+ finalJournal,
361
+ workflow.cleanTestArtifacts,
362
+ );
350
363
  printReleaseJournalSummary(finalJournal);
351
364
  };
352
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
+
353
382
  const assertFreshReleaseCapabilities = async (
354
383
  smartshellArg: plugins.smartshell.Smartshell,
355
384
  workflowArg: IResolvedReleaseWorkflow,
@@ -463,6 +492,7 @@ interface ICreateReleaseJournalOptions {
463
492
  releasePushUrl?: string;
464
493
  expectedRemoteMainOid?: string;
465
494
  version: string;
495
+ versionFloor?: IReleaseVersionFloorRecord;
466
496
  refs: IReleaseRefs;
467
497
  dockerRequest?: IReleaseQualificationRequest;
468
498
  tsdocker?: ITsdockerReleaseClient;
@@ -639,6 +669,9 @@ export const createReleaseJournal = async (
639
669
  tag: `v${optionsArg.version}`,
640
670
  mainOid: optionsArg.refs.mainOid,
641
671
  tagOid: optionsArg.refs.tagOid,
672
+ ...(optionsArg.versionFloor
673
+ ? { versionFloor: optionsArg.versionFloor }
674
+ : {}),
642
675
  },
643
676
  artifact,
644
677
  ...(packages.length || giteaAssets ? { packages } : {}),
@@ -890,6 +923,9 @@ const runReleaseRecover = async (
890
923
  const context = await withReleasePreparationRecovery(
891
924
  options,
892
925
  ensureUnpublished,
926
+ // The existing tag is authoritative: recovery never re-derives its version,
927
+ // and the failed run's level override that fed any floor decision is not
928
+ // recorded, so a recovered journal carries no version floor record.
893
929
  async (checkout, ensureCheckout) =>
894
930
  createReleaseJournal({
895
931
  pnpmCapability,
@@ -916,6 +952,7 @@ const runReleaseRecover = async (
916
952
  store: context.store,
917
953
  journal: context.journal,
918
954
  pushUrl: branch.pushUrl,
955
+ npmVerificationWindowMs: workflow.npmVerificationWindowMinutes * 60_000,
919
956
  tsdocker,
920
957
  ensurePublicationState: ensureState,
921
958
  });
@@ -1052,20 +1089,12 @@ const runReleaseResume = async (
1052
1089
  mergeRequested: false,
1053
1090
  planMode: false,
1054
1091
  });
1055
- if (branchContext.sourceOid !== journal.release.mainOid) {
1056
- throw new Error(
1057
- "Resume must run from the journaled release commit on main.",
1058
- );
1059
- }
1060
- const refs = await captureReleaseRefs(
1092
+ const { refs, verificationOnly } = await resolveResumeReleaseRefs(
1061
1093
  smartshellInstance,
1062
1094
  paths.cwd,
1063
- version,
1064
- journal.release.mainOid,
1095
+ journal,
1096
+ branchContext,
1065
1097
  );
1066
- if (refs.tagOid !== journal.release.tagOid) {
1067
- throw new Error("The local release tag no longer matches the journal.");
1068
- }
1069
1098
  const pushUrl = gitEnabled ? branchContext.pushUrl : undefined;
1070
1099
  if (
1071
1100
  gitEnabled &&
@@ -1093,7 +1122,22 @@ const runReleaseResume = async (
1093
1122
  const ensurePublicationState = async (
1094
1123
  expectedRemoteMainOidArg?: string,
1095
1124
  ): Promise<void> => {
1096
- 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
+ }
1097
1141
  await revalidateReleasePublicationState(
1098
1142
  smartshellInstance,
1099
1143
  branchContext,
@@ -1109,9 +1153,17 @@ const runReleaseResume = async (
1109
1153
  journal,
1110
1154
  pushUrl,
1111
1155
  recoveryAttemptId,
1156
+ npmVerificationWindowMs:
1157
+ resumeConfiguration.npmVerificationWindowMinutes * 60_000,
1112
1158
  tsdocker,
1113
1159
  ensurePublicationState,
1114
1160
  });
1161
+ await cleanTestArtifactsForCompletedRelease(
1162
+ smartshellInstance,
1163
+ paths.cwd,
1164
+ finalJournal,
1165
+ resumeConfiguration.cleanTestArtifacts,
1166
+ );
1115
1167
  printReleaseJournalSummary(finalJournal);
1116
1168
  };
1117
1169
 
@@ -1168,6 +1220,14 @@ const assertResumeConfiguration = async (
1168
1220
  const printReleaseJournalSummary = (journalArg: TReleaseJournal): void => {
1169
1221
  console.log("");
1170
1222
  console.log(`Release v${journalArg.release.version}`);
1223
+ if (journalArg.release.versionFloor) {
1224
+ console.log(
1225
+ describeAppliedVersionFloor(
1226
+ journalArg.release.versionFloor,
1227
+ journalArg.release.version,
1228
+ ),
1229
+ );
1230
+ }
1171
1231
  console.log(`journal revision: ${journalArg.revision}`);
1172
1232
  console.log(
1173
1233
  `artifact: ${journalArg.artifact ? `${journalArg.artifact.integrity} (${journalArg.artifact.sha256})` : "none"}`,
@@ -1206,14 +1266,13 @@ const printReleaseJournalSummary = (journalArg: TReleaseJournal): void => {
1206
1266
  console.log("");
1207
1267
  };
1208
1268
 
1209
- function resolveVersionType(
1269
+ function readReleaseLevelOverride(
1210
1270
  argvArg: any,
1211
- pendingBlock: string,
1212
- ): commitHelpers.VersionType {
1271
+ ): commitHelpers.VersionType | undefined {
1213
1272
  if (argvArg.major) return "major";
1214
1273
  if (argvArg.minor) return "minor";
1215
1274
  if (argvArg.patch) return "patch";
1216
- return inferVersionTypeFromPending(pendingBlock);
1275
+ return undefined;
1217
1276
  }
1218
1277
 
1219
1278
  async function runCommandStep(
@@ -1252,27 +1311,28 @@ async function verifyCleanTree(
1252
1311
 
1253
1312
  async function runVersionStep(
1254
1313
  projectType: commitHelpers.ProjectType,
1255
- versionType: commitHelpers.VersionType,
1314
+ resolutionArg: IReleaseVersionResolution,
1256
1315
  cwdArg: string,
1257
- ): Promise<string> {
1316
+ ): Promise<void> {
1258
1317
  const currentVersion = await commitHelpers.readCurrentVersion(
1259
1318
  projectType,
1260
1319
  cwdArg,
1261
1320
  );
1262
- const newVersion = commitHelpers.calculateNewVersion(
1263
- currentVersion,
1264
- versionType,
1321
+ assertResolvedCurrentVersion(resolutionArg, currentVersion);
1322
+ logger.log(
1323
+ "info",
1324
+ `Bumping version: ${currentVersion} -> ${resolutionArg.version}`,
1265
1325
  );
1266
- logger.log("info", `Bumping version: ${currentVersion} -> ${newVersion}`);
1267
1326
 
1268
- const commitInfo = new plugins.commitinfo.CommitInfo(cwdArg, versionType);
1327
+ const commitInfo = new plugins.commitinfo.CommitInfo(cwdArg, {
1328
+ version: resolutionArg.version,
1329
+ });
1269
1330
  await commitInfo.writeIntoPotentialDirs();
1270
1331
  await commitHelpers.updateProjectVersionFiles(
1271
1332
  projectType,
1272
- newVersion,
1333
+ resolutionArg.version,
1273
1334
  cwdArg,
1274
1335
  );
1275
- return newVersion;
1276
1336
  }
1277
1337
 
1278
1338
  async function runChangelogStep(
@@ -1413,6 +1473,9 @@ const captureReleaseRefs = async (
1413
1473
  cwdArg: string,
1414
1474
  newVersionArg: string,
1415
1475
  expectedMainOidArg?: string,
1476
+ // Verification reads the release commit through its tag, so main is allowed
1477
+ // to carry later commits.
1478
+ mainMayBeAheadArg = false,
1416
1479
  ): Promise<IReleaseRefs> => {
1417
1480
  const mainOid = await resolveGitObjectOid(
1418
1481
  smartshellInstanceArg,
@@ -1429,15 +1492,17 @@ const captureReleaseRefs = async (
1429
1492
  cwdArg,
1430
1493
  `refs/tags/v${newVersionArg}^{commit}`,
1431
1494
  );
1495
+ const releaseOid =
1496
+ mainMayBeAheadArg && expectedMainOidArg ? expectedMainOidArg : mainOid;
1432
1497
  if (
1433
- (expectedMainOidArg && mainOid !== expectedMainOidArg) ||
1434
- tagCommitOid !== mainOid
1498
+ (expectedMainOidArg && releaseOid !== expectedMainOidArg) ||
1499
+ tagCommitOid !== releaseOid
1435
1500
  ) {
1436
1501
  throw new Error(
1437
1502
  "The release tag is not bound to the captured main release commit.",
1438
1503
  );
1439
1504
  }
1440
- return { mainOid, tagOid };
1505
+ return { mainOid: releaseOid, tagOid };
1441
1506
  };
1442
1507
 
1443
1508
  const verifyReleaseRefs = async (
@@ -1445,12 +1510,14 @@ const verifyReleaseRefs = async (
1445
1510
  cwdArg: string,
1446
1511
  newVersionArg: string,
1447
1512
  expectedRefsArg: IReleaseRefs,
1513
+ mainMayBeAheadArg = false,
1448
1514
  ): Promise<void> => {
1449
1515
  const currentRefs = await captureReleaseRefs(
1450
1516
  smartshellInstanceArg,
1451
1517
  cwdArg,
1452
1518
  newVersionArg,
1453
1519
  expectedRefsArg.mainOid,
1520
+ mainMayBeAheadArg,
1454
1521
  );
1455
1522
  if (
1456
1523
  currentRefs.mainOid !== expectedRefsArg.mainOid ||
@@ -1462,6 +1529,43 @@ const verifyReleaseRefs = async (
1462
1529
  }
1463
1530
  };
1464
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
+
1465
1569
  type TDockerCommandWorkflow = Pick<
1466
1570
  IResolvedReleaseWorkflow,
1467
1571
  | "dockerRegistry"
@@ -1516,6 +1620,7 @@ function shellQuote(value: string): string {
1516
1620
  function printReleasePlan(
1517
1621
  workflow: IResolvedReleaseWorkflow,
1518
1622
  branchContextArg: IReleaseBranchContext,
1623
+ versionResolutionArg: IReleaseVersionResolution,
1519
1624
  ): void {
1520
1625
  console.log("");
1521
1626
  console.log("gitzone release - resolved workflow");
@@ -1534,6 +1639,9 @@ function printReleasePlan(
1534
1639
  console.log(
1535
1640
  `changelog: ${workflow.changelogFile}#${workflow.changelogPendingSection}`,
1536
1641
  );
1642
+ for (const line of describeReleaseVersion(versionResolutionArg)) {
1643
+ console.log(line);
1644
+ }
1537
1645
  if (workflow.targets.includes("npm")) {
1538
1646
  console.log(`npm package source: ${workflow.npmPackageSource}`);
1539
1647
  console.log(
@@ -1687,7 +1795,9 @@ export function showHelp(mode?: ICliMode): void {
1687
1795
  console.log(
1688
1796
  " --merge Fast-forward and lease-push a cleanly rebased feature branch before release metadata",
1689
1797
  );
1690
- console.log(" --major|--minor|--patch Override inferred semver level");
1798
+ console.log(
1799
+ " --major|--minor|--patch Override inferred semver level; release.versionFloor still applies",
1800
+ );
1691
1801
  console.log(
1692
1802
  " --plan Show workflow without fetching or mutating refs, files, index, or worktrees",
1693
1803
  );