@git.zone/cli 7.2.2 → 7.2.4
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/assets/templates/asset_tspack_release_gitea/scripts/gitzone-sealed-release.mjs +44 -9
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/mod_release/classes.releasejournal.js +6 -4
- package/dist_ts/mod_release/helpers.commandfailure.d.ts +44 -0
- package/dist_ts/mod_release/helpers.commandfailure.js +177 -0
- package/dist_ts/mod_release/helpers.npmartifact.d.ts +1 -0
- package/dist_ts/mod_release/helpers.npmartifact.js +43 -9
- package/dist_ts/mod_release/helpers.releasebranch.js +46 -16
- package/dist_ts/mod_release/helpers.releasepreparation.js +12 -4
- package/dist_ts/mod_release/helpers.releasepublication.js +24 -7
- package/dist_ts/mod_release/helpers.tsdockerprotocol.js +25 -11
- package/dist_ts/mod_release/index.js +30 -8
- package/package.json +1 -1
- package/readme.md +24 -0
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/mod_release/classes.releasejournal.ts +11 -5
- package/ts/mod_release/helpers.commandfailure.ts +258 -0
- package/ts/mod_release/helpers.npmartifact.ts +68 -11
- package/ts/mod_release/helpers.releasebranch.ts +72 -17
- package/ts/mod_release/helpers.releasepreparation.ts +29 -3
- package/ts/mod_release/helpers.releasepublication.ts +51 -6
- package/ts/mod_release/helpers.tsdockerprotocol.ts +35 -10
- package/ts/mod_release/index.ts +55 -9
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import * as plugins from "./mod.plugins.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Identifies a failed release command for its diagnostic. Git and pnpm
|
|
5
|
+
* commands are named without their arguments, because arguments can hold
|
|
6
|
+
* destinations and file paths the message has no use for.
|
|
7
|
+
*/
|
|
8
|
+
export interface IReleaseCommandFailureContext {
|
|
9
|
+
/**
|
|
10
|
+
* Command name, for example `git ls-remote`, or a configured project
|
|
11
|
+
* command. It passes the same redaction and bounding as output.
|
|
12
|
+
*/
|
|
13
|
+
command: string;
|
|
14
|
+
/** Timeout the command ran under, named when Smartshell's timeout fired. */
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Output whose tail the diagnostic quotes. Git reports errors on stderr;
|
|
18
|
+
* pnpm and project commands report many of theirs on stdout.
|
|
19
|
+
*/
|
|
20
|
+
output?: "stderr" | "combined";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Longest output tail a diagnostic quotes, in characters. */
|
|
24
|
+
export const releaseCommandOutputTailLength = 500;
|
|
25
|
+
|
|
26
|
+
const ansiEscapePattern =
|
|
27
|
+
/\u001b(?:\[[0-?]*[ -/]*[@-~]|\][^\u0007\u001b]*(?:\u0007|\u001b\\)|[@-Z\\-_])/g;
|
|
28
|
+
|
|
29
|
+
/** A credential form in command output and the replacement that hides it. */
|
|
30
|
+
interface ICredentialPattern {
|
|
31
|
+
pattern: RegExp;
|
|
32
|
+
/** Keeps the credential's name and replaces its value with `***`. */
|
|
33
|
+
replacement: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Name endings that mark a credential setting: NPM_TOKEN, DEPLOY_SECRET,
|
|
38
|
+
* MINIO_SECRET_KEY, secretKey, DB_PASSWORD, OPENAI_API_KEY,
|
|
39
|
+
* AWS_SECRET_ACCESS_KEY, GIT_CREDENTIALS.
|
|
40
|
+
*/
|
|
41
|
+
const credentialNameEndings = String.raw`token|secret(?:_?key)?|passw(?:or)?d|api_?key|access_?key|private_?key|credentials?`;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A name of `charsArg` characters that ends in one of `endingsArg`, or in
|
|
45
|
+
* PASS or PWD. PASS counts only as the whole name or after a _ or -, so BYPASS
|
|
46
|
+
* is no credential; PWD counts only after one, so the shell's PWD and OLDPWD,
|
|
47
|
+
* which hold directories, are none either.
|
|
48
|
+
*/
|
|
49
|
+
const credentialName = (charsArg: string, endingsArg: string): string =>
|
|
50
|
+
String.raw`(?:${charsArg}*(?:${endingsArg})|(?:${charsArg}*[_-])?pass|${charsArg}*[_-]pwd)`;
|
|
51
|
+
|
|
52
|
+
/** An environment variable or option name: NPM_TOKEN, DB_PASS, --token. */
|
|
53
|
+
const settingName = credentialName(String.raw`\w`, credentialNameEndings);
|
|
54
|
+
|
|
55
|
+
/** An object key: "_authToken", secretKey, 'PRIVATE-TOKEN', Docker's "auth". */
|
|
56
|
+
const credentialKeyEndings = String.raw`${credentialNameEndings}|auth(?:orization)?`;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A setting value: a quoted string, or the text up to the next whitespace. A
|
|
60
|
+
* quote the line never closes hides the value to the end of the line.
|
|
61
|
+
*/
|
|
62
|
+
const settingValue = String.raw`(?:"[^"\n]*"?|'[^'\n]*'?|[^\s"']\S*)`;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Credential forms that failing Git, pnpm and project commands can print, in
|
|
66
|
+
* the order they are redacted. Each pattern keeps what names the credential
|
|
67
|
+
* and replaces only the value, so a message still says which setting leaked
|
|
68
|
+
* into the output. Values stop at a line end, so a pattern never reaches into
|
|
69
|
+
* the next line of output.
|
|
70
|
+
*
|
|
71
|
+
* Redaction runs over the whole output of a command, which can be megabytes,
|
|
72
|
+
* so every pattern runs in time linear in its input: a run a pattern scans
|
|
73
|
+
* before it can fail either has a length bound or starts only where the run
|
|
74
|
+
* itself starts, so no position is rescanned from each of the positions
|
|
75
|
+
* before it.
|
|
76
|
+
*/
|
|
77
|
+
const credentialPatterns: ReadonlyArray<ICredentialPattern> = [
|
|
78
|
+
// PEM private key blocks, whole, across lines. A block cut off by the end
|
|
79
|
+
// of the output is hidden up to that end. The key type before and after
|
|
80
|
+
// PRIVATE KEY ("OPENSSH", "ENCRYPTED", " BLOCK") is bounded.
|
|
81
|
+
{
|
|
82
|
+
pattern:
|
|
83
|
+
/(-----BEGIN [A-Z0-9 ]{0,40}PRIVATE KEY[A-Z ]{0,20}-----)[\s\S]*?(-----END [A-Z0-9 ]{0,40}PRIVATE KEY[A-Z ]{0,20}-----|$)/g,
|
|
84
|
+
replacement: "$1***$2",
|
|
85
|
+
},
|
|
86
|
+
// URL userinfo: https://user:token@host, ssh://git@host. The scheme is at
|
|
87
|
+
// most 32 characters long.
|
|
88
|
+
{
|
|
89
|
+
pattern: /\b([A-Za-z][A-Za-z0-9+.-]{0,31}:\/\/)[^\s/?#]*@/g,
|
|
90
|
+
replacement: "$1***@",
|
|
91
|
+
},
|
|
92
|
+
// JSON string values under a credential key: "_authToken": "…",
|
|
93
|
+
// "password": "…", "secretKey": "…", "pass": "…", "token": "…", Docker's
|
|
94
|
+
// "auth": "…". A value the line never closes is hidden to the line end.
|
|
95
|
+
{
|
|
96
|
+
pattern: new RegExp(
|
|
97
|
+
String.raw`("${credentialName(String.raw`[^"\n]`, credentialKeyEndings)}"[ \t]*:[ \t]*")(?:[^"\\\n]|\\.)*("?)`,
|
|
98
|
+
"gi",
|
|
99
|
+
),
|
|
100
|
+
replacement: "$1***$2",
|
|
101
|
+
},
|
|
102
|
+
// Quoted values under a credential key in JavaScript object and YAML
|
|
103
|
+
// printouts: password: '…', secretKey: "…", token: '…', apiKey: '…',
|
|
104
|
+
// 'PRIVATE-TOKEN': '…', authorization: 'Bearer …'. \x60 is the backtick
|
|
105
|
+
// Node prints around a string that holds both quote marks. Only a quoted
|
|
106
|
+
// value is hidden, so "Unexpected token : in JSON" keeps its text.
|
|
107
|
+
{
|
|
108
|
+
pattern: new RegExp(
|
|
109
|
+
String.raw`((?<![\w-])${credentialName(String.raw`[\w-]`, credentialKeyEndings)}'?[ \t]*:[ \t]*)(?:'(?:[^'\\\n]|\\.)*'?|"(?:[^"\\\n]|\\.)*"?|\x60(?:[^\x60\\\n]|\\.)*\x60?)`,
|
|
110
|
+
"gi",
|
|
111
|
+
),
|
|
112
|
+
replacement: "$1***",
|
|
113
|
+
},
|
|
114
|
+
// HTTP headers: Authorization and Proxy-Authorization, with or without a
|
|
115
|
+
// scheme, and GitLab's PRIVATE-TOKEN, JOB-TOKEN and Deploy-Token.
|
|
116
|
+
{
|
|
117
|
+
pattern:
|
|
118
|
+
/(\b(?:authorization|(?:private|job|deploy)-token)[ \t]*:[ \t]*(?:(?:bearer|basic|token)[ \t]+)?)\S+/gi,
|
|
119
|
+
replacement: "$1***",
|
|
120
|
+
},
|
|
121
|
+
// npm credential settings in .npmrc lines and npm_config_ variables:
|
|
122
|
+
// //registry/:_authToken=…, _auth = …, npm_config__password=….
|
|
123
|
+
{
|
|
124
|
+
pattern: new RegExp(
|
|
125
|
+
String.raw`(_(?:authToken|auth|password)[ \t]*[=:][ \t]*)${settingValue}`,
|
|
126
|
+
"gi",
|
|
127
|
+
),
|
|
128
|
+
replacement: "$1***",
|
|
129
|
+
},
|
|
130
|
+
// Query parameters: ?token=, &access_token=, &private_token=, &sig=,
|
|
131
|
+
// X-Amz-Signature=, X-Amz-Credential=, ?key=.
|
|
132
|
+
{
|
|
133
|
+
pattern:
|
|
134
|
+
/([?&][\w.-]*(?:token|secret|passw(?:or)?d|sig|signature|credential|key|auth)=)[^\s&#"'<>]+/gi,
|
|
135
|
+
replacement: "$1***",
|
|
136
|
+
},
|
|
137
|
+
// Environment variables and options whose name ends in a credential word:
|
|
138
|
+
// NPM_TOKEN=, NODE_AUTH_TOKEN=, GITHUB_TOKEN=, GITEA_TOKEN=, *_SECRET=,
|
|
139
|
+
// SECRET_KEY=, *_PASSWORD=, DB_PASS=, MYSQL_PWD=, *_API_KEY=,
|
|
140
|
+
// AWS_SECRET_ACCESS_KEY=, --token=. A value without quotes is hidden to the
|
|
141
|
+
// next whitespace, & included. BYPASS=, PWD= and OLDPWD= keep their
|
|
142
|
+
// values, as credentialName describes. Query parameters, names that follow a ? or & (looked up at
|
|
143
|
+
// most 64 characters back), are left to the pattern above, which keeps the
|
|
144
|
+
// #fragment and the parameters after their value.
|
|
145
|
+
{
|
|
146
|
+
pattern: new RegExp(
|
|
147
|
+
String.raw`(\b(?=${settingName}[ \t]*=)(?<![?&][\w.-]{0,63})${settingName}[ \t]*=[ \t]*)${settingValue}`,
|
|
148
|
+
"gi",
|
|
149
|
+
),
|
|
150
|
+
replacement: "$1***",
|
|
151
|
+
},
|
|
152
|
+
// Credential options followed by their value: --token …, --password …,
|
|
153
|
+
// --secret …. Only these names, so --password-stdin and --token-file keep
|
|
154
|
+
// the argument after them.
|
|
155
|
+
{
|
|
156
|
+
pattern: new RegExp(
|
|
157
|
+
String.raw`((?<![\w-])--(?:token|password|secret)[ \t]+)${settingValue}`,
|
|
158
|
+
"gi",
|
|
159
|
+
),
|
|
160
|
+
replacement: "$1***",
|
|
161
|
+
},
|
|
162
|
+
// npm access tokens.
|
|
163
|
+
{ pattern: /\bnpm_[A-Za-z0-9]{36}\b/g, replacement: "***" },
|
|
164
|
+
// GitHub classic personal, OAuth, user, server and refresh tokens, and
|
|
165
|
+
// fine-grained personal access tokens.
|
|
166
|
+
{
|
|
167
|
+
pattern: /\b(?:gh[oprsu]_[A-Za-z0-9]{36,}|github_pat_[A-Za-z0-9_]{22,})\b/g,
|
|
168
|
+
replacement: "***",
|
|
169
|
+
},
|
|
170
|
+
// GitLab personal access tokens.
|
|
171
|
+
{ pattern: /\bglpat-[A-Za-z0-9_-]{20,}/g, replacement: "***" },
|
|
172
|
+
// Slack bot, user, app and refresh tokens.
|
|
173
|
+
{ pattern: /\bxox[abpr]-[A-Za-z0-9-]{10,}/g, replacement: "***" },
|
|
174
|
+
// AWS access key IDs, long-term and temporary.
|
|
175
|
+
{ pattern: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g, replacement: "***" },
|
|
176
|
+
// JSON Web Tokens: three base64url parts, the first a JSON object. A token
|
|
177
|
+
// starts where a run of base64url characters starts.
|
|
178
|
+
{
|
|
179
|
+
pattern:
|
|
180
|
+
/(?<![A-Za-z0-9_-])eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]*/g,
|
|
181
|
+
replacement: "***",
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Removes credentials from command output: private keys, URL userinfo,
|
|
187
|
+
* authorization headers, credential settings in JSON, npm configuration,
|
|
188
|
+
* query strings and environment variables, and tokens whose shape identifies
|
|
189
|
+
* them, as listed in {@link credentialPatterns}. Git and pnpm echo remote and
|
|
190
|
+
* registry URLs in their errors, and project commands can print anything.
|
|
191
|
+
*/
|
|
192
|
+
export const redactCommandOutput = (textArg: string): string =>
|
|
193
|
+
credentialPatterns.reduce(
|
|
194
|
+
(textSoFar, { pattern, replacement }) =>
|
|
195
|
+
textSoFar.replace(pattern, replacement),
|
|
196
|
+
textArg,
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Reduces command output to one redacted line of at most
|
|
201
|
+
* {@link releaseCommandOutputTailLength} characters, keeping its end, where
|
|
202
|
+
* the error is. Redaction runs before truncation, so a cut can never expose
|
|
203
|
+
* part of a credential.
|
|
204
|
+
*/
|
|
205
|
+
export const summarizeCommandOutput = (outputArg: string): string => {
|
|
206
|
+
const line = redactCommandOutput(outputArg.replace(ansiEscapePattern, ""))
|
|
207
|
+
.split(/\r\n|\r|\n/)
|
|
208
|
+
.map((lineArg) =>
|
|
209
|
+
lineArg
|
|
210
|
+
.replace(/[\u0000-\u001f\u007f]+/g, " ")
|
|
211
|
+
.replace(/\s+/g, " ")
|
|
212
|
+
.trim(),
|
|
213
|
+
)
|
|
214
|
+
.filter(Boolean)
|
|
215
|
+
.join(" | ");
|
|
216
|
+
return line.length > releaseCommandOutputTailLength
|
|
217
|
+
? `...${line.slice(line.length - releaseCommandOutputTailLength)}`
|
|
218
|
+
: line;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const formatDuration = (msArg: number): string =>
|
|
222
|
+
`${Number((msArg / 1000).toFixed(3))} s`;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* States how a command failed: its timeout, signal or exit code, followed by
|
|
226
|
+
* the tail of its output.
|
|
227
|
+
*/
|
|
228
|
+
export const describeCommandFailure = (
|
|
229
|
+
resultArg: plugins.smartshell.IExecResult,
|
|
230
|
+
contextArg: IReleaseCommandFailureContext,
|
|
231
|
+
): string => {
|
|
232
|
+
const termination = resultArg.signal
|
|
233
|
+
? `was terminated by ${resultArg.signal}`
|
|
234
|
+
: `exited with code ${resultArg.exitCode}`;
|
|
235
|
+
const outcome = resultArg.timedOut
|
|
236
|
+
? `timed out${
|
|
237
|
+
contextArg.timeoutMs === undefined
|
|
238
|
+
? ""
|
|
239
|
+
: ` after ${formatDuration(contextArg.timeoutMs)}`
|
|
240
|
+
} and ${termination}`
|
|
241
|
+
: termination;
|
|
242
|
+
const outputName = contextArg.output === "combined" ? "output" : "stderr";
|
|
243
|
+
const tail = summarizeCommandOutput(
|
|
244
|
+
contextArg.output === "combined"
|
|
245
|
+
? resultArg.combinedOutput
|
|
246
|
+
: resultArg.stderr,
|
|
247
|
+
);
|
|
248
|
+
return `\`${summarizeCommandOutput(contextArg.command)}\` ${outcome}${
|
|
249
|
+
tail ? `; ${outputName}: ${tail}` : ""
|
|
250
|
+
}`;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
/** Appends the failure detail of a command to the sentence that names its step. */
|
|
254
|
+
export const formatCommandFailure = (
|
|
255
|
+
messageArg: string,
|
|
256
|
+
resultArg: plugins.smartshell.IExecResult,
|
|
257
|
+
contextArg: IReleaseCommandFailureContext,
|
|
258
|
+
): string => `${messageArg} ${describeCommandFailure(resultArg, contextArg)}`;
|
|
@@ -4,6 +4,10 @@ import {
|
|
|
4
4
|
type IReleaseArtifact,
|
|
5
5
|
} from "./classes.releasejournal.js";
|
|
6
6
|
import { assertCredentialFreeGitPushDestination } from "./helpers.releasebranch.js";
|
|
7
|
+
import {
|
|
8
|
+
describeCommandFailure,
|
|
9
|
+
formatCommandFailure,
|
|
10
|
+
} from "./helpers.commandfailure.js";
|
|
7
11
|
import {
|
|
8
12
|
compareReleaseVersions,
|
|
9
13
|
isCanonicalReleaseVersion,
|
|
@@ -201,7 +205,13 @@ const readPnpmJson = async (
|
|
|
201
205
|
},
|
|
202
206
|
);
|
|
203
207
|
if (result.exitCode !== 0 || result.timedOut) {
|
|
204
|
-
throw new Error(
|
|
208
|
+
throw new Error(
|
|
209
|
+
formatCommandFailure(`Unable to inspect pnpm ${labelArg}.`, result, {
|
|
210
|
+
command: `pnpm ${argsArg[0]}`,
|
|
211
|
+
timeoutMs: capabilityCommandTimeoutMs,
|
|
212
|
+
output: "combined",
|
|
213
|
+
}),
|
|
214
|
+
);
|
|
205
215
|
}
|
|
206
216
|
if (result.stdout.trim() === "undefined") return undefined;
|
|
207
217
|
try {
|
|
@@ -317,11 +327,20 @@ export const assertPnpmReleaseCapability = async (
|
|
|
317
327
|
timeoutKillGraceMs: 5_000,
|
|
318
328
|
});
|
|
319
329
|
const version = versionResult.stdout.trim();
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
330
|
+
if (versionResult.exitCode !== 0 || versionResult.timedOut) {
|
|
331
|
+
throw new Error(
|
|
332
|
+
formatCommandFailure(
|
|
333
|
+
"Exact release packaging requires a canonical stable pnpm version.",
|
|
334
|
+
versionResult,
|
|
335
|
+
{
|
|
336
|
+
command: "pnpm --version",
|
|
337
|
+
timeoutMs: capabilityCommandTimeoutMs,
|
|
338
|
+
output: "combined",
|
|
339
|
+
},
|
|
340
|
+
),
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
if (!stablePnpmVersion.test(version)) {
|
|
325
344
|
throw new Error(
|
|
326
345
|
"Exact release packaging requires a canonical stable pnpm version.",
|
|
327
346
|
);
|
|
@@ -341,7 +360,15 @@ export const assertPnpmReleaseCapability = async (
|
|
|
341
360
|
);
|
|
342
361
|
if (packHelp.exitCode !== 0 || packHelp.timedOut) {
|
|
343
362
|
throw new Error(
|
|
344
|
-
|
|
363
|
+
formatCommandFailure(
|
|
364
|
+
"Unable to inspect the selected pnpm pack capabilities. Exact release commands require standalone pnpm with support; Corepack launchers are unsupported.",
|
|
365
|
+
packHelp,
|
|
366
|
+
{
|
|
367
|
+
command: "pnpm pack --help",
|
|
368
|
+
timeoutMs: capabilityCommandTimeoutMs,
|
|
369
|
+
output: "combined",
|
|
370
|
+
},
|
|
371
|
+
),
|
|
345
372
|
);
|
|
346
373
|
}
|
|
347
374
|
requireHelpFragments(packHelp.combinedOutput, "pack");
|
|
@@ -357,7 +384,17 @@ export const assertPnpmReleaseCapability = async (
|
|
|
357
384
|
},
|
|
358
385
|
);
|
|
359
386
|
if (publishHelp.exitCode !== 0 || publishHelp.timedOut) {
|
|
360
|
-
throw new Error(
|
|
387
|
+
throw new Error(
|
|
388
|
+
formatCommandFailure(
|
|
389
|
+
"Unable to inspect pnpm publish capabilities.",
|
|
390
|
+
publishHelp,
|
|
391
|
+
{
|
|
392
|
+
command: "pnpm publish --help",
|
|
393
|
+
timeoutMs: capabilityCommandTimeoutMs,
|
|
394
|
+
output: "combined",
|
|
395
|
+
},
|
|
396
|
+
),
|
|
397
|
+
);
|
|
361
398
|
}
|
|
362
399
|
requireHelpFragments(publishHelp.combinedOutput, "publish");
|
|
363
400
|
return capability;
|
|
@@ -620,7 +657,15 @@ export const packNpmArtifact = async (
|
|
|
620
657
|
);
|
|
621
658
|
if (result.exitCode !== 0) {
|
|
622
659
|
throw new Error(
|
|
623
|
-
|
|
660
|
+
formatCommandFailure(
|
|
661
|
+
"pnpm pack failed while creating the exact release artifact.",
|
|
662
|
+
result,
|
|
663
|
+
{
|
|
664
|
+
command: "pnpm pack",
|
|
665
|
+
timeoutMs: packCommandTimeoutMs,
|
|
666
|
+
output: "combined",
|
|
667
|
+
},
|
|
668
|
+
),
|
|
624
669
|
);
|
|
625
670
|
}
|
|
626
671
|
let report: unknown;
|
|
@@ -707,7 +752,7 @@ export const publishNpmArtifact = async (
|
|
|
707
752
|
artifactPathArg: string,
|
|
708
753
|
registryArg: string,
|
|
709
754
|
capabilityArg: IPnpmReleaseCapability | undefined,
|
|
710
|
-
): Promise<{ exitCode: number; output: string }> => {
|
|
755
|
+
): Promise<{ exitCode: number; output: string; failure?: string }> => {
|
|
711
756
|
const result = await smartshellArg.execSpawn(
|
|
712
757
|
"pnpm",
|
|
713
758
|
buildQualifiedPnpmArgs(
|
|
@@ -720,7 +765,19 @@ export const publishNpmArtifact = async (
|
|
|
720
765
|
timeoutKillGraceMs: 5_000,
|
|
721
766
|
},
|
|
722
767
|
);
|
|
723
|
-
return {
|
|
768
|
+
return {
|
|
769
|
+
exitCode: result.exitCode,
|
|
770
|
+
output: result.combinedOutput,
|
|
771
|
+
...(result.exitCode === 0
|
|
772
|
+
? {}
|
|
773
|
+
: {
|
|
774
|
+
failure: describeCommandFailure(result, {
|
|
775
|
+
command: "pnpm publish",
|
|
776
|
+
timeoutMs: publishCommandTimeoutMs,
|
|
777
|
+
output: "combined",
|
|
778
|
+
}),
|
|
779
|
+
}),
|
|
780
|
+
};
|
|
724
781
|
};
|
|
725
782
|
|
|
726
783
|
/**
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import * as plugins from "./mod.plugins.js";
|
|
2
|
+
import {
|
|
3
|
+
formatCommandFailure,
|
|
4
|
+
type IReleaseCommandFailureContext,
|
|
5
|
+
} from "./helpers.commandfailure.js";
|
|
2
6
|
|
|
3
7
|
const mainBranch = "main";
|
|
4
8
|
const mainBranchRef = `refs/heads/${mainBranch}`;
|
|
@@ -165,27 +169,50 @@ export function parseGitWorktreePorcelain(outputArg: string): IGitWorktree[] {
|
|
|
165
169
|
return worktrees;
|
|
166
170
|
}
|
|
167
171
|
|
|
172
|
+
interface IReleaseGitResult extends plugins.smartshell.IExecResult {
|
|
173
|
+
failureContext: IReleaseCommandFailureContext;
|
|
174
|
+
}
|
|
175
|
+
|
|
168
176
|
const runGit = async (
|
|
169
177
|
smartshellArg: TSmartshell,
|
|
170
178
|
cwdArg: string,
|
|
171
179
|
argsArg: string[],
|
|
172
180
|
readOnlyArg = false,
|
|
173
|
-
) =>
|
|
174
|
-
|
|
181
|
+
): Promise<IReleaseGitResult> => {
|
|
182
|
+
const timeoutMs =
|
|
183
|
+
argsArg[0] === "fetch" || argsArg[0] === "push" ? 5 * 60_000 : 60_000;
|
|
184
|
+
const result = await smartshellArg.execSpawn("git", argsArg, {
|
|
175
185
|
cwd: cwdArg,
|
|
176
186
|
env: readOnlyArg ? readOnlyGitEnv : releaseGitEnv,
|
|
177
187
|
silent: true,
|
|
178
|
-
timeout:
|
|
179
|
-
argsArg[0] === "fetch" || argsArg[0] === "push" ? 5 * 60_000 : 60_000,
|
|
188
|
+
timeout: timeoutMs,
|
|
180
189
|
timeoutKillGraceMs: 5_000,
|
|
181
190
|
});
|
|
191
|
+
return {
|
|
192
|
+
...result,
|
|
193
|
+
failureContext: { command: `git ${argsArg[0]}`, timeoutMs },
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/** Git's own failure, appended to the sentence that names the release step. */
|
|
198
|
+
const gitFailure = (
|
|
199
|
+
resultArg: IReleaseGitResult,
|
|
200
|
+
messageArg: string,
|
|
201
|
+
): Error =>
|
|
202
|
+
new Error(
|
|
203
|
+
formatCommandFailure(messageArg, resultArg, resultArg.failureContext),
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
/** Exit status 1 answers Git's predicate commands; it is no failure there. */
|
|
207
|
+
const isGitNegativeAnswer = (resultArg: IReleaseGitResult): boolean =>
|
|
208
|
+
resultArg.exitCode === 1 && !resultArg.timedOut && !resultArg.signal;
|
|
182
209
|
|
|
183
210
|
const requireGitSuccess = (
|
|
184
|
-
resultArg:
|
|
211
|
+
resultArg: IReleaseGitResult,
|
|
185
212
|
messageArg: string,
|
|
186
|
-
):
|
|
213
|
+
): IReleaseGitResult => {
|
|
187
214
|
if (resultArg.exitCode !== 0) {
|
|
188
|
-
throw
|
|
215
|
+
throw gitFailure(resultArg, messageArg);
|
|
189
216
|
}
|
|
190
217
|
return resultArg;
|
|
191
218
|
};
|
|
@@ -201,6 +228,12 @@ const resolveSymbolicBranch = async (
|
|
|
201
228
|
["symbolic-ref", "--quiet", "HEAD"],
|
|
202
229
|
readOnlyArg,
|
|
203
230
|
);
|
|
231
|
+
if (result.exitCode !== 0 && !isGitNegativeAnswer(result)) {
|
|
232
|
+
throw gitFailure(
|
|
233
|
+
result,
|
|
234
|
+
"Unable to resolve the checked-out release branch.",
|
|
235
|
+
);
|
|
236
|
+
}
|
|
204
237
|
const ref = result.stdout.trim();
|
|
205
238
|
if (result.exitCode !== 0 || !ref.startsWith("refs/heads/")) {
|
|
206
239
|
throw new Error(
|
|
@@ -549,6 +582,12 @@ const verifyLinearAncestry = async (
|
|
|
549
582
|
"Release merge ancestry cannot be verified in this shallow clone. Fetch complete main and feature history, then retry.",
|
|
550
583
|
);
|
|
551
584
|
}
|
|
585
|
+
if (!isGitNegativeAnswer(ancestryResult)) {
|
|
586
|
+
throw gitFailure(
|
|
587
|
+
ancestryResult,
|
|
588
|
+
"Unable to verify that the release branch is rebased onto main.",
|
|
589
|
+
);
|
|
590
|
+
}
|
|
552
591
|
throw new Error(
|
|
553
592
|
"The release branch is not cleanly rebased onto current main. Rebase it onto main, resolve conflicts, and retry.",
|
|
554
593
|
);
|
|
@@ -1019,7 +1058,9 @@ const verifyCommitContained = async (
|
|
|
1019
1058
|
["merge-base", "--is-ancestor", ancestorOidArg, descendantOidArg],
|
|
1020
1059
|
true,
|
|
1021
1060
|
);
|
|
1022
|
-
if (result.exitCode
|
|
1061
|
+
if (result.exitCode === 0) return;
|
|
1062
|
+
if (isGitNegativeAnswer(result)) throw new Error(messageArg);
|
|
1063
|
+
throw gitFailure(result, "Unable to verify release commit containment.");
|
|
1023
1064
|
};
|
|
1024
1065
|
|
|
1025
1066
|
/**
|
|
@@ -1038,8 +1079,9 @@ const ensureRemoteCommitObject = async (
|
|
|
1038
1079
|
if (await hasCommitObject(smartshellArg, cwdArg, remoteMainOidArg, true)) {
|
|
1039
1080
|
return;
|
|
1040
1081
|
}
|
|
1082
|
+
let lastFetchFailure: IReleaseGitResult | undefined;
|
|
1041
1083
|
for (const fetchTargetArg of [mainBranchRef, remoteMainOidArg]) {
|
|
1042
|
-
await runGit(smartshellArg, cwdArg, [
|
|
1084
|
+
const fetchResult = await runGit(smartshellArg, cwdArg, [
|
|
1043
1085
|
"fetch",
|
|
1044
1086
|
"--no-tags",
|
|
1045
1087
|
"--no-recurse-submodules",
|
|
@@ -1047,13 +1089,15 @@ const ensureRemoteCommitObject = async (
|
|
|
1047
1089
|
pushUrlArg,
|
|
1048
1090
|
fetchTargetArg,
|
|
1049
1091
|
]);
|
|
1092
|
+
if (fetchResult.exitCode !== 0) lastFetchFailure = fetchResult;
|
|
1050
1093
|
if (await hasCommitObject(smartshellArg, cwdArg, remoteMainOidArg, true)) {
|
|
1051
1094
|
return;
|
|
1052
1095
|
}
|
|
1053
1096
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1097
|
+
const message = `Remote main ${remoteMainOidArg} could not be fetched; remote containment unverified.`;
|
|
1098
|
+
throw lastFetchFailure
|
|
1099
|
+
? gitFailure(lastFetchFailure, message)
|
|
1100
|
+
: new Error(message);
|
|
1057
1101
|
};
|
|
1058
1102
|
|
|
1059
1103
|
/**
|
|
@@ -1232,7 +1276,11 @@ const compensateFailedLocalMainTransition = async (
|
|
|
1232
1276
|
if (restoreResult.exitCode === 0) {
|
|
1233
1277
|
return ` Local main ref was restored after the worktree update failed.${localState}`;
|
|
1234
1278
|
}
|
|
1235
|
-
|
|
1279
|
+
const failure = gitFailure(
|
|
1280
|
+
restoreResult,
|
|
1281
|
+
"Local main changed before its ref could be restored.",
|
|
1282
|
+
);
|
|
1283
|
+
return ` ${failure.message}${localState}`;
|
|
1236
1284
|
};
|
|
1237
1285
|
|
|
1238
1286
|
const rollbackLocalMain = async (
|
|
@@ -1385,7 +1433,8 @@ export async function integrateReleaseBranch(
|
|
|
1385
1433
|
contextArg.localMainOid,
|
|
1386
1434
|
]);
|
|
1387
1435
|
if (refAdvanceResult.exitCode !== 0) {
|
|
1388
|
-
throw
|
|
1436
|
+
throw gitFailure(
|
|
1437
|
+
refAdvanceResult,
|
|
1389
1438
|
"Local main changed before integration. No local ref or worktree rollback was attempted.",
|
|
1390
1439
|
);
|
|
1391
1440
|
}
|
|
@@ -1403,9 +1452,11 @@ export async function integrateReleaseBranch(
|
|
|
1403
1452
|
releaseCwd,
|
|
1404
1453
|
destinationGitDir,
|
|
1405
1454
|
);
|
|
1406
|
-
|
|
1407
|
-
|
|
1455
|
+
const failure = gitFailure(
|
|
1456
|
+
worktreeAdvanceResult,
|
|
1457
|
+
"Local main advanced, but its index and worktree could not be updated. No remote ref or release metadata was changed.",
|
|
1408
1458
|
);
|
|
1459
|
+
throw new Error(`${failure.message}${rollbackState}`);
|
|
1409
1460
|
}
|
|
1410
1461
|
try {
|
|
1411
1462
|
await verifyMainWorktree(
|
|
@@ -1468,8 +1519,12 @@ export async function integrateReleaseBranch(
|
|
|
1468
1519
|
releaseCwd,
|
|
1469
1520
|
destinationGitDir,
|
|
1470
1521
|
);
|
|
1522
|
+
const failure = gitFailure(
|
|
1523
|
+
pushResult,
|
|
1524
|
+
"Integrated main could not be confirmed at the remote. No release metadata was created.",
|
|
1525
|
+
);
|
|
1471
1526
|
throw new Error(
|
|
1472
|
-
|
|
1527
|
+
`${failure.message}${rollbackState}${
|
|
1473
1528
|
remoteAfterPush
|
|
1474
1529
|
? ""
|
|
1475
1530
|
: " The remote outcome is unknown; inspect refs/heads/main before retrying."
|
|
@@ -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(
|
|
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(
|
|
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(
|
|
528
|
+
throw new Error(
|
|
529
|
+
formatCommandFailure(
|
|
530
|
+
`Release ${phase} failed in the release checkout.`,
|
|
531
|
+
result,
|
|
532
|
+
{ command, output: "combined" },
|
|
533
|
+
),
|
|
534
|
+
);
|
|
509
535
|
};
|