1
0
mirror of https://github.com/Minionguyjpro/Inno-Setup-Action synced 2026-02-18 09:31:19 +01:00

Update CJS script (automated by GitHub Actions)

This commit is contained in:
github-actions[bot]
2024-01-08 19:08:20 +00:00
parent 504af95050
commit 91777ef9eb
3 changed files with 45 additions and 36 deletions

View File

@@ -1,11 +1,11 @@
// main.test.js // main.test.js
const core = require('@actions/core'); const core = require("@actions/core");
const fs = require('fs'); const fs = require("fs");
const main = require('../src/main'); const main = require("../src/main");
// Mocking fs.promises for the test // Mocking fs.promises for the test
jest.mock('fs', () => { jest.mock("fs", () => {
const originalFs = jest.requireActual('fs'); const originalFs = jest.requireActual("fs");
return { return {
...originalFs, ...originalFs,
promises: { promises: {
@@ -13,18 +13,18 @@ jest.mock('fs', () => {
}, },
}; };
}); });
const child_process = require('child_process'); const child_process = require("child_process");
jest.mock('@actions/core'); jest.mock("@actions/core");
jest.mock('child_process'); jest.mock("child_process");
describe('Inno Setup Action', () => { describe("Inno Setup Action", () => {
beforeEach(() => { beforeEach(() => {
jest.resetAllMocks(); jest.resetAllMocks();
}); });
it('should execute Inno Setup command on Windows with existing workspace', () => { it("should execute Inno Setup command on Windows with existing workspace", () => {
process.platform = 'win32'; process.platform = "win32";
main(); main();
expect(core.getInput).toHaveBeenCalledTimes(2); expect(core.getInput).toHaveBeenCalledTimes(2);

View File

@@ -1,6 +1,6 @@
/** /**
* The entrypoint for the action. * The entrypoint for the action.
*/ */
const { run } = require('./main') const { run } = require("./main");
run() run();

View File

@@ -1,46 +1,55 @@
// Importing necessary modules // Importing necessary modules
const core = require('@actions/core') const core = require("@actions/core");
const fs = require('fs') const fs = require("fs");
// Getting the path to the workspace from environment variables // 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 // 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 // Importing the child_process module for executing shell commands
const exec = require('child_process').exec const exec = require("child_process").exec;
// Initializing error variables // Initializing error variables
let repoError; let repoError;
let platformError; let platformError;
// Checking if the platform is Windows // Checking if the platform is Windows
if (process.platform === 'win32') { if (process.platform === "win32") {
// Checking if the GitHub workspace exists and is not empty // Checking if the GitHub workspace exists and is not empty
if (fs.existsSync(process.env.GITHUB_WORKSPACE) && fs.readdirSync(workspacePath).length > 0) { if (
fs.existsSync(process.env.GITHUB_WORKSPACE) &&
fs.readdirSync(workspacePath).length > 0
) {
// Building and executing the Inno Setup compiler command // 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) { exec(
// Logging the standard output of the command `"%PROGRAMFILES(X86)%\\Inno Setup 6\\iscc.exe" ${options} "${workspacePath}\\${path}"`,
console.log(stdout) { stdio: "ignore" },
function (execError, stdout, stderr) {
// Logging the standard output of the command
console.log(stdout);
// Handling errors, if any // Handling errors, if any
if (execError) { if (execError) {
repoError = { code: execError.code || 1 }; repoError = { code: execError.code || 1 };
core.setFailed(stderr); core.setFailed(stderr);
process.exit(repoError.code); process.exit(repoError.code);
} }
}); },
);
} else { } else {
// Setting an error code and failing the workflow if the repository is not cloned // Setting an error code and failing the workflow if the repository is not cloned
repoError = { code: 1 } repoError = { code: 1 };
core.setFailed('The repository was not cloned. Please specify the actions/checkout action before this step.'); core.setFailed(
process.exit(repoError.code) "The repository was not cloned. Please specify the actions/checkout action before this step.",
);
process.exit(repoError.code);
} }
} else { } else {
// Setting an error code and failing the workflow if the platform is not Windows // Setting an error code and failing the workflow if the platform is not Windows
platformError = { code: 1 }; platformError = { code: 1 };
core.setFailed('This action is only supported on Windows!') core.setFailed("This action is only supported on Windows!");
process.exit(platformError.code) process.exit(platformError.code);
} }