From 3ef002d02d1b53807a9a713dc4321fd377a53309 Mon Sep 17 00:00:00 2001 From: lekristapino Date: Wed, 16 Nov 2022 02:06:51 +0200 Subject: [PATCH 1/4] Add option to skip sudo --- action.yml | 4 +++- cleanup.sh | 3 ++- index.js | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index f9cd75d..81eff46 100644 --- a/action.yml +++ b/action.yml @@ -2,11 +2,13 @@ name: 'gabrielbb/xvfb-action' description: 'Run your headless tests with XVFB' branding: icon: airplay - color: black + color: white inputs: run: description: 'Command to execute using xvfb' required: true + skip-sudo: + description: "Add this option with any value, if you want to run commands without sudo" working-directory: description: 'Directory to execute command on, defaults to ./' required: false diff --git a/cleanup.sh b/cleanup.sh index 3c9b3fd..1f6edaa 100644 --- a/cleanup.sh +++ b/cleanup.sh @@ -1,11 +1,12 @@ #!/bin/bash #author Bret Comnes +SUDO_PREFIX=${1:+sudo} kill_xvfb () { local xvfb_pids=`ps aux | grep tmp/xvfb-run | grep -v grep | awk '{print $2}'` if [ "$xvfb_pids" != "" ]; then echo "Killing the following xvfb processes: $xvfb_pids" - sudo kill $xvfb_pids + $SUDO_PREFIX kill $xvfb_pids else echo "No xvfb processes to kill" fi diff --git a/index.js b/index.js index 1a37f3f..65636a6 100644 --- a/index.js +++ b/index.js @@ -4,8 +4,10 @@ const exec = require('@actions/exec'); async function main() { try { + const skipSudo = !!core.getInput('skip-sudo'); + const sudoPrefix = skipSudo ? '' : 'sudo '; if (process.platform == "linux") { - await exec.exec("sudo apt-get install -y xvfb"); + await exec.exec(`${sudoPrefix} apt-get install -y xvfb`); } const commands = core.getInput('run', { required: true }).split("\n"); From 2b23b6952e29c65420f568b86986810b78f203d7 Mon Sep 17 00:00:00 2001 From: lekristapino Date: Wed, 16 Nov 2022 02:07:26 +0200 Subject: [PATCH 2/4] Revery previous value for branding --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 81eff46..15c2a07 100644 --- a/action.yml +++ b/action.yml @@ -2,7 +2,7 @@ name: 'gabrielbb/xvfb-action' description: 'Run your headless tests with XVFB' branding: icon: airplay - color: white + color: black inputs: run: description: 'Command to execute using xvfb' From 3f41d5b83284876ccf39d1c799d1bb70def1e4e6 Mon Sep 17 00:00:00 2001 From: lekristapino Date: Wed, 16 Nov 2022 02:11:56 +0200 Subject: [PATCH 3/4] Add sudo prefix usage in cleanup call --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 65636a6..e592273 100644 --- a/index.js +++ b/index.js @@ -41,7 +41,7 @@ async function runCommandWithXvfb(command, directory, options) { async function cleanUpXvfb() { try { - await exec.exec("bash", [`${__dirname}/cleanup.sh`]); + await exec.exec("bash", [`${__dirname}/cleanup.sh ${sudoPrefix}`]); } catch { } From d88edd2a2e8b82d26b272c413ef951e1ee12a1cf Mon Sep 17 00:00:00 2001 From: lekristapino Date: Wed, 16 Nov 2022 02:31:05 +0200 Subject: [PATCH 4/4] Don't need option for trying without sudo --- action.yml | 2 -- cleanup.sh | 3 +-- index.js | 17 ++++++++++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index 15c2a07..f9cd75d 100644 --- a/action.yml +++ b/action.yml @@ -7,8 +7,6 @@ inputs: run: description: 'Command to execute using xvfb' required: true - skip-sudo: - description: "Add this option with any value, if you want to run commands without sudo" working-directory: description: 'Directory to execute command on, defaults to ./' required: false diff --git a/cleanup.sh b/cleanup.sh index 1f6edaa..c5401a0 100644 --- a/cleanup.sh +++ b/cleanup.sh @@ -1,12 +1,11 @@ #!/bin/bash #author Bret Comnes -SUDO_PREFIX=${1:+sudo} kill_xvfb () { local xvfb_pids=`ps aux | grep tmp/xvfb-run | grep -v grep | awk '{print $2}'` if [ "$xvfb_pids" != "" ]; then echo "Killing the following xvfb processes: $xvfb_pids" - $SUDO_PREFIX kill $xvfb_pids + kill $xvfb_pids else echo "No xvfb processes to kill" fi diff --git a/index.js b/index.js index e592273..5cbca96 100644 --- a/index.js +++ b/index.js @@ -4,10 +4,13 @@ const exec = require('@actions/exec'); async function main() { try { - const skipSudo = !!core.getInput('skip-sudo'); - const sudoPrefix = skipSudo ? '' : 'sudo '; if (process.platform == "linux") { - await exec.exec(`${sudoPrefix} apt-get install -y xvfb`); + try { + await exec.exec(`sudo apt-get install -y xvfb`); + } catch(error) { + core.debug("Failed to install xvfb with sudo, trying without"); + await exec.exec(`apt-get install -y xvfb`); + } } const commands = core.getInput('run', { required: true }).split("\n"); @@ -41,9 +44,13 @@ async function runCommandWithXvfb(command, directory, options) { async function cleanUpXvfb() { try { - await exec.exec("bash", [`${__dirname}/cleanup.sh ${sudoPrefix}`]); + try { + await exec.exec("bash", [`sudo ${__dirname}/cleanup.sh`]); + } catch { + await exec.exec("bash", [`${__dirname}/cleanup.sh`]); + } } catch { - + core.debug('Cleanup failed'); } }