@git.zone/cli 9.2.1 → 10.0.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/assets/templates/asset_binary_installer/install.sh +109 -34
- package/assets/templates/asset_binary_release_gitea/.gitea/workflows/release.yml +20 -6
- package/assets/templates/ci_rust/.gitea/workflows/rust_nottags.yaml +29 -0
- package/assets/templates/ci_rust/.gitea/workflows/rust_tags.yaml +32 -0
- package/assets/templates/gitignore/_gitignore +1 -1
- package/assets/templates/gitignore_rust/_gitignore +31 -0
- package/assets/templates/license_mit/license +4 -1
- package/assets/templates/rust/.smartscaf.yml +16 -0
- package/assets/templates/rust/_Cargo.toml +12 -0
- package/assets/templates/rust/_crate_Cargo.toml +10 -0
- package/assets/templates/rust/_crate_lib.rs +19 -0
- package/assets/templates/rust/_smartconfig.json +27 -0
- package/assets/templates/rust/readme.md +23 -0
- package/dist_ts/00_commitinfo_data.js +2 -2
- package/dist_ts/classes.gitzoneconfig.d.ts +3 -1
- package/dist_ts/classes.gitzoneconfig.js +9 -1
- package/dist_ts/helpers.managedassets.d.ts +1 -1
- package/dist_ts/helpers.managedassets.js +58 -14
- package/dist_ts/helpers.releasetargets.d.ts +6 -0
- package/dist_ts/helpers.releasetargets.js +13 -0
- package/dist_ts/helpers.smartconfigmigrations.js +42 -1
- package/dist_ts/helpers.toolconfig.d.ts +50 -0
- package/dist_ts/helpers.toolconfig.js +212 -0
- package/dist_ts/helpers.tssea.d.ts +9 -2
- package/dist_ts/helpers.tssea.js +47 -17
- package/dist_ts/helpers.tstest.d.ts +27 -8
- package/dist_ts/helpers.tstest.js +64 -26
- package/dist_ts/helpers.versionsource.d.ts +37 -0
- package/dist_ts/helpers.versionsource.js +112 -0
- package/dist_ts/helpers.workflow.d.ts +45 -1
- package/dist_ts/helpers.workflow.js +120 -5
- package/dist_ts/mod_commit/mod.helpers.d.ts +0 -24
- package/dist_ts/mod_commit/mod.helpers.js +1 -94
- package/dist_ts/mod_config/index.js +131 -18
- package/dist_ts/mod_format/formatters/assets.formatter.js +29 -27
- package/dist_ts/mod_format/formatters/gitignore.formatter.d.ts +4 -2
- package/dist_ts/mod_format/formatters/gitignore.formatter.js +10 -7
- package/dist_ts/mod_format/formatters/license.formatter.d.ts +8 -0
- package/dist_ts/mod_format/formatters/license.formatter.js +25 -2
- package/dist_ts/mod_format/formatters/packagejson.formatter.js +14 -3
- package/dist_ts/mod_format/formatters/rustfmt.formatter.d.ts +19 -0
- package/dist_ts/mod_format/formatters/rustfmt.formatter.js +97 -0
- package/dist_ts/mod_format/formatters/smartconfig.formatter.js +5 -2
- package/dist_ts/mod_format/index.js +3 -1
- package/dist_ts/mod_format/interfaces.format.js +2 -1
- package/dist_ts/mod_release/classes.releasejournal.d.ts +38 -2
- package/dist_ts/mod_release/classes.releasejournal.js +238 -66
- package/dist_ts/mod_release/helpers.cargorelease.d.ts +52 -0
- package/dist_ts/mod_release/helpers.cargorelease.js +195 -0
- package/dist_ts/mod_release/helpers.npmpackages.d.ts +18 -0
- package/dist_ts/mod_release/helpers.npmpackages.js +40 -2
- package/dist_ts/mod_release/helpers.releasecheck.d.ts +73 -0
- package/dist_ts/mod_release/helpers.releasecheck.js +269 -0
- package/dist_ts/mod_release/helpers.releasepreparation.d.ts +22 -8
- package/dist_ts/mod_release/helpers.releasepreparation.js +74 -26
- package/dist_ts/mod_release/helpers.releasepublication.d.ts +21 -1
- package/dist_ts/mod_release/helpers.releasepublication.js +249 -4
- package/dist_ts/mod_release/helpers.releaseversionsource.d.ts +10 -0
- package/dist_ts/mod_release/helpers.releaseversionsource.js +18 -0
- package/dist_ts/mod_release/helpers.rsrepoengine.d.ts +192 -0
- package/dist_ts/mod_release/helpers.rsrepoengine.js +457 -0
- package/dist_ts/mod_release/index.d.ts +3 -0
- package/dist_ts/mod_release/index.js +177 -65
- package/dist_ts/mod_template/index.js +6 -2
- package/package.json +1 -1
- package/readme.md +237 -21
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.gitzoneconfig.ts +10 -1
- package/ts/helpers.managedassets.ts +64 -14
- package/ts/helpers.releasetargets.ts +13 -0
- package/ts/helpers.smartconfigmigrations.ts +48 -0
- package/ts/helpers.toolconfig.ts +280 -0
- package/ts/helpers.tssea.ts +59 -16
- package/ts/helpers.tstest.ts +105 -35
- package/ts/helpers.versionsource.ts +169 -0
- package/ts/helpers.workflow.ts +197 -5
- package/ts/mod_commit/mod.helpers.ts +0 -119
- package/ts/mod_config/index.ts +169 -19
- package/ts/mod_format/formatters/assets.formatter.ts +28 -27
- package/ts/mod_format/formatters/gitignore.formatter.ts +10 -6
- package/ts/mod_format/formatters/license.formatter.ts +26 -1
- package/ts/mod_format/formatters/packagejson.formatter.ts +14 -2
- package/ts/mod_format/formatters/rustfmt.formatter.ts +107 -0
- package/ts/mod_format/formatters/smartconfig.formatter.ts +8 -1
- package/ts/mod_format/index.ts +2 -0
- package/ts/mod_format/interfaces.format.ts +1 -0
- package/ts/mod_release/classes.releasejournal.ts +312 -39
- package/ts/mod_release/helpers.cargorelease.ts +289 -0
- package/ts/mod_release/helpers.npmpackages.ts +76 -1
- package/ts/mod_release/helpers.releasecheck.ts +409 -0
- package/ts/mod_release/helpers.releasepreparation.ts +116 -36
- package/ts/mod_release/helpers.releasepublication.ts +462 -1
- package/ts/mod_release/helpers.releaseversionsource.ts +29 -0
- package/ts/mod_release/helpers.rsrepoengine.ts +790 -0
- package/ts/mod_release/index.ts +277 -84
- package/ts/mod_template/index.ts +5 -1
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import * as plugins from "./mod.plugins.js";
|
|
2
|
+
import type {
|
|
3
|
+
IResolvedReleaseWorkflow,
|
|
4
|
+
TReleaseTarget,
|
|
5
|
+
} from "../helpers.workflow.js";
|
|
6
|
+
import { assertPackageJsonFilesCurrent } from "../helpers.packagefiles.js";
|
|
7
|
+
import type { IReleaseArtifact } from "./classes.releasejournal.js";
|
|
8
|
+
import { releaseGitEnv } from "./helpers.releasebranch.js";
|
|
9
|
+
import { formatCommandFailure } from "./helpers.commandfailure.js";
|
|
10
|
+
import {
|
|
11
|
+
assertPnpmReleaseCapability,
|
|
12
|
+
packNpmArtifact,
|
|
13
|
+
type IPnpmReleaseCapability,
|
|
14
|
+
} from "./helpers.npmartifact.js";
|
|
15
|
+
import {
|
|
16
|
+
readNpmArtifactContents,
|
|
17
|
+
verifyPackedNpmArtifacts,
|
|
18
|
+
} from "./helpers.npmartifactcheck.js";
|
|
19
|
+
import {
|
|
20
|
+
packReleaseNpmModules,
|
|
21
|
+
planReleaseNpmPackages,
|
|
22
|
+
} from "./helpers.npmpackages.js";
|
|
23
|
+
import {
|
|
24
|
+
describeCargoReleasePlan,
|
|
25
|
+
describePackedCrates,
|
|
26
|
+
findCargoReleaseProblems,
|
|
27
|
+
openCargoReleaseEngine,
|
|
28
|
+
readCargoReleasePlan,
|
|
29
|
+
} from "./helpers.cargorelease.js";
|
|
30
|
+
import { withIsolatedReleaseCheckout } from "./helpers.releasepreparation.js";
|
|
31
|
+
import { openReleaseVersionSource } from "./helpers.releaseversionsource.js";
|
|
32
|
+
import { printReleasePhase } from "./helpers.releasephase.js";
|
|
33
|
+
|
|
34
|
+
/** Where a release check found a problem. */
|
|
35
|
+
export type TReleaseCheckArea = "tree" | "configuration" | "checkout" | "npm" | "cargo";
|
|
36
|
+
|
|
37
|
+
export interface IReleaseCheckProblem {
|
|
38
|
+
area: TReleaseCheckArea;
|
|
39
|
+
message: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** One packed npm tarball and what it carries. */
|
|
43
|
+
export interface IReleaseCheckNpmPackage {
|
|
44
|
+
packageName: string;
|
|
45
|
+
version: string;
|
|
46
|
+
size: number;
|
|
47
|
+
sha256: string;
|
|
48
|
+
integrity: string;
|
|
49
|
+
files: string[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** One packed crate and what it carries. */
|
|
53
|
+
export interface IReleaseCheckCrate {
|
|
54
|
+
name: string;
|
|
55
|
+
version: string;
|
|
56
|
+
sha256: string;
|
|
57
|
+
files: string[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** What `gitzone release check` built and packed, and every problem it found. */
|
|
61
|
+
export interface IReleaseCheckReport {
|
|
62
|
+
ok: boolean;
|
|
63
|
+
/** The checked commit: HEAD of the clean working tree. */
|
|
64
|
+
sourceOid: string | null;
|
|
65
|
+
targets: TReleaseTarget[];
|
|
66
|
+
/** The configured release build, run in the isolated checkout; null when the release does not build. */
|
|
67
|
+
build: { command: string; passed: boolean } | null;
|
|
68
|
+
npm?: { packages: IReleaseCheckNpmPackage[] };
|
|
69
|
+
cargo?: {
|
|
70
|
+
registries: string[];
|
|
71
|
+
order: string[];
|
|
72
|
+
/** The plan lines `gitzone release --plan` prints. */
|
|
73
|
+
plan: string[];
|
|
74
|
+
crates: IReleaseCheckCrate[];
|
|
75
|
+
};
|
|
76
|
+
/** Active targets this check does not cover, with the reason. */
|
|
77
|
+
notChecked: Array<{ target: TReleaseTarget; reason: string }>;
|
|
78
|
+
problems: IReleaseCheckProblem[];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface IReleaseCheckOptions {
|
|
82
|
+
smartshell: plugins.smartshell.Smartshell;
|
|
83
|
+
/** The working tree whose HEAD is checked. */
|
|
84
|
+
cwd: string;
|
|
85
|
+
workflow: IResolvedReleaseWorkflow;
|
|
86
|
+
/** Progress and content lines; the report carries the same facts. */
|
|
87
|
+
log: (lineArg: string) => void;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const messageOf = (errorArg: unknown): string =>
|
|
91
|
+
errorArg instanceof Error ? errorArg.message : String(errorArg);
|
|
92
|
+
|
|
93
|
+
const checkGit = async (
|
|
94
|
+
optionsArg: IReleaseCheckOptions,
|
|
95
|
+
argsArg: string[],
|
|
96
|
+
): Promise<plugins.smartshell.IExecResult> =>
|
|
97
|
+
optionsArg.smartshell.execSpawn("git", argsArg, {
|
|
98
|
+
cwd: optionsArg.cwd,
|
|
99
|
+
env: releaseGitEnv,
|
|
100
|
+
silent: true,
|
|
101
|
+
timeout: 60_000,
|
|
102
|
+
timeoutKillGraceMs: 5_000,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const notCheckedReasons: Partial<Record<TReleaseTarget, string>> = {
|
|
106
|
+
docker:
|
|
107
|
+
"tSDocker builds and qualifies the images during the release; `release check` packs no image",
|
|
108
|
+
giteaAssets:
|
|
109
|
+
"the Gitea asset manifest is frozen during the release; `release check` uploads and freezes nothing",
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Packs the npm packages of the checkout, verifies each tarball like a
|
|
114
|
+
* release does, and lists what each carries.
|
|
115
|
+
*/
|
|
116
|
+
const checkNpmPackages = async (
|
|
117
|
+
optionsArg: IReleaseCheckOptions,
|
|
118
|
+
checkoutPathArg: string,
|
|
119
|
+
preparationPathArg: string,
|
|
120
|
+
artifactDirectoryArg: string,
|
|
121
|
+
capabilityArg: IPnpmReleaseCapability,
|
|
122
|
+
): Promise<IReleaseCheckNpmPackage[]> => {
|
|
123
|
+
const { packageSet, plan } = await planReleaseNpmPackages(checkoutPathArg);
|
|
124
|
+
const artifacts: IReleaseArtifact[] = [];
|
|
125
|
+
if (plan.modules.length > 0) {
|
|
126
|
+
printReleasePhase("Packing the tspublish modules");
|
|
127
|
+
const modules = await packReleaseNpmModules(
|
|
128
|
+
{
|
|
129
|
+
smartshell: optionsArg.smartshell,
|
|
130
|
+
preparationDirectory: preparationPathArg,
|
|
131
|
+
version: plan.version,
|
|
132
|
+
pnpmCapability: capabilityArg,
|
|
133
|
+
},
|
|
134
|
+
checkoutPathArg,
|
|
135
|
+
plan,
|
|
136
|
+
artifactDirectoryArg,
|
|
137
|
+
);
|
|
138
|
+
artifacts.push(...modules.map((moduleArg) => moduleArg.artifact));
|
|
139
|
+
}
|
|
140
|
+
if (!packageSet.root.private) {
|
|
141
|
+
printReleasePhase("Packing the root package");
|
|
142
|
+
artifacts.push(
|
|
143
|
+
await packNpmArtifact(
|
|
144
|
+
optionsArg.smartshell,
|
|
145
|
+
checkoutPathArg,
|
|
146
|
+
artifactDirectoryArg,
|
|
147
|
+
plan.version,
|
|
148
|
+
capabilityArg,
|
|
149
|
+
),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
printReleasePhase("Checking the packed npm artifacts");
|
|
153
|
+
await verifyPackedNpmArtifacts({
|
|
154
|
+
workflow: optionsArg.workflow,
|
|
155
|
+
artifactDirectory: artifactDirectoryArg,
|
|
156
|
+
artifacts,
|
|
157
|
+
log: optionsArg.log,
|
|
158
|
+
});
|
|
159
|
+
const packages: IReleaseCheckNpmPackage[] = [];
|
|
160
|
+
for (const artifact of artifacts) {
|
|
161
|
+
const contents = await readNpmArtifactContents(
|
|
162
|
+
plugins.path.join(artifactDirectoryArg, artifact.file),
|
|
163
|
+
);
|
|
164
|
+
packages.push({
|
|
165
|
+
packageName: artifact.packageName,
|
|
166
|
+
version: artifact.version,
|
|
167
|
+
size: artifact.size,
|
|
168
|
+
sha256: artifact.sha256,
|
|
169
|
+
integrity: artifact.integrity,
|
|
170
|
+
files: [...contents.files].sort(),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
for (const entry of packages) {
|
|
174
|
+
optionsArg.log(
|
|
175
|
+
`npm package ${entry.packageName}@${entry.version}: ${entry.files.length} files, ${entry.size} bytes, sha256 ${entry.sha256}`,
|
|
176
|
+
);
|
|
177
|
+
for (const file of entry.files) optionsArg.log(` ${file}`);
|
|
178
|
+
}
|
|
179
|
+
return packages;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Reads the workspace plan of the checkout, reports every problem a release
|
|
184
|
+
* would refuse, and packs the crates the release would publish.
|
|
185
|
+
*/
|
|
186
|
+
const checkCargoCrates = async (
|
|
187
|
+
optionsArg: IReleaseCheckOptions,
|
|
188
|
+
checkoutPathArg: string,
|
|
189
|
+
artifactDirectoryArg: string,
|
|
190
|
+
reportArg: IReleaseCheckReport,
|
|
191
|
+
): Promise<void> => {
|
|
192
|
+
const cargo = optionsArg.workflow.cargo;
|
|
193
|
+
if (!cargo) throw new Error("The cargo target has no resolved configuration.");
|
|
194
|
+
const engine = await openCargoReleaseEngine(optionsArg.smartshell, checkoutPathArg);
|
|
195
|
+
const plan = await readCargoReleasePlan(engine, checkoutPathArg, cargo);
|
|
196
|
+
const planLines = describeCargoReleasePlan(plan, cargo);
|
|
197
|
+
for (const line of planLines) optionsArg.log(line);
|
|
198
|
+
reportArg.cargo = {
|
|
199
|
+
registries: cargo.registries,
|
|
200
|
+
order: plan.order,
|
|
201
|
+
plan: planLines,
|
|
202
|
+
crates: [],
|
|
203
|
+
};
|
|
204
|
+
for (const problem of findCargoReleaseProblems(plan, cargo))
|
|
205
|
+
reportArg.problems.push({ area: "cargo", message: problem });
|
|
206
|
+
if (plan.order.length === 0) return;
|
|
207
|
+
printReleasePhase(`Packing the crates ${plan.order.join(", ")}`);
|
|
208
|
+
const packed = await engine.package({
|
|
209
|
+
cwd: checkoutPathArg,
|
|
210
|
+
outDir: artifactDirectoryArg,
|
|
211
|
+
members: plan.order,
|
|
212
|
+
});
|
|
213
|
+
for (const line of describePackedCrates(packed.crates)) optionsArg.log(line);
|
|
214
|
+
reportArg.cargo.crates = packed.crates.map(({ name, version, sha256, files }) => ({
|
|
215
|
+
name,
|
|
216
|
+
version,
|
|
217
|
+
sha256,
|
|
218
|
+
files,
|
|
219
|
+
}));
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* `gitzone release check`: everything a release builds and packs, without
|
|
224
|
+
* creating anything. It needs a clean working tree and a version source the
|
|
225
|
+
* release accepts, checks out HEAD into a
|
|
226
|
+
* disposable worktree exactly as a release checks out its release commit
|
|
227
|
+
* (npm install or `cargo fetch --locked`), runs the configured release build
|
|
228
|
+
* there, packs and verifies the npm packages and the crates of the active
|
|
229
|
+
* targets, and removes the checkout and every artifact again. It never
|
|
230
|
+
* changes the version, commits, tags, writes a journal or publishes.
|
|
231
|
+
*/
|
|
232
|
+
export const runReleaseCheck = async (
|
|
233
|
+
optionsArg: IReleaseCheckOptions,
|
|
234
|
+
): Promise<IReleaseCheckReport> => {
|
|
235
|
+
const { workflow } = optionsArg;
|
|
236
|
+
const report: IReleaseCheckReport = {
|
|
237
|
+
ok: false,
|
|
238
|
+
sourceOid: null,
|
|
239
|
+
targets: workflow.targets,
|
|
240
|
+
build: null,
|
|
241
|
+
notChecked: workflow.targets.flatMap((target) => {
|
|
242
|
+
const reason = notCheckedReasons[target];
|
|
243
|
+
return reason ? [{ target, reason }] : [];
|
|
244
|
+
}),
|
|
245
|
+
problems: [],
|
|
246
|
+
};
|
|
247
|
+
const finish = (): IReleaseCheckReport => {
|
|
248
|
+
report.ok = report.problems.length === 0;
|
|
249
|
+
return report;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const head = await checkGit(optionsArg, ["rev-parse", "--verify", "HEAD"]);
|
|
253
|
+
if (head.exitCode !== 0) {
|
|
254
|
+
report.problems.push({
|
|
255
|
+
area: "tree",
|
|
256
|
+
message: formatCommandFailure("The working tree has no HEAD commit to check.", head, {
|
|
257
|
+
command: "git rev-parse",
|
|
258
|
+
timeoutMs: 60_000,
|
|
259
|
+
}),
|
|
260
|
+
});
|
|
261
|
+
return finish();
|
|
262
|
+
}
|
|
263
|
+
report.sourceOid = head.stdout.trim();
|
|
264
|
+
const status = await checkGit(optionsArg, ["status", "--porcelain"]);
|
|
265
|
+
if (status.exitCode !== 0 || status.stdout.trim() !== "") {
|
|
266
|
+
report.problems.push({
|
|
267
|
+
area: "tree",
|
|
268
|
+
message:
|
|
269
|
+
status.exitCode !== 0
|
|
270
|
+
? formatCommandFailure("Unable to inspect the working tree.", status, {
|
|
271
|
+
command: "git status",
|
|
272
|
+
timeoutMs: 60_000,
|
|
273
|
+
})
|
|
274
|
+
: "The working tree has uncommitted changes. A release packs only committed files: commit or stash them, then check again.",
|
|
275
|
+
});
|
|
276
|
+
return finish();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// The version source the release would bump: a project the release and its
|
|
280
|
+
// plan refuse (a Cargo.toml without projectType "rust", a Rust workspace
|
|
281
|
+
// outside the repository root, independent crate versions) is refused here
|
|
282
|
+
// with the same message, before anything is checked out.
|
|
283
|
+
try {
|
|
284
|
+
await (
|
|
285
|
+
await openReleaseVersionSource(optionsArg.smartshell, workflow, optionsArg.cwd)
|
|
286
|
+
).readCurrentVersion();
|
|
287
|
+
} catch (error) {
|
|
288
|
+
report.problems.push({ area: "configuration", message: messageOf(error) });
|
|
289
|
+
return finish();
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (workflow.packageFilesConfigured) {
|
|
293
|
+
try {
|
|
294
|
+
await assertPackageJsonFilesCurrent(optionsArg.cwd);
|
|
295
|
+
} catch (error) {
|
|
296
|
+
report.problems.push({ area: "configuration", message: messageOf(error) });
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const checksNpm = workflow.targets.includes("npm");
|
|
301
|
+
const checksCargo = workflow.targets.includes("cargo");
|
|
302
|
+
if (!workflow.runBuild && !checksNpm && !checksCargo) {
|
|
303
|
+
optionsArg.log("Nothing to check: the release neither builds nor packs anything.");
|
|
304
|
+
return finish();
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
let pnpmCapability: IPnpmReleaseCapability | undefined;
|
|
308
|
+
if (checksNpm) {
|
|
309
|
+
try {
|
|
310
|
+
pnpmCapability = await assertPnpmReleaseCapability(
|
|
311
|
+
optionsArg.smartshell,
|
|
312
|
+
optionsArg.cwd,
|
|
313
|
+
);
|
|
314
|
+
} catch (error) {
|
|
315
|
+
report.problems.push({ area: "npm", message: messageOf(error) });
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (workflow.runBuild) report.build = { command: workflow.buildCommand, passed: false };
|
|
320
|
+
const artifactDirectory = await plugins.fs.mkdtemp(
|
|
321
|
+
plugins.path.join(
|
|
322
|
+
await plugins.fs.realpath(plugins.os.tmpdir()),
|
|
323
|
+
"gitzone-release-check-",
|
|
324
|
+
),
|
|
325
|
+
);
|
|
326
|
+
try {
|
|
327
|
+
await withIsolatedReleaseCheckout(
|
|
328
|
+
{
|
|
329
|
+
smartshell: optionsArg.smartshell,
|
|
330
|
+
repositoryCwd: optionsArg.cwd,
|
|
331
|
+
mainOid: report.sourceOid,
|
|
332
|
+
...(workflow.runBuild ? { buildCommand: workflow.buildCommand } : {}),
|
|
333
|
+
cargo: workflow.cargoVersioned,
|
|
334
|
+
},
|
|
335
|
+
async (checkout) => {
|
|
336
|
+
if (report.build) report.build.passed = true;
|
|
337
|
+
if (checksNpm && pnpmCapability) {
|
|
338
|
+
try {
|
|
339
|
+
report.npm = {
|
|
340
|
+
packages: await checkNpmPackages(
|
|
341
|
+
optionsArg,
|
|
342
|
+
checkout.path,
|
|
343
|
+
checkout.preparationPath,
|
|
344
|
+
artifactDirectory,
|
|
345
|
+
pnpmCapability,
|
|
346
|
+
),
|
|
347
|
+
};
|
|
348
|
+
} catch (error) {
|
|
349
|
+
report.problems.push({ area: "npm", message: messageOf(error) });
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
if (checksCargo) {
|
|
353
|
+
const crateDirectory = plugins.path.join(artifactDirectory, "crates");
|
|
354
|
+
await plugins.fs.mkdir(crateDirectory);
|
|
355
|
+
try {
|
|
356
|
+
await checkCargoCrates(optionsArg, checkout.path, crateDirectory, report);
|
|
357
|
+
} catch (error) {
|
|
358
|
+
report.problems.push({ area: "cargo", message: messageOf(error) });
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
);
|
|
363
|
+
} catch (error) {
|
|
364
|
+
// The checkout, its install or fetch, the build, or the final exactness
|
|
365
|
+
// check failed; the packing steps above report their own failures.
|
|
366
|
+
report.problems.push({ area: "checkout", message: messageOf(error) });
|
|
367
|
+
} finally {
|
|
368
|
+
await plugins.fs.rm(artifactDirectory, { recursive: true, force: true });
|
|
369
|
+
}
|
|
370
|
+
return finish();
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
/** The human-readable summary of a report, after the progress output. */
|
|
374
|
+
export const describeReleaseCheckReport = (
|
|
375
|
+
reportArg: IReleaseCheckReport,
|
|
376
|
+
): string[] => {
|
|
377
|
+
const lines = [
|
|
378
|
+
"",
|
|
379
|
+
"gitzone release check",
|
|
380
|
+
`commit: ${reportArg.sourceOid ?? "none"}`,
|
|
381
|
+
`targets: ${reportArg.targets.length > 0 ? reportArg.targets.join(", ") : "none"}`,
|
|
382
|
+
`build: ${reportArg.build ? `${reportArg.build.command} (${reportArg.build.passed ? "passed" : "failed"})` : "not part of this release"}`,
|
|
383
|
+
];
|
|
384
|
+
if (reportArg.npm)
|
|
385
|
+
for (const entry of reportArg.npm.packages)
|
|
386
|
+
lines.push(
|
|
387
|
+
`npm package: ${entry.packageName}@${entry.version} (${entry.files.length} files, ${entry.size} bytes)`,
|
|
388
|
+
);
|
|
389
|
+
if (reportArg.cargo) {
|
|
390
|
+
lines.push(
|
|
391
|
+
`cargo order: ${reportArg.cargo.order.length > 0 ? reportArg.cargo.order.join(" -> ") : "none"} (registries ${reportArg.cargo.registries.join(", ")})`,
|
|
392
|
+
);
|
|
393
|
+
for (const crate of reportArg.cargo.crates)
|
|
394
|
+
lines.push(`crate: ${crate.name}@${crate.version} (${crate.files.length} files)`);
|
|
395
|
+
}
|
|
396
|
+
for (const entry of reportArg.notChecked)
|
|
397
|
+
lines.push(`not checked: ${entry.target}: ${entry.reason}`);
|
|
398
|
+
if (reportArg.problems.length > 0) {
|
|
399
|
+
lines.push(`problems (${reportArg.problems.length}):`);
|
|
400
|
+
for (const problem of reportArg.problems)
|
|
401
|
+
lines.push(`- [${problem.area}] ${problem.message}`);
|
|
402
|
+
}
|
|
403
|
+
lines.push(
|
|
404
|
+
reportArg.ok
|
|
405
|
+
? "Release check passed; the checkout and every artifact were removed."
|
|
406
|
+
: `Release check failed with ${reportArg.problems.length} problem(s); the checkout and every artifact were removed.`,
|
|
407
|
+
);
|
|
408
|
+
return lines;
|
|
409
|
+
};
|
|
@@ -278,6 +278,7 @@ const bindPreparation = async (
|
|
|
278
278
|
};
|
|
279
279
|
|
|
280
280
|
const releaseLockfileName = "pnpm-lock.yaml";
|
|
281
|
+
const cargoLockfileName = "Cargo.lock";
|
|
281
282
|
|
|
282
283
|
/** The commit the release commit is built on top of, and its clean worktree. */
|
|
283
284
|
export interface IReleaseSourceCommit {
|
|
@@ -336,24 +337,76 @@ export const getReleaseCommandEnvironment = async (
|
|
|
336
337
|
};
|
|
337
338
|
};
|
|
338
339
|
|
|
340
|
+
/** The locked Cargo dependencies of a checkout, fetched without changing Cargo.lock. */
|
|
341
|
+
const fetchLockedCargoDependencies = async (
|
|
342
|
+
smartshellArg: plugins.smartshell.Smartshell,
|
|
343
|
+
cwdArg: string,
|
|
344
|
+
failureArg: string,
|
|
345
|
+
): Promise<void> => {
|
|
346
|
+
const fetch = await smartshellArg.execSpawn(
|
|
347
|
+
"cargo",
|
|
348
|
+
["fetch", "--locked"],
|
|
349
|
+
{
|
|
350
|
+
cwd: cwdArg,
|
|
351
|
+
silent: true,
|
|
352
|
+
timeout: 10 * 60_000,
|
|
353
|
+
timeoutKillGraceMs: 5_000,
|
|
354
|
+
},
|
|
355
|
+
);
|
|
356
|
+
if (fetch.exitCode !== 0 || fetch.timedOut)
|
|
357
|
+
throw new Error(
|
|
358
|
+
formatCommandFailure(failureArg, fetch, {
|
|
359
|
+
command: "cargo fetch --locked",
|
|
360
|
+
timeoutMs: 10 * 60_000,
|
|
361
|
+
output: "combined",
|
|
362
|
+
}),
|
|
363
|
+
);
|
|
364
|
+
};
|
|
365
|
+
|
|
339
366
|
/**
|
|
340
|
-
* The isolated release checkout installs with `pnpm install --frozen-lockfile
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
367
|
+
* The isolated release checkout installs with `pnpm install --frozen-lockfile`
|
|
368
|
+
* when the release commit carries a package.json, and fetches with
|
|
369
|
+
* `cargo fetch --locked` when Cargo carries the release version. A manifest or
|
|
370
|
+
* lockfile that the release commit does not carry, or a lockfile that no
|
|
371
|
+
* longer matches its manifest, would fail a release that already created its
|
|
372
|
+
* commit and tag, so preflight proves them before anything is created. The
|
|
373
|
+
* release commit is what counts, not the working folder: an ignored
|
|
374
|
+
* package.json is not part of the release.
|
|
346
375
|
*
|
|
347
376
|
* The release commit only adds the version bump, the baked commit info, and the
|
|
348
377
|
* changelog section on top of the source commit, and a version change never
|
|
349
|
-
* changes a dependency specifier, so what installs here installs there.
|
|
378
|
+
* changes a dependency specifier, so what installs here installs there. A
|
|
379
|
+
* Cargo version bump rewrites the workspace's own entries in Cargo.lock
|
|
380
|
+
* offline, which `cargo fetch --locked` accepts again in the checkout.
|
|
350
381
|
*/
|
|
351
382
|
export const assertReleaseCheckoutInstallable = async (
|
|
352
|
-
options: IReleaseSourceCommit
|
|
383
|
+
options: IReleaseSourceCommit & {
|
|
384
|
+
/** projectType "rust": the Cargo workspace carries the version. */
|
|
385
|
+
cargo: boolean;
|
|
386
|
+
},
|
|
353
387
|
): Promise<void> => {
|
|
388
|
+
if (options.cargo) {
|
|
389
|
+
for (const file of ["Cargo.toml", cargoLockfileName]) {
|
|
390
|
+
if (!(await commitCarriesBlob(options, file))) {
|
|
391
|
+
throw new Error(
|
|
392
|
+
`The release fetches the locked Cargo dependencies of its release commit with \`cargo fetch --locked\`, but commit ${options.sourceOid} carries no root ${file}. Commit it — it must not be ignored — and release again.`,
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
logger.log(
|
|
397
|
+
"info",
|
|
398
|
+
"Verifying the committed Cargo.lock fetches the release checkout",
|
|
399
|
+
);
|
|
400
|
+
await fetchLockedCargoDependencies(
|
|
401
|
+
options.smartshell,
|
|
402
|
+
options.cwd,
|
|
403
|
+
`\`cargo fetch --locked\` rejects the committed ${cargoLockfileName}, so the release checkout could not fetch it. Run \`cargo update --workspace\`, commit the updated lockfile, and release again.`,
|
|
404
|
+
);
|
|
405
|
+
}
|
|
354
406
|
if (!(await commitCarriesBlob(options, "package.json"))) {
|
|
407
|
+
if (options.cargo) return;
|
|
355
408
|
throw new Error(
|
|
356
|
-
`Commit ${options.sourceOid} tracks no package.json: gitzone commit and release version the package.json.`,
|
|
409
|
+
`Commit ${options.sourceOid} tracks no package.json: gitzone commit and release version the package.json, or the Cargo workspace of projectType "rust".`,
|
|
357
410
|
);
|
|
358
411
|
}
|
|
359
412
|
logger.log(
|
|
@@ -419,6 +472,13 @@ export interface IIsolatedReleaseCheckoutOptions {
|
|
|
419
472
|
testCommand?: string;
|
|
420
473
|
/** Configured build command, when the checkout must build. */
|
|
421
474
|
buildCommand?: string;
|
|
475
|
+
/** projectType "rust": fetch the locked Cargo dependencies. */
|
|
476
|
+
cargo?: boolean;
|
|
477
|
+
/**
|
|
478
|
+
* Install the npm dependencies of a commit that carries a package.json;
|
|
479
|
+
* default true. A checkout that only publishes crates needs none.
|
|
480
|
+
*/
|
|
481
|
+
npmInstall?: boolean;
|
|
422
482
|
}
|
|
423
483
|
|
|
424
484
|
/**
|
|
@@ -471,33 +531,52 @@ export const withIsolatedReleaseCheckout = async <T>(
|
|
|
471
531
|
cwd: checkout,
|
|
472
532
|
sourceOid: options.mainOid,
|
|
473
533
|
});
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
534
|
+
// The checkout holds exactly the release commit, so its files are the
|
|
535
|
+
// commit's files.
|
|
536
|
+
const carriesPackageJson = await plugins.fs
|
|
537
|
+
.lstat(plugins.path.join(checkout, "package.json"))
|
|
538
|
+
.then((statArg) => statArg.isFile())
|
|
539
|
+
.catch((error: NodeJS.ErrnoException) => {
|
|
540
|
+
if (error.code === "ENOENT") return false;
|
|
541
|
+
throw error;
|
|
542
|
+
});
|
|
543
|
+
// Without a Cargo workspace the npm install always runs, so a missing or
|
|
544
|
+
// linked package.json fails it exactly as before.
|
|
545
|
+
if ((carriesPackageJson || !options.cargo) && options.npmInstall !== false) {
|
|
546
|
+
const install = await options.smartshell.execSpawn(
|
|
547
|
+
"pnpm",
|
|
548
|
+
[
|
|
549
|
+
"install",
|
|
550
|
+
"--frozen-lockfile",
|
|
551
|
+
...(env.PNPM_CONFIG_IGNORE_WORKSPACE === "true"
|
|
552
|
+
? ["--ignore-workspace"]
|
|
553
|
+
: []),
|
|
554
|
+
],
|
|
555
|
+
{
|
|
556
|
+
cwd: checkout,
|
|
557
|
+
env,
|
|
558
|
+
timeout: 10 * 60_000,
|
|
559
|
+
timeoutKillGraceMs: 5_000,
|
|
560
|
+
},
|
|
561
|
+
);
|
|
562
|
+
if (install.exitCode !== 0)
|
|
563
|
+
throw new Error(
|
|
564
|
+
formatCommandFailure(
|
|
565
|
+
"Release checkout dependency installation failed.",
|
|
566
|
+
install,
|
|
567
|
+
{
|
|
568
|
+
command: "pnpm install --frozen-lockfile",
|
|
569
|
+
timeoutMs: 10 * 60_000,
|
|
570
|
+
output: "combined",
|
|
571
|
+
},
|
|
572
|
+
),
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
if (options.cargo)
|
|
576
|
+
await fetchLockedCargoDependencies(
|
|
577
|
+
options.smartshell,
|
|
578
|
+
checkout,
|
|
579
|
+
"Release checkout Cargo dependency fetch failed.",
|
|
501
580
|
);
|
|
502
581
|
if (options.testCommand)
|
|
503
582
|
await run(
|
|
@@ -579,6 +658,7 @@ export const withReleasePreparationRecovery = async <T>(
|
|
|
579
658
|
...(options.workflow.runBuild
|
|
580
659
|
? { buildCommand: options.workflow.buildCommand }
|
|
581
660
|
: {}),
|
|
661
|
+
cargo: options.workflow.cargoVersioned,
|
|
582
662
|
},
|
|
583
663
|
async (checkout) => {
|
|
584
664
|
await ensureState();
|