🎨 update github actions performance

This commit is contained in:
Tw93
2025-08-20 15:52:30 +08:00
parent facdfb564e
commit fe10dc7848
4 changed files with 45 additions and 56 deletions

View File

@@ -1,7 +1,7 @@
import fs from "fs";
import path from "path";
import axios from "axios";
import { execa } from "execa";
// We'll call the CLI directly for icon handling
// Configuration logging
const logConfiguration = () => {
@@ -58,33 +58,7 @@ const buildParameters = () => {
return params;
};
// Icon download handling
const downloadIcon = async (iconFile) => {
try {
const response = await axios.get(process.env.ICON, {
responseType: "arraybuffer",
});
fs.writeFileSync(iconFile, response.data);
return ["--icon", iconFile];
} catch (error) {
console.error("Error occurred during icon download:", error);
throw error;
}
};
// Get icon file name based on platform
const getIconFileName = () => {
switch (process.platform) {
case "linux":
return "icon.png";
case "darwin":
return "icon.icns";
case "win32":
return "icon.ico";
default:
throw new Error("Unable to detect your OS system");
}
};
// Icon will be handled directly by CLI
// Main execution
const main = async () => {
@@ -97,24 +71,16 @@ const main = async () => {
let params = buildParameters();
// Multi-arch target is now handled in GitHub Actions workflow
// Download icon in parallel with parameter preparation if needed
let iconPromise = null;
// Add icon parameter if provided - CLI will handle download and conversion
if (process.env.ICON && process.env.ICON !== "") {
const iconFile = getIconFileName();
iconPromise = downloadIcon(iconFile);
params.push("--icon", process.env.ICON);
} else {
console.log(
"Won't download the icon as ICON environment variable is not defined!",
"Won't use icon as ICON environment variable is not defined!",
);
}
// If icon is being downloaded, wait for it and add to params
if (iconPromise) {
const iconParams = await iconPromise;
params.push(...iconParams);
}
console.log("Pake parameters:", params.join(" "));
console.log("Compiling....");
@@ -129,19 +95,25 @@ const main = async () => {
// Move built files to output directory more efficiently
const buildPaths = [
`src-tauri/target/release/bundle`,
`src-tauri/target/universal-apple-darwin/release/bundle`
`src-tauri/target/universal-apple-darwin/release/bundle`,
];
for (const buildPath of buildPaths) {
if (fs.existsSync(buildPath)) {
const bundleFiles = fs.readdirSync(buildPath, { recursive: true })
.filter(file => {
const bundleFiles = fs
.readdirSync(buildPath, { recursive: true })
.filter((file) => {
const fullPath = path.join(buildPath, file);
return fs.statSync(fullPath).isFile() &&
(file.endsWith('.dmg') || file.endsWith('.exe') ||
file.endsWith('.deb') || file.endsWith('.rpm') || file.endsWith('.AppImage'));
return (
fs.statSync(fullPath).isFile() &&
(file.endsWith(".dmg") ||
file.endsWith(".exe") ||
file.endsWith(".deb") ||
file.endsWith(".rpm") ||
file.endsWith(".AppImage"))
);
});
for (const file of bundleFiles) {
const srcPath = path.join(buildPath, file);
const destPath = path.join("output", path.basename(file));
@@ -150,7 +122,7 @@ const main = async () => {
break; // Found files, no need to check other paths
}
}
// Fallback to original method if no bundle files found
const files = fs.readdirSync(".");
const namePattern = new RegExp(`^${process.env.NAME}\\..*$`);
@@ -161,7 +133,7 @@ const main = async () => {
foundFiles = true;
}
}
if (!foundFiles) {
console.log("Warning: No output files found matching pattern");
}