-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathindex.js
52 lines (42 loc) · 1.37 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const core = require('@actions/core');
const exec = require('@actions/exec');
async function main() {
try {
if (process.platform == "linux") {
await exec.exec("sudo apt-get install -y xvfb");
}
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();
}
}
async function cleanUpXvfb() {
try {
await exec.exec("bash", [`${__dirname}/cleanup.sh`]);
} catch {
}
}
async function runCommand(command, directory) {
await (directory ? exec.exec(command, [], {cwd: directory}) : exec.exec(command));
}
main();