perf(ci): speed up release builds and Windows packaging (#7975)
This commit is contained in:
1 parent
f70eeeeb06
commit
25dcee00a6
6 files changed
+251
-120
No files matched your search
@@ -40,6 +40,7 @@ import {
|
||||
resolveDesktopUpdateChannel,
|
||||
resolveDesktopWebAssetBrand,
|
||||
resolveResourceMonitorRustTargets,
|
||||
resolveWindowsServerAsarIgnoreGlobs,
|
||||
resourceMonitorExecutableName,
|
||||
resolveGitHubPublishConfig,
|
||||
resolveMockUpdateServerPort,
|
||||
@@ -47,6 +48,7 @@ import {
|
||||
resolvePackageManagerUserAgent,
|
||||
stageLinuxIconSize,
|
||||
stageDesktopDmgBackground,
|
||||
stageResourceMonitor,
|
||||
STAGE_INSTALL_ARGS,
|
||||
ancestorNodeModulesPaths,
|
||||
copyDirectoryPreservingSymlinks,
|
||||
@@ -118,7 +120,7 @@ const makeWindowsPayloadFixture = Effect.fn("test.makeWindowsPayloadFixture")(fu
|
||||
yield* fs.writeFileString(nativePath, "native-binary");
|
||||
|
||||
const generatedAsarPath = path.join(tempDir, WINDOWS_SERVER_ASAR_RESOURCE);
|
||||
yield* packWindowsServerAsar({ sourceDir, asarPath: generatedAsarPath });
|
||||
yield* packWindowsServerAsar({ sourceDir, asarPath: generatedAsarPath, arch: "x64" });
|
||||
|
||||
const stageDistDir = path.join(tempDir, "dist");
|
||||
const packagedAppDir = path.join(stageDistDir, "win-unpacked");
|
||||
@@ -488,6 +490,121 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
|
||||
}).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
|
||||
);
|
||||
|
||||
it("excludes node-pty binaries for the other Windows architecture", () => {
|
||||
assert.deepStrictEqual(resolveWindowsServerAsarIgnoreGlobs("x64"), [
|
||||
...WINDOWS_SERVER_ASAR_IGNORE_GLOBS,
|
||||
"**/node_modules/node-pty/prebuilds/win32-arm64",
|
||||
"**/node_modules/node-pty/prebuilds/win32-arm64/**",
|
||||
"**/node_modules/node-pty/third_party/conpty/*/win10-arm64",
|
||||
"**/node_modules/node-pty/third_party/conpty/*/win10-arm64/**",
|
||||
]);
|
||||
assert.deepStrictEqual(resolveWindowsServerAsarIgnoreGlobs("arm64"), [
|
||||
...WINDOWS_SERVER_ASAR_IGNORE_GLOBS,
|
||||
"**/node_modules/node-pty/prebuilds/win32-x64",
|
||||
"**/node_modules/node-pty/prebuilds/win32-x64/**",
|
||||
"**/node_modules/node-pty/third_party/conpty/*/win10-x64",
|
||||
"**/node_modules/node-pty/third_party/conpty/*/win10-x64/**",
|
||||
]);
|
||||
});
|
||||
|
||||
it.effect(
|
||||
"keeps target and WSL native files while excluding the other Windows architecture",
|
||||
() =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const tempDir = yield* fs.makeTempDirectoryScoped({
|
||||
prefix: "t3-windows-architecture-test-",
|
||||
});
|
||||
const sourceDir = path.join(tempDir, "server");
|
||||
const nativeFiles = [
|
||||
"node_modules/node-pty/prebuilds/win32-x64/conpty/OpenConsole.exe",
|
||||
"node_modules/node-pty/prebuilds/win32-arm64/conpty/OpenConsole.exe",
|
||||
"node_modules/node-pty/prebuilds/linux-x64/pty.node",
|
||||
"node_modules/node-pty/third_party/conpty/1.0.0/win10-x64/OpenConsole.exe",
|
||||
"node_modules/node-pty/third_party/conpty/1.0.0/win10-arm64/OpenConsole.exe",
|
||||
];
|
||||
|
||||
for (const nativeFile of nativeFiles) {
|
||||
const nativePath = path.join(sourceDir, nativeFile);
|
||||
yield* fs.makeDirectory(path.dirname(nativePath), { recursive: true });
|
||||
yield* fs.writeFileString(nativePath, "native");
|
||||
}
|
||||
|
||||
const asarPath = path.join(tempDir, "server.asar");
|
||||
yield* packWindowsServerAsar({ sourceDir, asarPath, arch: "x64" });
|
||||
const unpackedRoot = `${asarPath}.unpacked`;
|
||||
|
||||
assert.isTrue(
|
||||
yield* fs.exists(
|
||||
path.join(
|
||||
unpackedRoot,
|
||||
"node_modules/node-pty/prebuilds/win32-x64/conpty/OpenConsole.exe",
|
||||
),
|
||||
),
|
||||
);
|
||||
assert.isTrue(
|
||||
yield* fs.exists(
|
||||
path.join(unpackedRoot, "node_modules/node-pty/prebuilds/linux-x64/pty.node"),
|
||||
),
|
||||
);
|
||||
assert.isFalse(
|
||||
yield* fs.exists(
|
||||
path.join(unpackedRoot, "node_modules/node-pty/prebuilds/win32-arm64"),
|
||||
),
|
||||
);
|
||||
assert.isFalse(
|
||||
yield* fs.exists(
|
||||
path.join(unpackedRoot, "node_modules/node-pty/third_party/conpty/1.0.0/win10-arm64"),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("stages a cached resource monitor without invoking Cargo", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const repoRoot = yield* fs.makeTempDirectoryScoped({
|
||||
prefix: "t3-resource-monitor-cache-test-",
|
||||
});
|
||||
const binaryPath = path.join(
|
||||
repoRoot,
|
||||
"native/resource-monitor/target/x86_64-unknown-linux-gnu/release/t3-resource-monitor",
|
||||
);
|
||||
const stageResourcesDir = path.join(repoRoot, "stage");
|
||||
yield* fs.makeDirectory(path.dirname(binaryPath), { recursive: true });
|
||||
yield* fs.writeFileString(binaryPath, "cached monitor");
|
||||
|
||||
yield* stageResourceMonitor({
|
||||
repoRoot,
|
||||
stageResourcesDir,
|
||||
platform: "linux",
|
||||
arch: "x64",
|
||||
verbose: false,
|
||||
}).pipe(
|
||||
Effect.provide(
|
||||
ConfigProvider.layer(
|
||||
ConfigProvider.fromEnv({
|
||||
env: { T3CODE_DESKTOP_REUSE_RESOURCE_MONITOR: "true" },
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
yield* fs.readFileString(
|
||||
path.join(stageResourcesDir, "resource-monitor/t3-resource-monitor"),
|
||||
),
|
||||
"cached monitor",
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("validates every ASAR-unpacked native in the packaged Windows payload", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
@@ -504,6 +621,7 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
|
||||
yield* packWindowsServerAsar({
|
||||
sourceDir: fixture.sourceDir,
|
||||
asarPath: secondAsarPath,
|
||||
arch: "x64",
|
||||
});
|
||||
const [firstAsar, secondAsar] = yield* Effect.all([
|
||||
fs.readFile(fixture.generatedAsarPath),
|
||||
|
||||
@@ -819,6 +819,21 @@ export const WINDOWS_SERVER_ASAR_IGNORE_GLOBS = [
|
||||
"**/node_modules/.bin",
|
||||
"**/node_modules/.bin/**",
|
||||
] as const;
|
||||
|
||||
export function resolveWindowsServerAsarIgnoreGlobs(arch: typeof BuildArch.Type) {
|
||||
const unusedArch = arch === "arm64" ? "x64" : "arm64";
|
||||
const unusedPrebuild = `**/node_modules/node-pty/prebuilds/win32-${unusedArch}`;
|
||||
const unusedConpty = `**/node_modules/node-pty/third_party/conpty/*/win10-${unusedArch}`;
|
||||
|
||||
return [
|
||||
...WINDOWS_SERVER_ASAR_IGNORE_GLOBS,
|
||||
unusedPrebuild,
|
||||
`${unusedPrebuild}/**`,
|
||||
unusedConpty,
|
||||
`${unusedConpty}/**`,
|
||||
];
|
||||
}
|
||||
|
||||
export const WINDOWS_PACKAGED_PAYLOAD_FILE_LIMIT = 80;
|
||||
export const WINDOWS_SERVER_RESOURCE_SOURCE_DIR = "apps/desktop/prod-resources/windows-server";
|
||||
export const WINDOWS_SERVER_EXTRA_RESOURCES = [
|
||||
@@ -1643,7 +1658,7 @@ const verifyPackagedBundleIsSelfContained = Effect.fn("verifyPackagedBundleIsSel
|
||||
},
|
||||
);
|
||||
|
||||
const stageResourceMonitor = Effect.fn("stageResourceMonitor")(function* (input: {
|
||||
export const stageResourceMonitor = Effect.fn("stageResourceMonitor")(function* (input: {
|
||||
readonly repoRoot: string;
|
||||
readonly stageResourcesDir: string;
|
||||
readonly platform: typeof BuildPlatform.Type;
|
||||
@@ -1655,28 +1670,33 @@ const stageResourceMonitor = Effect.fn("stageResourceMonitor")(function* (input:
|
||||
const manifestPath = path.join(input.repoRoot, "native/resource-monitor/Cargo.toml");
|
||||
const executableName = resourceMonitorExecutableName(input.platform);
|
||||
const rustTargets = resolveResourceMonitorRustTargets(input.platform, input.arch);
|
||||
const reuseResourceMonitor = yield* Config.boolean("T3CODE_DESKTOP_REUSE_RESOURCE_MONITOR").pipe(
|
||||
Config.withDefault(false),
|
||||
);
|
||||
const builtBinaries: string[] = [];
|
||||
|
||||
for (const rustTarget of rustTargets) {
|
||||
const spawnCommand = yield* resolveSpawnCommand("cargo", [
|
||||
"build",
|
||||
"--locked",
|
||||
"--release",
|
||||
"--manifest-path",
|
||||
manifestPath,
|
||||
"--target",
|
||||
rustTarget,
|
||||
]);
|
||||
yield* runCommand(
|
||||
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
|
||||
cwd: input.repoRoot,
|
||||
shell: spawnCommand.shell,
|
||||
}),
|
||||
{
|
||||
label: `cargo build resource monitor (${rustTarget})`,
|
||||
verbose: input.verbose,
|
||||
},
|
||||
);
|
||||
if (!reuseResourceMonitor) {
|
||||
const spawnCommand = yield* resolveSpawnCommand("cargo", [
|
||||
"build",
|
||||
"--locked",
|
||||
"--release",
|
||||
"--manifest-path",
|
||||
manifestPath,
|
||||
"--target",
|
||||
rustTarget,
|
||||
]);
|
||||
yield* runCommand(
|
||||
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
|
||||
cwd: input.repoRoot,
|
||||
shell: spawnCommand.shell,
|
||||
}),
|
||||
{
|
||||
label: `cargo build resource monitor (${rustTarget})`,
|
||||
verbose: input.verbose,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const binaryPath = path.join(
|
||||
input.repoRoot,
|
||||
@@ -1693,6 +1713,9 @@ const stageResourceMonitor = Effect.fn("stageResourceMonitor")(function* (input:
|
||||
arch: input.arch,
|
||||
});
|
||||
}
|
||||
if (reuseResourceMonitor) {
|
||||
yield* Effect.log(`[desktop-artifact] Reusing cached resource monitor (${rustTarget}).`);
|
||||
}
|
||||
builtBinaries.push(binaryPath);
|
||||
}
|
||||
|
||||
@@ -2253,6 +2276,7 @@ const stageWslNodePtyPrebuild = Effect.fn("stageWslNodePtyPrebuild")(function* (
|
||||
export const packWindowsServerAsar = Effect.fn("packWindowsServerAsar")(function* (input: {
|
||||
readonly sourceDir: string;
|
||||
readonly asarPath: string;
|
||||
readonly arch: typeof BuildArch.Type;
|
||||
}) {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
yield* Effect.tryPromise({
|
||||
@@ -2260,7 +2284,7 @@ export const packWindowsServerAsar = Effect.fn("packWindowsServerAsar")(function
|
||||
createPackageWithOptions(input.sourceDir, input.asarPath, {
|
||||
dot: true,
|
||||
unpack: WINDOWS_SERVER_ASAR_UNPACK_GLOB,
|
||||
globOptions: { ignore: [...WINDOWS_SERVER_ASAR_IGNORE_GLOBS] },
|
||||
globOptions: { ignore: resolveWindowsServerAsarIgnoreGlobs(input.arch) },
|
||||
}),
|
||||
catch: (cause) => new WindowsServerSidecarPackError({ asarPath: input.asarPath, cause }),
|
||||
});
|
||||
@@ -2354,7 +2378,11 @@ export const stageWindowsServerSidecar = Effect.fn("stageWindowsServerSidecar")(
|
||||
|
||||
yield* Effect.log("[desktop-artifact] Packing server.asar...");
|
||||
yield* fs.makeDirectory(path.dirname(input.asarPath), { recursive: true });
|
||||
yield* packWindowsServerAsar({ sourceDir: serverStageDir, asarPath: input.asarPath });
|
||||
yield* packWindowsServerAsar({
|
||||
sourceDir: serverStageDir,
|
||||
asarPath: input.asarPath,
|
||||
arch: input.arch,
|
||||
});
|
||||
const packedStat = yield* fs.stat(input.asarPath);
|
||||
yield* Effect.log(
|
||||
`[desktop-artifact] Packed server.asar (${String(packedStat.size)} bytes) + unpacked natives.`,
|
||||
|
||||
Reference in new issue
Block a user