-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gabriel Basilio
committed
Dec 5, 2024
1 parent
50ab602
commit b706e4e
Showing
1 changed file
with
38 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |