mirror of
https://github.com/Minionguyjpro/Inno-Setup-Action.git
synced 2026-04-12 18:01:24 +02:00
Improve main script, correct order of run
This commit is contained in:
116
src/index.js
116
src/index.js
@@ -1,65 +1,77 @@
|
|||||||
import * as core from "@actions/core";
|
const core = require("@actions/core");
|
||||||
import { promises as fs } from "fs";
|
const { promises: fs } = require("fs");
|
||||||
import { exec } from "child_process";
|
const { exec, execFile } = require("child_process");
|
||||||
import { execFile } from "child_process";
|
|
||||||
|
function execPromise(command) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
exec(command, (error, stdout, stderr) => {
|
||||||
|
console.log(stdout);
|
||||||
|
console.error(stderr);
|
||||||
|
if (error) {
|
||||||
|
reject(new Error(`Command failed: ${stderr}`));
|
||||||
|
} else {
|
||||||
|
resolve(stdout);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function execFilePromise(file, args) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
execFile(file, args, (error, stdout, stderr) => {
|
||||||
|
console.log(stdout);
|
||||||
|
console.error(stderr);
|
||||||
|
if (error) {
|
||||||
|
reject(new Error(`Execution failed: ${stderr}`));
|
||||||
|
} else {
|
||||||
|
resolve(stdout);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const workspacePath = process.env.GITHUB_WORKSPACE;
|
const workspacePath = process.env.GITHUB_WORKSPACE;
|
||||||
const options = core.getMultilineInput("options");
|
const options = core.getMultilineInput("options");
|
||||||
const path = core.getInput("path");
|
const path = core.getInput("path");
|
||||||
|
|
||||||
let repoError;
|
|
||||||
let platformError;
|
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
if (process.platform === "win32") {
|
if (process.platform !== "win32") {
|
||||||
let workspaceExists;
|
|
||||||
try {
|
|
||||||
await fs.access(workspacePath);
|
|
||||||
workspaceExists = true;
|
|
||||||
} catch {
|
|
||||||
workspaceExists = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const workspaceNotEmpty = (await fs.readdir(workspacePath)).length > 0;
|
|
||||||
|
|
||||||
if (workspaceExists && workspaceNotEmpty) {
|
|
||||||
const escapedOptions = options.map((str) =>
|
|
||||||
str.replace(/(["'])/g, "$1"),
|
|
||||||
);
|
|
||||||
|
|
||||||
exec(
|
|
||||||
`winget install --id JRSoftware.InnoSetup -e -s winget -h`,
|
|
||||||
(execError, stdout, stderr) => {
|
|
||||||
console.log(stdout, stderr);
|
|
||||||
if (execError) {
|
|
||||||
core.setFailed(`Failed to install Inno Setup: ${stderr}`);
|
|
||||||
process.exit(execError.code || 1);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
execFile(
|
|
||||||
`${process.env["ProgramFiles(x86)"]}\\Inno Setup 6\\iscc.exe`,
|
|
||||||
[...escapedOptions, `${workspacePath}\\${path}`],
|
|
||||||
(execError, stdout, stderr) => {
|
|
||||||
console.log(stdout, stderr);
|
|
||||||
if (execError) {
|
|
||||||
core.setFailed(`Execution failed with error: ${stderr}`);
|
|
||||||
process.exit(execError.code || 1);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
throw new Error(
|
|
||||||
"The repository was not cloned. Please specify the actions/checkout action before this step.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new Error("This action is only supported on Windows!");
|
throw new Error("This action is only supported on Windows!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!workspacePath) {
|
||||||
|
throw new Error("GITHUB_WORKSPACE is not defined.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.access(workspacePath);
|
||||||
|
} catch {
|
||||||
|
throw new Error("Workspace path does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
const files = await fs.readdir(workspacePath);
|
||||||
|
if (files.length === 0) {
|
||||||
|
throw new Error(
|
||||||
|
"The repository was not cloned. Please specify the actions/checkout action before this step."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const escapedOptions = options.map((str) => str.replace(/(["'])/g, "$1"));
|
||||||
|
|
||||||
|
// Install Inno Setup silently
|
||||||
|
await execPromise(
|
||||||
|
`winget install --id JRSoftware.InnoSetup -e -s winget -h`
|
||||||
|
);
|
||||||
|
|
||||||
|
const isccPath = `${process.env["ProgramFiles(x86)"]}\\Inno Setup 6\\iscc.exe`;
|
||||||
|
const scriptPath = `${workspacePath}\\${path}`;
|
||||||
|
|
||||||
|
await execFilePromise(isccPath, [...escapedOptions, scriptPath]);
|
||||||
|
|
||||||
|
console.log("Inno Setup script compiled successfully.");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message || "An unknown error occurred.");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user