Something went wrong. Try again.
Self-hosted file management and sharing system, supports multiple storage providers. forked from tdvorak.tngl.sh/cloudreve
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475import assert from "node:assert/strict";import { execFileSync } from "node:child_process";import { createHash } from "node:crypto";import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync,} from "node:fs";import { tmpdir } from "node:os";import { join, resolve } from "node:path";import { verifyBinary } from "./binary-probe.mjs";
const manifest = JSON.parse(readFileSync("package.json", "utf8"));const output = resolve(".artifacts/release");const temp = mkdtempSync(join(tmpdir(), "cloudreve-release-"));const extension = process.platform === "win32" ? ".exe" : "";const platform = { linux: "linux", darwin: "macos", win32: "windows" }[process.platform];
const tar = process.platform === "win32" ? join(process.env.SystemRoot ?? "C:\\Windows", "System32", "tar.exe") : "tar";
const run = (command, args) => execFileSync(command, args, { stdio: "inherit", timeout: 180000 });
try { mkdirSync(output, { recursive: true });
const bundle = join(temp, "bundle"); const executable = join(bundle, "cloudreve-cli" + extension);
mkdirSync(bundle); run("bun", ["scripts/build-binary.mjs", executable]);
if (process.platform === "darwin") { run("codesign", ["--force", "--sign", "-", executable]); }
copyFileSync(executable, join(bundle, "cr" + extension)); copyFileSync("LICENSE", join(bundle, "LICENSE")); copyFileSync("README.md", join(bundle, "README.md"));
const name = `cloudreve-cli-${manifest.version}-${platform}-${process.arch}.tar.gz`; const archive = join(output, name);
run(tar, ["-czf", archive, "-C", bundle, "."]);
const extracted = join(temp, "extracted with spaces");
mkdirSync(extracted); run(tar, ["-xzf", archive, "-C", extracted]);
assert.deepEqual( readdirSync(extracted).sort(), ["LICENSE", "README.md", "cloudreve-cli" + extension, "cr" + extension].sort(), );
for (const command of ["cloudreve-cli", "cr"]) { await verifyBinary(join(extracted, command + extension), manifest.version); }
writeFileSync( archive + ".sha256", `${createHash("sha256").update(readFileSync(archive)).digest("hex")} ${name}\n`, );
console.log(`Built and verified ${archive}`);} finally { rmSync(temp, { recursive: true, force: true });}