Skip to content

Commit 7466069

Browse files
committed
Use UPX in CI
1 parent bc076ca commit 7466069

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

build/tasks.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { register, run } from "@coder/runner";
22
import * as fs from "fs";
33
import * as fse from "fs-extra";
4+
import * as os from "os";
45
import * as path from "path";
56
import * as zlib from "zlib";
67

@@ -30,12 +31,48 @@ const buildServerBinaryPackage = register("build:server:binary:package", async (
3031
throw new Error("Cannot build binary without web bundle built");
3132
}
3233
await buildServerBinaryCopy();
34+
await dependencyNexeBinary();
3335
const resp = await runner.execute("npm", ["run", "build:nexe"]);
3436
if (resp.exitCode !== 0) {
3537
throw new Error(`Failed to package binary: ${resp.stderr}`);
3638
}
3739
});
3840

41+
const dependencyNexeBinary = register("dependency:nexe", async (runner) => {
42+
if (os.platform() === "linux") {
43+
const nexeDir = path.join(os.homedir(), ".nexe");
44+
const targetBinaryName = `${os.platform()}-${os.arch()}-${process.version.substr(1)}`;
45+
const targetBinaryPath = path.join(nexeDir, targetBinaryName);
46+
if (!fs.existsSync(targetBinaryPath)) {
47+
/**
48+
* We create a binary with nexe
49+
* so we can compress it
50+
*/
51+
fse.mkdirpSync(nexeDir);
52+
runner.cwd = nexeDir;
53+
await runner.execute("wget", [`https://github.com/nexe/nexe/releases/download/v3.0.0-beta.15/${targetBinaryName}`]);
54+
await runner.execute("chmod", ["+x", targetBinaryPath]);
55+
}
56+
if (fs.statSync(targetBinaryPath).size >= 20000000) {
57+
// Compress w/ upx
58+
const upxFolder = path.join(os.tmpdir(), "upx");
59+
const upxBinary = path.join(upxFolder, "upx");
60+
if (!fs.existsSync(upxBinary)) {
61+
fse.mkdirpSync(upxFolder);
62+
runner.cwd = upxFolder;
63+
const upxExtract = await runner.execute("bash", ["-c", "curl -L https://github.com/upx/upx/releases/download/v3.95/upx-3.95-amd64_linux.tar.xz | tar xJ --strip-components=1"]);
64+
if (upxExtract.exitCode !== 0) {
65+
throw new Error(`Failed to extract upx: ${upxExtract.stderr}`);
66+
}
67+
}
68+
if (!fs.existsSync(upxBinary)) {
69+
throw new Error("Not sure how, but the UPX binary does not exist");
70+
}
71+
await runner.execute(upxBinary, [targetBinaryPath]);
72+
}
73+
}
74+
});
75+
3976
const buildServerBinaryCopy = register("build:server:binary:copy", async (runner) => {
4077
const cliPath = path.join(pkgsPath, "server");
4178
const cliBuildPath = path.join(cliPath, "build");

0 commit comments

Comments
 (0)