mirror of
https://github.com/Minionguyjpro/Inno-Setup-Action
synced 2026-02-18 17:41:18 +01:00
src/index.js: Optimize code for better performance and strategies
This commit is contained in:
65
src/index.js
65
src/index.js
@@ -1,55 +1,42 @@
|
|||||||
// Importing necessary modules
|
|
||||||
const core = require("@actions/core");
|
const core = require("@actions/core");
|
||||||
const fs = require("fs");
|
const fs = require("fs").promises;
|
||||||
|
const { execFile } = require("child_process");
|
||||||
|
|
||||||
// Getting the path to the workspace from environment variables
|
|
||||||
const workspacePath = process.env.GITHUB_WORKSPACE;
|
const workspacePath = process.env.GITHUB_WORKSPACE;
|
||||||
|
|
||||||
// Getting inputs from the workflow
|
|
||||||
const options = core.getInput("options");
|
const options = core.getInput("options");
|
||||||
const path = core.getInput("path");
|
const path = core.getInput("path");
|
||||||
|
|
||||||
// Importing the child_process module for executing shell commands
|
|
||||||
const exec = require("child_process").exec;
|
|
||||||
|
|
||||||
// Initializing error variables
|
|
||||||
let repoError;
|
let repoError;
|
||||||
let platformError;
|
let platformError;
|
||||||
|
|
||||||
// Checking if the platform is Windows
|
async function run() {
|
||||||
if (process.platform === "win32") {
|
try {
|
||||||
// Checking if the GitHub workspace exists and is not empty
|
if (process.platform === "win32") {
|
||||||
if (
|
const workspaceExists = await fs.access(workspacePath).then(() => true).catch(() => false);
|
||||||
fs.existsSync(process.env.GITHUB_WORKSPACE) &&
|
const workspaceNotEmpty = (await fs.readdir(workspacePath)).length > 0;
|
||||||
fs.readdirSync(workspacePath).length > 0
|
|
||||||
) {
|
|
||||||
// Building and executing the Inno Setup compiler command
|
|
||||||
exec(
|
|
||||||
`"%PROGRAMFILES(X86)%\\Inno Setup 6\\iscc.exe" ${options} "${workspacePath}\\${path}"`,
|
|
||||||
{ stdio: "ignore" },
|
|
||||||
function (execError, stdout, stderr) {
|
|
||||||
// Logging the standard output of the command
|
|
||||||
console.log(stdout);
|
|
||||||
|
|
||||||
// Handling errors, if any
|
if (workspaceExists && workspaceNotEmpty) {
|
||||||
|
execFile(
|
||||||
|
`${process.env.ProgramFiles(x86)}\\Inno Setup 6\\iscc.exe`,
|
||||||
|
[options, `${workspacePath}\\${path}`],
|
||||||
|
(execError, stdout, stderr) => {
|
||||||
|
console.log(stdout);
|
||||||
if (execError) {
|
if (execError) {
|
||||||
repoError = { code: execError.code || 1 };
|
core.setFailed(`Execution failed with error: ${stderr}`);
|
||||||
core.setFailed(stderr);
|
process.exit(execError.code || 1);
|
||||||
process.exit(repoError.code);
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Setting an error code and failing the workflow if the repository is not cloned
|
throw new Error("The repository was not cloned. Please specify the actions/checkout action before this step.");
|
||||||
repoError = { code: 1 };
|
}
|
||||||
core.setFailed(
|
} else {
|
||||||
"The repository was not cloned. Please specify the actions/checkout action before this step.",
|
throw new Error("This action is only supported on Windows!");
|
||||||
);
|
}
|
||||||
process.exit(repoError.code);
|
} catch (error) {
|
||||||
|
core.setFailed(error.message);
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Setting an error code and failing the workflow if the platform is not Windows
|
|
||||||
platformError = { code: 1 };
|
|
||||||
core.setFailed("This action is only supported on Windows!");
|
|
||||||
process.exit(platformError.code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
|
|||||||
Reference in New Issue
Block a user