|
1 |
| -const core = require('@actions/core'); |
2 |
| -const exec = require('@actions/exec'); |
| 1 | +/** |
| 2 | + * Author: Gabriel Basilio |
| 3 | + */ |
| 4 | +const core = require("@actions/core"); |
| 5 | +const exec = require("@actions/exec"); |
3 | 6 |
|
4 | 7 | async function main() {
|
5 |
| - |
6 |
| - try { |
7 |
| - if (process.platform == "linux") { |
8 |
| - await exec.exec("sudo apt-get update"); |
9 |
| - await exec.exec("sudo apt-get install -y xvfb x11-xserver-utils"); |
10 |
| - } |
11 |
| - |
12 |
| - const commands = core.getInput('run', { required: true }).split("\n"); |
13 |
| - const directory = core.getInput('working-directory'); |
14 |
| - const serverOptions = core.getInput('options'); |
15 |
| - |
16 |
| - for (i in commands) { |
17 |
| - if (process.platform == "linux") { |
18 |
| - console.log('Command: ' + commands[i]); |
19 |
| - await runCommandWithXvfb(commands[i], directory, serverOptions); |
20 |
| - } else { |
21 |
| - await runCommand(commands[i], directory); |
22 |
| - } |
23 |
| - } |
| 8 | + try { |
| 9 | + if (process.platform == "linux") { |
| 10 | + await exec.exec("sudo apt-get update"); |
| 11 | + await exec.exec("sudo apt-get install -y xvfb x11-xserver-utils"); |
24 | 12 | }
|
25 |
| - catch (error) { |
26 |
| - core.setFailed(error.message); |
| 13 | + |
| 14 | + const commands = core.getInput("run", { required: true }).split("\n"); |
| 15 | + const directory = core.getInput("working-directory"); |
| 16 | + const serverOptions = core.getInput("options"); |
| 17 | + |
| 18 | + for (i in commands) { |
| 19 | + if (process.platform == "linux") { |
| 20 | + console.log("Command: " + commands[i]); |
| 21 | + await runCommandWithXvfb(commands[i], directory, serverOptions); |
| 22 | + } else { |
| 23 | + await runCommand(commands[i], directory); |
| 24 | + } |
27 | 25 | }
|
| 26 | + } catch (error) { |
| 27 | + core.setFailed(error.message); |
| 28 | + } |
28 | 29 | }
|
29 | 30 |
|
30 | 31 | async function runCommandWithXvfb(command, directory, options) {
|
31 |
| - const optionsArgument = options ? `-s "${options}"` : ''; |
32 |
| - command = `xvfb-run --auto-servernum ${optionsArgument} ${command}`; |
33 |
| - |
34 |
| - try { |
35 |
| - await runCommand(command, directory) |
36 |
| - } finally { |
37 |
| - await cleanUpXvfb(); |
38 |
| - } |
| 32 | + const optionsArgument = options ? `-s "${options}"` : ""; |
| 33 | + command = `xvfb-run --auto-servernum ${optionsArgument} ${command}`; |
| 34 | + |
| 35 | + try { |
| 36 | + await runCommand(command, directory); |
| 37 | + } finally { |
| 38 | + await cleanUpXvfb(); |
| 39 | + } |
39 | 40 | }
|
40 | 41 |
|
41 | 42 | async function cleanUpXvfb() {
|
42 |
| - try { |
43 |
| - await exec.exec("bash", [`${__dirname}/cleanup.sh`]); |
44 |
| - } catch { |
45 |
| - |
46 |
| - } |
| 43 | + try { |
| 44 | + await exec.exec("bash", [`${__dirname}/cleanup.sh`]); |
| 45 | + } catch {} |
47 | 46 | }
|
48 | 47 |
|
49 | 48 | async function runCommand(command, directory) {
|
50 |
| - await (directory ? exec.exec(command, [], {cwd: directory}) : exec.exec(command)); |
| 49 | + await (directory |
| 50 | + ? exec.exec(command, [], { cwd: directory }) |
| 51 | + : exec.exec(command)); |
51 | 52 | }
|
52 | 53 |
|
53 | 54 | main();
|
0 commit comments