@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.
- package/dist_ts/00_commitinfo_data.js +3 -3
- package/dist_ts/helpers.workflow.d.ts +10 -0
- package/dist_ts/helpers.workflow.js +22 -1
- package/dist_ts/mod_config/index.js +41 -2
- package/dist_ts/mod_release/classes.releasejournal.d.ts +23 -13
- package/dist_ts/mod_release/classes.releasejournal.js +83 -35
- package/dist_ts/mod_release/helpers.npmartifact.d.ts +20 -0
- package/dist_ts/mod_release/helpers.npmartifact.js +50 -2
- package/dist_ts/mod_release/helpers.releasebranch.d.ts +6 -0
- package/dist_ts/mod_release/helpers.releasebranch.js +56 -1
- package/dist_ts/mod_release/helpers.releasepublication.d.ts +2 -0
- package/dist_ts/mod_release/helpers.releasepublication.js +68 -46
- package/dist_ts/mod_release/helpers.releaseversion.d.ts +59 -0
- package/dist_ts/mod_release/helpers.releaseversion.js +148 -0
- package/dist_ts/mod_release/index.d.ts +19 -0
- package/dist_ts/mod_release/index.js +97 -45
- package/package.json +6 -6
- package/readme.md +92 -12
- package/ts/00_commitinfo_data.ts +3 -3
- package/ts/helpers.workflow.ts +39 -0
- package/ts/mod_config/index.ts +45 -0
- package/ts/mod_release/classes.releasejournal.ts +141 -63
- package/ts/mod_release/helpers.npmartifact.ts +76 -1
- package/ts/mod_release/helpers.releasebranch.ts +114 -0
- package/ts/mod_release/helpers.releasepublication.ts +119 -61
- package/ts/mod_release/helpers.releaseversion.ts +261 -0
- package/ts/mod_release/index.ts +167 -57
|
@@ -21,6 +21,11 @@ import {
|
|
|
21
21
|
type IReleaseQualificationResult,
|
|
22
22
|
type TReleasePromotionEvidence,
|
|
23
23
|
} from "./helpers.tsdockerprotocol.js";
|
|
24
|
+
import {
|
|
25
|
+
compareReleaseVersions,
|
|
26
|
+
isCanonicalReleaseVersion,
|
|
27
|
+
type IReleaseVersionFloorRecord,
|
|
28
|
+
} from "./helpers.releaseversion.js";
|
|
24
29
|
|
|
25
30
|
export const releaseJournalStorageVersion = 1 as const;
|
|
26
31
|
export const legacyReleaseJournalSchemaVersion = 1 as const;
|
|
@@ -28,8 +33,19 @@ export const releaseJournalSchemaVersion = 2 as const;
|
|
|
28
33
|
export const releaseArtifactFileName = "package.tgz" as const;
|
|
29
34
|
export const releaseJournalFileName = "journal.json" as const;
|
|
30
35
|
|
|
36
|
+
/**
|
|
37
|
+
* `accepted` records a destination that took the upload without rejecting it
|
|
38
|
+
* while its read-back is still missing. It is neither a success nor a failure:
|
|
39
|
+
* the bytes are never sent again, and only an exact probe promotes it.
|
|
40
|
+
*/
|
|
31
41
|
export type TReleaseTargetState =
|
|
32
|
-
|
|
42
|
+
| "pending"
|
|
43
|
+
| "publishing"
|
|
44
|
+
| "accepted"
|
|
45
|
+
| "verified"
|
|
46
|
+
| "failed"
|
|
47
|
+
| "conflict"
|
|
48
|
+
| "skipped";
|
|
33
49
|
|
|
34
50
|
export type TReleaseErrorCode =
|
|
35
51
|
| "command-failed"
|
|
@@ -74,16 +90,20 @@ export interface IReleaseNpmRegistryJournal extends IReleaseTargetStatus {
|
|
|
74
90
|
packageName?: string;
|
|
75
91
|
}
|
|
76
92
|
|
|
93
|
+
export interface IReleaseIdentity {
|
|
94
|
+
version: string;
|
|
95
|
+
tag: string;
|
|
96
|
+
mainOid: string;
|
|
97
|
+
tagOid: string;
|
|
98
|
+
/** Present only when release.versionFloor raised the version above the inferred one. */
|
|
99
|
+
versionFloor?: IReleaseVersionFloorRecord;
|
|
100
|
+
}
|
|
101
|
+
|
|
77
102
|
export interface IReleaseJournalV1 {
|
|
78
103
|
kind: "gitzone-release-journal";
|
|
79
104
|
schemaVersion: typeof legacyReleaseJournalSchemaVersion;
|
|
80
105
|
revision: number;
|
|
81
|
-
release:
|
|
82
|
-
version: string;
|
|
83
|
-
tag: string;
|
|
84
|
-
mainOid: string;
|
|
85
|
-
tagOid: string;
|
|
86
|
-
};
|
|
106
|
+
release: IReleaseIdentity;
|
|
87
107
|
artifact: IReleaseArtifact | null;
|
|
88
108
|
git: IReleaseGitJournal;
|
|
89
109
|
npm: {
|
|
@@ -123,12 +143,7 @@ export interface IReleaseJournalV2 {
|
|
|
123
143
|
kind: "gitzone-release-journal";
|
|
124
144
|
schemaVersion: typeof releaseJournalSchemaVersion;
|
|
125
145
|
revision: number;
|
|
126
|
-
release:
|
|
127
|
-
version: string;
|
|
128
|
-
tag: string;
|
|
129
|
-
mainOid: string;
|
|
130
|
-
tagOid: string;
|
|
131
|
-
};
|
|
146
|
+
release: IReleaseIdentity;
|
|
132
147
|
artifact: IReleaseArtifact | null;
|
|
133
148
|
git: IReleaseGitJournal;
|
|
134
149
|
npm: {
|
|
@@ -213,7 +228,6 @@ export const getReleaseNpmArtifact = (
|
|
|
213
228
|
return artifact;
|
|
214
229
|
};
|
|
215
230
|
|
|
216
|
-
const releaseVersionRegex = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/;
|
|
217
231
|
const gitOidRegex = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
218
232
|
const attemptIdRegex = /^[0-9a-f]{32}$/;
|
|
219
233
|
const sha1Regex = /^[0-9a-f]{40}$/;
|
|
@@ -225,6 +239,7 @@ const gitRemoteNameRegex = /^[A-Za-z0-9][A-Za-z0-9._/-]*$/;
|
|
|
225
239
|
const targetStates: TReleaseTargetState[] = [
|
|
226
240
|
"pending",
|
|
227
241
|
"publishing",
|
|
242
|
+
"accepted",
|
|
228
243
|
"verified",
|
|
229
244
|
"failed",
|
|
230
245
|
"conflict",
|
|
@@ -292,7 +307,7 @@ const assertIsoTimestamp = (valueArg: unknown, contextArg: string): string => {
|
|
|
292
307
|
|
|
293
308
|
export const normalizeReleaseVersion = (valueArg: string): string => {
|
|
294
309
|
const version = valueArg.startsWith("v") ? valueArg.slice(1) : valueArg;
|
|
295
|
-
if (!
|
|
310
|
+
if (!isCanonicalReleaseVersion(version)) {
|
|
296
311
|
throw new Error(
|
|
297
312
|
"Release journal versions must use canonical x.y.z semver.",
|
|
298
313
|
);
|
|
@@ -368,12 +383,16 @@ const assertTargetStatus = (
|
|
|
368
383
|
|
|
369
384
|
if (
|
|
370
385
|
(valueArg.state === "pending" ||
|
|
386
|
+
valueArg.state === "accepted" ||
|
|
371
387
|
valueArg.state === "verified" ||
|
|
372
388
|
valueArg.state === "skipped") &&
|
|
373
389
|
valueArg.error !== null
|
|
374
390
|
) {
|
|
375
391
|
throw new Error(`${contextArg}.error must be null for ${valueArg.state}.`);
|
|
376
392
|
}
|
|
393
|
+
if (valueArg.state === "accepted" && (valueArg.attempts as number) < 1) {
|
|
394
|
+
throw new Error(`${contextArg} accepted state requires one attempt.`);
|
|
395
|
+
}
|
|
377
396
|
if (
|
|
378
397
|
(valueArg.state === "failed" || valueArg.state === "conflict") &&
|
|
379
398
|
valueArg.error === null
|
|
@@ -452,6 +471,39 @@ const isComplete = (journalArg: TReleaseJournal): boolean => {
|
|
|
452
471
|
);
|
|
453
472
|
};
|
|
454
473
|
|
|
474
|
+
/**
|
|
475
|
+
* True when every remaining target only needs verification. Such a resume
|
|
476
|
+
* sends no bytes and mutates no destination, so it may run from a main that
|
|
477
|
+
* already carries later commits.
|
|
478
|
+
*/
|
|
479
|
+
export const isVerificationOnlyResume = (
|
|
480
|
+
journalArg: TReleaseJournal,
|
|
481
|
+
): boolean => {
|
|
482
|
+
const targets: IReleaseTargetStatus[] = [
|
|
483
|
+
journalArg.git,
|
|
484
|
+
...journalArg.npm.registries,
|
|
485
|
+
...(journalArg.schemaVersion === 4
|
|
486
|
+
? [
|
|
487
|
+
journalArg.giteaAssets.release,
|
|
488
|
+
...journalArg.giteaAssets.assets,
|
|
489
|
+
]
|
|
490
|
+
: []),
|
|
491
|
+
...(journalArg.schemaVersion === releaseJournalSchemaVersion
|
|
492
|
+
? [
|
|
493
|
+
journalArg.docker.qualification,
|
|
494
|
+
...journalArg.docker.promotions,
|
|
495
|
+
journalArg.docker.cleanup,
|
|
496
|
+
]
|
|
497
|
+
: []),
|
|
498
|
+
];
|
|
499
|
+
return (
|
|
500
|
+
targets.some((targetArg) => targetArg.state === "accepted") &&
|
|
501
|
+
targets.every((targetArg) =>
|
|
502
|
+
["accepted", "verified", "skipped"].includes(targetArg.state),
|
|
503
|
+
)
|
|
504
|
+
);
|
|
505
|
+
};
|
|
506
|
+
|
|
455
507
|
const immutableJournalIdentity = (journalArg: TReleaseJournal): string =>
|
|
456
508
|
JSON.stringify({
|
|
457
509
|
schemaVersion: journalArg.schemaVersion,
|
|
@@ -494,6 +546,69 @@ const immutableJournalIdentity = (journalArg: TReleaseJournal): string =>
|
|
|
494
546
|
: undefined,
|
|
495
547
|
});
|
|
496
548
|
|
|
549
|
+
const releaseIdentityKeys = ["version", "tag", "mainOid", "tagOid"] as const;
|
|
550
|
+
|
|
551
|
+
const assertVersionFloorRecord = (
|
|
552
|
+
valueArg: unknown,
|
|
553
|
+
versionArg: string,
|
|
554
|
+
): void => {
|
|
555
|
+
if (!isPlainObject(valueArg)) {
|
|
556
|
+
throw new Error("Release journal version floor must be an object.");
|
|
557
|
+
}
|
|
558
|
+
assertExactKeys(
|
|
559
|
+
valueArg,
|
|
560
|
+
["floor", "inferredVersion"],
|
|
561
|
+
"Release journal version floor",
|
|
562
|
+
);
|
|
563
|
+
if (
|
|
564
|
+
typeof valueArg.floor !== "string" ||
|
|
565
|
+
typeof valueArg.inferredVersion !== "string" ||
|
|
566
|
+
!isCanonicalReleaseVersion(valueArg.floor) ||
|
|
567
|
+
!isCanonicalReleaseVersion(valueArg.inferredVersion)
|
|
568
|
+
) {
|
|
569
|
+
throw new Error(
|
|
570
|
+
"Release journal version floor must record canonical x.y.z versions.",
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
if (
|
|
574
|
+
valueArg.floor !== versionArg ||
|
|
575
|
+
compareReleaseVersions(valueArg.inferredVersion, valueArg.floor) >= 0
|
|
576
|
+
) {
|
|
577
|
+
throw new Error(
|
|
578
|
+
"Release journal version floor must equal the release version and exceed the inferred version.",
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
const assertReleaseIdentity = (valueArg: unknown): IReleaseIdentity => {
|
|
584
|
+
if (!isPlainObject(valueArg)) {
|
|
585
|
+
throw new Error("Release journal release identity is missing.");
|
|
586
|
+
}
|
|
587
|
+
const hasVersionFloor = Object.hasOwn(valueArg, "versionFloor");
|
|
588
|
+
assertExactKeys(
|
|
589
|
+
valueArg,
|
|
590
|
+
hasVersionFloor
|
|
591
|
+
? [...releaseIdentityKeys, "versionFloor"]
|
|
592
|
+
: releaseIdentityKeys,
|
|
593
|
+
"Release journal release",
|
|
594
|
+
);
|
|
595
|
+
if (
|
|
596
|
+
typeof valueArg.version !== "string" ||
|
|
597
|
+
normalizeReleaseVersion(valueArg.version) !== valueArg.version ||
|
|
598
|
+
valueArg.tag !== `v${valueArg.version}` ||
|
|
599
|
+
typeof valueArg.mainOid !== "string" ||
|
|
600
|
+
!gitOidRegex.test(valueArg.mainOid) ||
|
|
601
|
+
typeof valueArg.tagOid !== "string" ||
|
|
602
|
+
!gitOidRegex.test(valueArg.tagOid)
|
|
603
|
+
) {
|
|
604
|
+
throw new Error("Release journal Git identity is invalid.");
|
|
605
|
+
}
|
|
606
|
+
if (hasVersionFloor) {
|
|
607
|
+
assertVersionFloorRecord(valueArg.versionFloor, valueArg.version);
|
|
608
|
+
}
|
|
609
|
+
return valueArg as unknown as IReleaseIdentity;
|
|
610
|
+
};
|
|
611
|
+
|
|
497
612
|
const assertReleaseJournalV1 = (valueArg: unknown): IReleaseJournalV1 => {
|
|
498
613
|
if (!isPlainObject(valueArg)) {
|
|
499
614
|
throw new Error("Release journal root must be a JSON object.");
|
|
@@ -523,29 +638,10 @@ const assertReleaseJournalV1 = (valueArg: unknown): IReleaseJournalV1 => {
|
|
|
523
638
|
throw new Error("Release journal header is invalid or unsupported.");
|
|
524
639
|
}
|
|
525
640
|
|
|
526
|
-
|
|
527
|
-
throw new Error("Release journal release identity is missing.");
|
|
528
|
-
}
|
|
529
|
-
assertExactKeys(
|
|
530
|
-
valueArg.release,
|
|
531
|
-
["version", "tag", "mainOid", "tagOid"],
|
|
532
|
-
"Release journal release",
|
|
533
|
-
);
|
|
534
|
-
if (
|
|
535
|
-
typeof valueArg.release.version !== "string" ||
|
|
536
|
-
normalizeReleaseVersion(valueArg.release.version) !==
|
|
537
|
-
valueArg.release.version ||
|
|
538
|
-
valueArg.release.tag !== `v${valueArg.release.version}` ||
|
|
539
|
-
typeof valueArg.release.mainOid !== "string" ||
|
|
540
|
-
!gitOidRegex.test(valueArg.release.mainOid) ||
|
|
541
|
-
typeof valueArg.release.tagOid !== "string" ||
|
|
542
|
-
!gitOidRegex.test(valueArg.release.tagOid)
|
|
543
|
-
) {
|
|
544
|
-
throw new Error("Release journal Git identity is invalid.");
|
|
545
|
-
}
|
|
641
|
+
const release = assertReleaseIdentity(valueArg.release);
|
|
546
642
|
|
|
547
643
|
const artifact = assertArtifact(valueArg.artifact);
|
|
548
|
-
if (artifact && artifact.version !==
|
|
644
|
+
if (artifact && artifact.version !== release.version) {
|
|
549
645
|
throw new Error(
|
|
550
646
|
"Release journal artifact version does not match the release.",
|
|
551
647
|
);
|
|
@@ -717,7 +813,7 @@ export const getReleaseDockerPromotionContext = (
|
|
|
717
813
|
|
|
718
814
|
const assertDockerJournal = (
|
|
719
815
|
valueArg: unknown,
|
|
720
|
-
releaseArg:
|
|
816
|
+
releaseArg: IReleaseIdentity,
|
|
721
817
|
): IReleaseDockerJournal => {
|
|
722
818
|
if (!isPlainObject(valueArg)) {
|
|
723
819
|
throw new Error("Release journal Docker target is missing.");
|
|
@@ -932,28 +1028,9 @@ const assertReleaseJournalV2 = (valueArg: unknown): IReleaseJournalV2 => {
|
|
|
932
1028
|
) {
|
|
933
1029
|
throw new Error("Release journal header is invalid or unsupported.");
|
|
934
1030
|
}
|
|
935
|
-
|
|
936
|
-
throw new Error("Release journal release identity is missing.");
|
|
937
|
-
}
|
|
938
|
-
assertExactKeys(
|
|
939
|
-
valueArg.release,
|
|
940
|
-
["version", "tag", "mainOid", "tagOid"],
|
|
941
|
-
"Release journal release",
|
|
942
|
-
);
|
|
943
|
-
if (
|
|
944
|
-
typeof valueArg.release.version !== "string" ||
|
|
945
|
-
normalizeReleaseVersion(valueArg.release.version) !==
|
|
946
|
-
valueArg.release.version ||
|
|
947
|
-
valueArg.release.tag !== `v${valueArg.release.version}` ||
|
|
948
|
-
typeof valueArg.release.mainOid !== "string" ||
|
|
949
|
-
!gitOidRegex.test(valueArg.release.mainOid) ||
|
|
950
|
-
typeof valueArg.release.tagOid !== "string" ||
|
|
951
|
-
!gitOidRegex.test(valueArg.release.tagOid)
|
|
952
|
-
) {
|
|
953
|
-
throw new Error("Release journal Git identity is invalid.");
|
|
954
|
-
}
|
|
1031
|
+
const release = assertReleaseIdentity(valueArg.release);
|
|
955
1032
|
const artifact = assertArtifact(valueArg.artifact);
|
|
956
|
-
if (artifact && artifact.version !==
|
|
1033
|
+
if (artifact && artifact.version !== release.version) {
|
|
957
1034
|
throw new Error(
|
|
958
1035
|
"Release journal artifact version does not match the release.",
|
|
959
1036
|
);
|
|
@@ -1043,10 +1120,7 @@ const assertReleaseJournalV2 = (valueArg: unknown): IReleaseJournalV2 => {
|
|
|
1043
1120
|
"Release journal npm targets and artifact must exist together.",
|
|
1044
1121
|
);
|
|
1045
1122
|
}
|
|
1046
|
-
const docker = assertDockerJournal(
|
|
1047
|
-
valueArg.docker,
|
|
1048
|
-
valueArg.release as unknown as IReleaseJournalV2["release"],
|
|
1049
|
-
);
|
|
1123
|
+
const docker = assertDockerJournal(valueArg.docker, release);
|
|
1050
1124
|
const activePublishers = [
|
|
1051
1125
|
valueArg.git as unknown as IReleaseTargetStatus,
|
|
1052
1126
|
...(valueArg.npm.registries as unknown as IReleaseTargetStatus[]),
|
|
@@ -1661,11 +1735,15 @@ const assertSchema4AppendOnlyTransition = (
|
|
|
1661
1735
|
if (
|
|
1662
1736
|
after.attempts !== before.attempts ||
|
|
1663
1737
|
(after.state === "pending" && before.state !== "pending") ||
|
|
1738
|
+
(after.state === "accepted" &&
|
|
1739
|
+
!["publishing", "accepted"].includes(before.state)) ||
|
|
1664
1740
|
(before.state === "conflict" && after.state !== "conflict") ||
|
|
1665
1741
|
(before.state === "verified" &&
|
|
1666
1742
|
!["verified", "conflict"].includes(after.state)) ||
|
|
1743
|
+
(before.state === "accepted" &&
|
|
1744
|
+
!["accepted", "verified", "conflict"].includes(after.state)) ||
|
|
1667
1745
|
(before.state === "publishing" &&
|
|
1668
|
-
!["verified", "failed", "conflict"].includes(after.state))
|
|
1746
|
+
!["accepted", "verified", "failed", "conflict"].includes(after.state))
|
|
1669
1747
|
) {
|
|
1670
1748
|
throw new Error(
|
|
1671
1749
|
"Release publication status cannot regress or rewrite attempt history.",
|
|
@@ -84,10 +84,51 @@ export interface INpmArtifactProbeResult {
|
|
|
84
84
|
export interface INpmArtifactProbeOptions {
|
|
85
85
|
fetchImplementation?: typeof fetch;
|
|
86
86
|
timeoutMs?: number;
|
|
87
|
+
/** Maximum probes of one waiting verification. */
|
|
87
88
|
attempts?: number;
|
|
89
|
+
/** First delay between probes; later delays double up to maxDelayMs. */
|
|
88
90
|
delayMs?: number;
|
|
91
|
+
/** Upper bound of the doubling delay. Defaults to delayMs, which disables backoff. */
|
|
92
|
+
maxDelayMs?: number;
|
|
89
93
|
}
|
|
90
94
|
|
|
95
|
+
/** npmjs usually serves a new version within minutes; an hour has happened. */
|
|
96
|
+
export const defaultNpmVerificationWindowMinutes = 15;
|
|
97
|
+
|
|
98
|
+
const probeDelayForAttempt = (
|
|
99
|
+
attemptArg: number,
|
|
100
|
+
delayMsArg: number,
|
|
101
|
+
maxDelayMsArg: number,
|
|
102
|
+
): number => Math.min(delayMsArg * 2 ** attemptArg, maxDelayMsArg);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* npm accepts an upload before it serves it. Translate an availability window
|
|
106
|
+
* into the exact probe schedule that covers it under doubling backoff.
|
|
107
|
+
*/
|
|
108
|
+
export const planNpmAvailabilityProbes = (
|
|
109
|
+
windowMsArg: number,
|
|
110
|
+
delayMsArg: number,
|
|
111
|
+
maxDelayMsArg: number,
|
|
112
|
+
): Required<Pick<INpmArtifactProbeOptions, "attempts" | "delayMs" | "maxDelayMs">> => {
|
|
113
|
+
if (
|
|
114
|
+
!Number.isSafeInteger(windowMsArg) ||
|
|
115
|
+
windowMsArg < 0 ||
|
|
116
|
+
!Number.isSafeInteger(delayMsArg) ||
|
|
117
|
+
delayMsArg <= 0 ||
|
|
118
|
+
!Number.isSafeInteger(maxDelayMsArg) ||
|
|
119
|
+
maxDelayMsArg < delayMsArg
|
|
120
|
+
) {
|
|
121
|
+
throw new Error("npm availability probes require a sane waiting window.");
|
|
122
|
+
}
|
|
123
|
+
let elapsed = 0;
|
|
124
|
+
let attempts = 1;
|
|
125
|
+
while (elapsed < windowMsArg) {
|
|
126
|
+
elapsed += probeDelayForAttempt(attempts - 1, delayMsArg, maxDelayMsArg);
|
|
127
|
+
attempts += 1;
|
|
128
|
+
}
|
|
129
|
+
return { attempts, delayMs: delayMsArg, maxDelayMs: maxDelayMsArg };
|
|
130
|
+
};
|
|
131
|
+
|
|
91
132
|
const readPackageIdentity = async (
|
|
92
133
|
cwdArg: string,
|
|
93
134
|
): Promise<{ packageName: string; version: string }> => {
|
|
@@ -608,6 +649,34 @@ export const publishNpmArtifact = async (
|
|
|
608
649
|
return { exitCode: result.exitCode, output: result.combinedOutput };
|
|
609
650
|
};
|
|
610
651
|
|
|
652
|
+
/**
|
|
653
|
+
* A registry answers an upload of a version it already holds with a conflict.
|
|
654
|
+
* npm, pnpm and registry implementations print that conflict as an HTTP 409,
|
|
655
|
+
* as the `E409` or `EPUBLISHCONFLICT` error code, or as the bare sentence, and
|
|
656
|
+
* frequently only one of them. Each signal on its own therefore proves the
|
|
657
|
+
* conflict.
|
|
658
|
+
*/
|
|
659
|
+
const npmPublishConflictSignals: RegExp[] = [
|
|
660
|
+
/\b409\b/,
|
|
661
|
+
/e409\b/i,
|
|
662
|
+
/epublishconflict\b/i,
|
|
663
|
+
/cannot publish over (?:the )?previously (?:staged|published) versions?/i,
|
|
664
|
+
];
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* A conflict for the journaled version means the registry already holds it,
|
|
668
|
+
* which npm answers both for a staged and for a served version. The upload was
|
|
669
|
+
* therefore accepted, not rejected. Exact bytes still decide verification.
|
|
670
|
+
*/
|
|
671
|
+
export const npmPublishWasAccepted = (resultArg: {
|
|
672
|
+
exitCode: number;
|
|
673
|
+
output: string;
|
|
674
|
+
}): boolean =>
|
|
675
|
+
resultArg.exitCode === 0 ||
|
|
676
|
+
npmPublishConflictSignals.some((signalArg) =>
|
|
677
|
+
signalArg.test(resultArg.output),
|
|
678
|
+
);
|
|
679
|
+
|
|
611
680
|
const getFetch = (optionsArg: INpmArtifactProbeOptions): typeof fetch =>
|
|
612
681
|
optionsArg.fetchImplementation || globalThis.fetch;
|
|
613
682
|
|
|
@@ -831,11 +900,15 @@ export const waitForAnonymousNpmArtifact = async (
|
|
|
831
900
|
): Promise<INpmArtifactProbeResult> => {
|
|
832
901
|
const attempts = optionsArg.attempts ?? 10;
|
|
833
902
|
const delayMs = optionsArg.delayMs ?? 1_000;
|
|
903
|
+
const maxDelayMs = optionsArg.maxDelayMs ?? delayMs;
|
|
834
904
|
if (!Number.isSafeInteger(attempts) || attempts < 1) {
|
|
835
905
|
throw new Error(
|
|
836
906
|
"npm verification attempts must be a positive safe integer.",
|
|
837
907
|
);
|
|
838
908
|
}
|
|
909
|
+
if (maxDelayMs < delayMs) {
|
|
910
|
+
throw new Error("npm verification backoff cannot fall below its delay.");
|
|
911
|
+
}
|
|
839
912
|
let lastResult: INpmArtifactProbeResult = {
|
|
840
913
|
status: "inconclusive",
|
|
841
914
|
code: "network-error",
|
|
@@ -851,7 +924,9 @@ export const waitForAnonymousNpmArtifact = async (
|
|
|
851
924
|
return lastResult;
|
|
852
925
|
}
|
|
853
926
|
if (attempt + 1 < attempts) {
|
|
854
|
-
await plugins.smartdelay.delayFor(
|
|
927
|
+
await plugins.smartdelay.delayFor(
|
|
928
|
+
probeDelayForAttempt(attempt, delayMs, maxDelayMs),
|
|
929
|
+
);
|
|
855
930
|
}
|
|
856
931
|
}
|
|
857
932
|
return lastResult;
|
|
@@ -1005,6 +1005,120 @@ export async function revalidatePreparedReleaseBranch(
|
|
|
1005
1005
|
}
|
|
1006
1006
|
}
|
|
1007
1007
|
|
|
1008
|
+
const verifyCommitContained = async (
|
|
1009
|
+
smartshellArg: TSmartshell,
|
|
1010
|
+
cwdArg: string,
|
|
1011
|
+
ancestorOidArg: string,
|
|
1012
|
+
descendantOidArg: string,
|
|
1013
|
+
messageArg: string,
|
|
1014
|
+
): Promise<void> => {
|
|
1015
|
+
if (ancestorOidArg === descendantOidArg) return;
|
|
1016
|
+
const result = await runGit(
|
|
1017
|
+
smartshellArg,
|
|
1018
|
+
cwdArg,
|
|
1019
|
+
["merge-base", "--is-ancestor", ancestorOidArg, descendantOidArg],
|
|
1020
|
+
true,
|
|
1021
|
+
);
|
|
1022
|
+
if (result.exitCode !== 0) throw new Error(messageArg);
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* Containment against the remote tip is only provable with that commit in the
|
|
1027
|
+
* local object store, so a tip this clone has never seen is fetched: by branch
|
|
1028
|
+
* ref, which every server serves, and then by object id for a tip that moved
|
|
1029
|
+
* while it was being read. A tip that stays unavailable leaves remote
|
|
1030
|
+
* containment unproven, which refuses verification instead of skipping it.
|
|
1031
|
+
*/
|
|
1032
|
+
const ensureRemoteCommitObject = async (
|
|
1033
|
+
smartshellArg: TSmartshell,
|
|
1034
|
+
cwdArg: string,
|
|
1035
|
+
pushUrlArg: string,
|
|
1036
|
+
remoteMainOidArg: string,
|
|
1037
|
+
): Promise<void> => {
|
|
1038
|
+
if (await hasCommitObject(smartshellArg, cwdArg, remoteMainOidArg, true)) {
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
for (const fetchTargetArg of [mainBranchRef, remoteMainOidArg]) {
|
|
1042
|
+
await runGit(smartshellArg, cwdArg, [
|
|
1043
|
+
"fetch",
|
|
1044
|
+
"--no-tags",
|
|
1045
|
+
"--no-recurse-submodules",
|
|
1046
|
+
"--no-write-fetch-head",
|
|
1047
|
+
pushUrlArg,
|
|
1048
|
+
fetchTargetArg,
|
|
1049
|
+
]);
|
|
1050
|
+
if (await hasCommitObject(smartshellArg, cwdArg, remoteMainOidArg, true)) {
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
throw new Error(
|
|
1055
|
+
`Remote main ${remoteMainOidArg} could not be fetched; remote containment unverified.`,
|
|
1056
|
+
);
|
|
1057
|
+
};
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* A verification-only resume publishes nothing, so main may already carry
|
|
1061
|
+
* later commits. The journaled release commit only has to remain part of that
|
|
1062
|
+
* history, locally and on the unchanged remote.
|
|
1063
|
+
*/
|
|
1064
|
+
export async function verifyReleaseHistoryRetained(
|
|
1065
|
+
smartshellArg: TSmartshell,
|
|
1066
|
+
contextArg: IReleaseBranchContext,
|
|
1067
|
+
releaseCommitOidArg: string,
|
|
1068
|
+
): Promise<void> {
|
|
1069
|
+
await verifyNoHistoryOverrides(smartshellArg, contextArg.sourceCwd, true);
|
|
1070
|
+
const localMainOid = await resolveCommit(
|
|
1071
|
+
smartshellArg,
|
|
1072
|
+
contextArg.sourceCwd,
|
|
1073
|
+
mainBranchRef,
|
|
1074
|
+
"A local main branch is required to resume a release.",
|
|
1075
|
+
true,
|
|
1076
|
+
);
|
|
1077
|
+
await verifyCommitContained(
|
|
1078
|
+
smartshellArg,
|
|
1079
|
+
contextArg.sourceCwd,
|
|
1080
|
+
releaseCommitOidArg,
|
|
1081
|
+
localMainOid,
|
|
1082
|
+
"Local main no longer contains the journaled release commit. Restore that history before resuming.",
|
|
1083
|
+
);
|
|
1084
|
+
if (!contextArg.pushUrl) return;
|
|
1085
|
+
const currentPushUrl = await resolvePushUrl(
|
|
1086
|
+
smartshellArg,
|
|
1087
|
+
contextArg.sourceCwd,
|
|
1088
|
+
contextArg.gitRemote,
|
|
1089
|
+
true,
|
|
1090
|
+
);
|
|
1091
|
+
if (currentPushUrl !== contextArg.pushUrl) {
|
|
1092
|
+
throw new Error(
|
|
1093
|
+
"The Git push destination changed before release verification. Restart after reviewing the remote configuration.",
|
|
1094
|
+
);
|
|
1095
|
+
}
|
|
1096
|
+
const remoteMainOid = await resolveRemoteMainOid(
|
|
1097
|
+
smartshellArg,
|
|
1098
|
+
contextArg.sourceCwd,
|
|
1099
|
+
contextArg.pushUrl,
|
|
1100
|
+
true,
|
|
1101
|
+
);
|
|
1102
|
+
if (isAbsentGitOid(remoteMainOid)) {
|
|
1103
|
+
throw new Error(
|
|
1104
|
+
"Remote main no longer exists, so the journaled release history cannot be confirmed.",
|
|
1105
|
+
);
|
|
1106
|
+
}
|
|
1107
|
+
await ensureRemoteCommitObject(
|
|
1108
|
+
smartshellArg,
|
|
1109
|
+
contextArg.sourceCwd,
|
|
1110
|
+
contextArg.pushUrl,
|
|
1111
|
+
remoteMainOid,
|
|
1112
|
+
);
|
|
1113
|
+
await verifyCommitContained(
|
|
1114
|
+
smartshellArg,
|
|
1115
|
+
contextArg.sourceCwd,
|
|
1116
|
+
releaseCommitOidArg,
|
|
1117
|
+
remoteMainOid,
|
|
1118
|
+
"Remote main no longer contains the journaled release commit. Inspect the remote before resuming.",
|
|
1119
|
+
);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1008
1122
|
export async function revalidateReleasePublicationState(
|
|
1009
1123
|
smartshellArg: TSmartshell,
|
|
1010
1124
|
contextArg: IReleaseBranchContext,
|