2022-03-13 00:52:31 +08:00
|
|
|
import fs from "fs-extra";
|
|
|
|
import path from "path";
|
|
|
|
import AdmZip from "adm-zip";
|
|
|
|
import { createRequire } from "module";
|
|
|
|
import { getOctokit, context } from "@actions/github";
|
|
|
|
|
2023-12-03 15:35:31 +08:00
|
|
|
const target = process.argv.slice(2)[0];
|
2024-02-15 18:43:20 +08:00
|
|
|
const alpha = process.argv.slice(2)[1];
|
2023-12-03 15:35:31 +08:00
|
|
|
|
|
|
|
const ARCH_MAP = {
|
|
|
|
"x86_64-pc-windows-msvc": "x64",
|
2024-05-06 13:03:52 +08:00
|
|
|
"i686-pc-windows-msvc": "x86",
|
2023-12-10 17:14:48 +08:00
|
|
|
"aarch64-pc-windows-msvc": "arm64",
|
2023-12-03 15:35:31 +08:00
|
|
|
};
|
|
|
|
|
2024-05-06 19:13:08 +08:00
|
|
|
const PROCESS_MAP = {
|
|
|
|
x64: "x64",
|
|
|
|
ia32: "x86",
|
|
|
|
arm64: "arm64",
|
|
|
|
};
|
|
|
|
const arch = target ? ARCH_MAP[target] : PROCESS_MAP[process.arch];
|
2022-03-13 00:52:31 +08:00
|
|
|
/// Script for ci
|
|
|
|
/// 打包绿色版/便携版 (only Windows)
|
2022-04-13 01:17:40 +08:00
|
|
|
async function resolvePortable() {
|
2022-03-13 00:52:31 +08:00
|
|
|
if (process.platform !== "win32") return;
|
|
|
|
|
2023-12-05 12:52:26 +08:00
|
|
|
const releaseDir = target
|
|
|
|
? `./src-tauri/target/${target}/release`
|
|
|
|
: `./src-tauri/target/release`;
|
|
|
|
const configDir = path.join(releaseDir, ".config");
|
2022-03-13 00:52:31 +08:00
|
|
|
|
|
|
|
if (!(await fs.pathExists(releaseDir))) {
|
|
|
|
throw new Error("could not found the release dir");
|
|
|
|
}
|
|
|
|
|
2023-12-05 12:52:26 +08:00
|
|
|
await fs.mkdir(configDir);
|
|
|
|
await fs.createFile(path.join(configDir, "PORTABLE"));
|
|
|
|
|
2022-03-13 00:52:31 +08:00
|
|
|
const zip = new AdmZip();
|
|
|
|
|
|
|
|
zip.addLocalFile(path.join(releaseDir, "Clash Verge.exe"));
|
2024-06-19 10:04:28 +08:00
|
|
|
zip.addLocalFile(path.join(releaseDir, "verge-mihomo.exe"));
|
|
|
|
zip.addLocalFile(path.join(releaseDir, "verge-mihomo-alpha.exe"));
|
2022-03-13 00:52:31 +08:00
|
|
|
zip.addLocalFolder(path.join(releaseDir, "resources"), "resources");
|
2023-12-05 12:52:26 +08:00
|
|
|
zip.addLocalFolder(configDir, ".config");
|
2022-03-13 00:52:31 +08:00
|
|
|
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
const packageJson = require("../package.json");
|
|
|
|
const { version } = packageJson;
|
|
|
|
|
2024-05-06 19:13:08 +08:00
|
|
|
const zipFile = `Clash.Verge_${version}_${arch}_portable.zip`;
|
2022-03-13 00:52:31 +08:00
|
|
|
zip.writeZip(zipFile);
|
|
|
|
|
2022-04-13 01:17:40 +08:00
|
|
|
console.log("[INFO]: create portable zip successfully");
|
2022-03-13 00:52:31 +08:00
|
|
|
|
|
|
|
// push release assets
|
|
|
|
if (process.env.GITHUB_TOKEN === undefined) {
|
|
|
|
throw new Error("GITHUB_TOKEN is required");
|
|
|
|
}
|
|
|
|
|
|
|
|
const options = { owner: context.repo.owner, repo: context.repo.repo };
|
|
|
|
const github = getOctokit(process.env.GITHUB_TOKEN);
|
2024-02-15 18:43:20 +08:00
|
|
|
const tag = alpha ? "alpha" : process.env.TAG_NAME || `v${version}`;
|
|
|
|
console.log("[INFO]: upload to ", tag);
|
2022-05-17 02:46:15 +08:00
|
|
|
|
|
|
|
const { data: release } = await github.rest.repos.getReleaseByTag({
|
|
|
|
...options,
|
2024-02-15 18:43:20 +08:00
|
|
|
tag,
|
|
|
|
});
|
|
|
|
|
|
|
|
let assets = release.assets.filter((x) => {
|
|
|
|
return x.name === zipFile;
|
2022-05-17 02:46:15 +08:00
|
|
|
});
|
2024-02-15 18:43:20 +08:00
|
|
|
if (assets.length > 0) {
|
|
|
|
let id = assets[0].id;
|
|
|
|
await github.rest.repos.deleteReleaseAsset({
|
|
|
|
...options,
|
|
|
|
asset_id: id,
|
|
|
|
});
|
|
|
|
}
|
2022-05-17 02:46:15 +08:00
|
|
|
|
|
|
|
console.log(release.name);
|
|
|
|
|
|
|
|
await github.rest.repos.uploadReleaseAsset({
|
|
|
|
...options,
|
|
|
|
release_id: release.id,
|
|
|
|
name: zipFile,
|
|
|
|
data: zip.toBuffer(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-22 00:16:30 +08:00
|
|
|
resolvePortable().catch(console.error);
|