Skip to content

Commit

Permalink
Format index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Basilio committed Dec 5, 2024
1 parent 50ab602 commit b706e4e
Showing 1 changed file with 38 additions and 37 deletions.
75 changes: 38 additions & 37 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
const core = require('@actions/core');
const exec = require('@actions/exec');
/**
* Author: Gabriel Basilio
*/
const core = require("@actions/core");
const exec = require("@actions/exec");

async function main() {

try {
if (process.platform == "linux") {
await exec.exec("sudo apt-get update");
await exec.exec("sudo apt-get install -y xvfb x11-xserver-utils");
}

const commands = core.getInput('run', { required: true }).split("\n");
const directory = core.getInput('working-directory');
const serverOptions = core.getInput('options');

for (i in commands) {
if (process.platform == "linux") {
console.log('Command: ' + commands[i]);
await runCommandWithXvfb(commands[i], directory, serverOptions);
} else {
await runCommand(commands[i], directory);
}
}
try {
if (process.platform == "linux") {
await exec.exec("sudo apt-get update");
await exec.exec("sudo apt-get install -y xvfb x11-xserver-utils");
}
catch (error) {
core.setFailed(error.message);

const commands = core.getInput("run", { required: true }).split("\n");
const directory = core.getInput("working-directory");
const serverOptions = core.getInput("options");

for (i in commands) {
if (process.platform == "linux") {
console.log("Command: " + commands[i]);
await runCommandWithXvfb(commands[i], directory, serverOptions);
} else {
await runCommand(commands[i], directory);
}
}
} catch (error) {
core.setFailed(error.message);
}
}

async function runCommandWithXvfb(command, directory, options) {
const optionsArgument = options ? `-s "${options}"` : '';
command = `xvfb-run --auto-servernum ${optionsArgument} ${command}`;

try {
await runCommand(command, directory)
} finally {
await cleanUpXvfb();
}
const optionsArgument = options ? `-s "${options}"` : "";
command = `xvfb-run --auto-servernum ${optionsArgument} ${command}`;

try {
await runCommand(command, directory);
} finally {
await cleanUpXvfb();
}
}

async function cleanUpXvfb() {
try {
await exec.exec("bash", [`${__dirname}/cleanup.sh`]);
} catch {

}
try {
await exec.exec("bash", [`${__dirname}/cleanup.sh`]);
} catch {}
}

async function runCommand(command, directory) {
await (directory ? exec.exec(command, [], {cwd: directory}) : exec.exec(command));
await (directory
? exec.exec(command, [], { cwd: directory })
: exec.exec(command));
}

main();

0 comments on commit b706e4e

Please sign in to comment.