diff --git a/.gitignore b/.gitignore index c5bbe22..c8ba63b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ coverage test/home/.config +test/home/builds .nyc_output node_modules/ diff --git a/README.md b/README.md index 0faaa07..2a5a258 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ gcr - a gitlab ci runner -s, --strictSSL enable/disable strict ssl -n, --npm run npm install/test if no commands are present -k, --keypath specify path to rsa key + -s, --shell specify path to shell e.g. /bin/bash + -sf, --shellFlag set the flag to run commands on your shell e.g. -c -C, --sslcert enable/disable strict ssl -K, --sslkey run npm install/test if no commands are present -A, --cacert specify path to rsa key diff --git a/bin/cmd.js b/bin/cmd.js index 130d498..3f59c6e 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -22,6 +22,8 @@ var gcr = require('../lib/gcr') , strictSSL: Boolean , timeout: Number , keypath: path + , shell: path + , shellFlag: String , sslcert: path , sslkey: path , cacert: path @@ -35,6 +37,8 @@ var gcr = require('../lib/gcr') , s: ['--strictSSL'] , T: ['--timeout'] , k: ['--keypath'] + , s: ['--shell'] + , f: ['--shellFlag'] , C: ['--sslcert'] , K: ['--sslkey'] , A: ['--cacert'] diff --git a/bin/usage.txt b/bin/usage.txt index be53180..5c97c0d 100644 --- a/bin/usage.txt +++ b/bin/usage.txt @@ -16,6 +16,8 @@ gcr - a gitlab ci runner -s, --strictSSL enable/disable strict ssl -n, --npm run npm install/test if no commands are present -k, --keypath specify path to rsa key + -s, --shell specify path to shell e.g. /bin/bash + -sf, --shellFlag set the flag to run commands on your shell e.g. -c -C, --sslcert enable/disable strict ssl -K, --sslkey run npm install/test if no commands are present -A, --cacert specify path to rsa key diff --git a/lib/build.js b/lib/build.js index 36592af..fc4314f 100644 --- a/lib/build.js +++ b/lib/build.js @@ -188,7 +188,12 @@ Build.prototype.runCommand = function(cmd, dir, cb) { log.verbose('[builder]', 'cmd', cmd) this.append(`\n${cmd}\n`) - const child = spawn('/bin/sh', ['-c', fixedCmd.join(' ')], opts) + const child = spawn( + gcr.config.get('shell') + , [gcr.config.get('shellFlag') + , fixedCmd.join(' ')] + , opts + ) var timedout = false var timer = setTimeout(() => { timedout = true diff --git a/lib/config.default.js b/lib/config.default.js index af02855..75c8b9a 100644 --- a/lib/config.default.js +++ b/lib/config.default.js @@ -24,5 +24,16 @@ module.exports = function(parsed) { o.strictSSL = parsed.hasOwnProperty('strictSSL') ? parsed.strictSSL : true + + o.shell = parsed.shell + ? parsed.shell + : isWin + ? 'C:\\Windows\\System32\\cmd.exe' + : '/bin/bash' + o.shellFlag = parsed.shellFlag + ? parsed.shellFlag + : isWin + ? '/C' + : '-c' return o } diff --git a/lib/gcr.js b/lib/gcr.js index 20997b9..a2038e6 100644 --- a/lib/gcr.js +++ b/lib/gcr.js @@ -57,6 +57,12 @@ gcr.load = function(opts, cb) { if (opts.keypath) { nconf.set('keypath', opts.keypath) } + if (opts.shell) { + nconf.set('shell', opts.shell) + } + if (opts.shellFlag) { + nconf.set('shellFlag', opts.shellFlag) + } if (opts.sslcert) { nconf.set('sslcert', opts.sslcert) } diff --git a/test/gcr.js b/test/gcr.js index c4d5be3..64c90cf 100644 --- a/test/gcr.js +++ b/test/gcr.js @@ -29,8 +29,10 @@ test('setup', (t) => { }) test('gcr', (t) => { + var home = require('os-homedir')() + t.type(gcr, EE) - t.equal(gcr.root, path.join(HOME, '.config'), 'gcr.root is correct') + t.equal(gcr.root, path.join(home, '.config'), 'gcr.root is correct') t.equal(gcr.loaded, false, 'gcr.loaded is false') t.equal(gcr.version, require('../package').version, 'gcr.version is correct') t.ok(gcr.hasOwnProperty('utils'), 'hasOwnProperty(utils)') @@ -59,6 +61,19 @@ test('load', (t) => { }) }) +test('shell selection', (t) => { + t.plan(2) + t.match(gcr.config.get('shell') + , /cmd\.exe$|\/bash$/ + , 'Shell is either cmd.exe or /bin/bash' + ) + + t.match(gcr.config.get('shellFlag') + , /[-/][cC]/ + , 'Shell Flag is either -c or /C' + ) +}) + test('build and run with clone', (t) => { t.plan(11) const build = Build({ @@ -79,7 +94,7 @@ test('build and run with clone', (t) => { t.ok(build.hasOwnProperty('opts'), 'hasOwnProperty(opts)') t.ok(build.hasOwnProperty('output'), 'hasOwnProperty(output)') t.ok(build.hasOwnProperty('projectDir'), 'hasOwnProperty(projectDir)') - t.equal(build.projectDir, '/tmp/gcr-builds/project-1') + t.equal(build.projectDir, path.join('/', 'tmp', 'gcr-builds', 'project-1')) t.equal(build.state, 'waiting') const orig = build.update @@ -117,7 +132,7 @@ test('build and run with fetch', (t) => { t.ok(build.hasOwnProperty('opts'), 'hasOwnProperty(opts)') t.ok(build.hasOwnProperty('output'), 'hasOwnProperty(output)') t.ok(build.hasOwnProperty('projectDir'), 'hasOwnProperty(projectDir)') - t.equal(build.projectDir, '/tmp/gcr-builds/project-2') + t.equal(build.projectDir, path.join('/', 'tmp', 'gcr-builds', 'project-2')) t.equal(build.state, 'waiting') const updateOrig = gcr.client.updateBuild