From c3637254aaf7615b3b347e4bdb3e4563839ec9f8 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Thu, 15 Oct 2015 15:38:36 +0100 Subject: [PATCH 1/6] ignore node_modules/ --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index bb81443..396185a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ coverage test/home/.config +node_modules/ From b02ff21fc20bed3df765892e85be01a393a201c4 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Thu, 15 Oct 2015 15:41:19 +0100 Subject: [PATCH 2/6] change build run command if on windows --- lib/build.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/build.js b/lib/build.js index c3f090f..df17129 100644 --- a/lib/build.js +++ b/lib/build.js @@ -173,7 +173,11 @@ Build.prototype.runCommand = function(cmd, dir, cb) { log.verbose('[builder]', 'cmd', cmd) this.append(util.format('\n%s\n', cmd)) - var child = spawn('/bin/bash', ['-c', fixedCmd.join(' ')], opts) + if(process.platform === 'win32'){ + var child = spawn('cmd.exe', ['/C', fixedCmd.join(' ')], opts) + }else{ + var child = spawn('/bin/bash', ['-c', fixedCmd.join(' ')], opts) + } var timedout = false var timer = setTimeout(function() { timedout = true From afb66d8585081ed676d5aeef9bebd4ec809b5ae8 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Mon, 19 Oct 2015 13:27:29 +0100 Subject: [PATCH 3/6] fix some pathing and make tests work on my machine will use travis to ensure they still pass online --- .gitignore | 1 + lib/gcr.js | 5 +++-- test/gcr.js | 12 ++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 396185a..7bfbadb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ coverage test/home/.config +test/home/builds node_modules/ diff --git a/lib/gcr.js b/lib/gcr.js index 8a0f765..e6dc759 100644 --- a/lib/gcr.js +++ b/lib/gcr.js @@ -15,7 +15,8 @@ log.heading = 'gcr' module.exports = gcr -gcr.root = path.dirname(confFile) +gcr.confFile = confFile +gcr.root = path.dirname(gcr.confFile) gcr.loaded = false gcr.version = require('../package').version @@ -30,7 +31,7 @@ gcr.load = function(opts, cb) { err.heading = '[mkdirp]' return cb(err) } - nconf.file({ file: confFile }) + nconf.file({ file: gcr.confFile }) nconf.defaults(require('./config.default')(opts)) if (opts.url) { nconf.set('url', opts.url) diff --git a/test/gcr.js b/test/gcr.js index 4365a17..940abe5 100644 --- a/test/gcr.js +++ b/test/gcr.js @@ -18,6 +18,9 @@ describe('gcr', function() { port = server.address().port done() }) + + gcr.root = path.join(HOME, '.config') + gcr.confFile = path.join(HOME, '.config', 'gcr.json') }) it('should be an EventEmitter', function() { @@ -29,6 +32,11 @@ describe('gcr', function() { gcr.root.should.equal(path.join(HOME, '.config')) }) + it('should have property confFile', function(){ + should.exist(gcr.confFile) + gcr.confFile.should.equal(path.join(HOME, '.config', 'gcr.json')) + }) + it('should have property loaded', function() { gcr.loaded.should.be.false }) @@ -46,7 +54,7 @@ describe('gcr', function() { gcr.load({ url: 'http://127.0.0.1:' + port + '/ci' , token: 'biscuits' - , buildDir: '/tmp/gcr-builds' + , buildDir: __dirname + '/home/builds' , npm: true , strictSSL: false , timeout: 5000 @@ -89,7 +97,7 @@ describe('gcr', function() { build.should.have.property('opts') build.should.have.property('output') build.should.have.property('projectDir') - build.projectDir.should.equal('/tmp/gcr-builds/project-1') + build.projectDir.should.equal(__dirname + '/home/builds/project-1'.replace(/\//g, path.sep)) build.should.have.property('state', 'waiting') }) From a3b04ac6f9037f5a97c690b090b96b89663278cf Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Mon, 19 Oct 2015 13:56:50 +0100 Subject: [PATCH 4/6] implement flags to control the shell used --- README.md | 2 ++ bin/cmd.js | 4 ++++ bin/usage.txt | 2 ++ lib/build.js | 6 +----- lib/config.default.js | 3 +++ lib/gcr.js | 6 ++++++ test/gcr.js | 5 +++++ 7 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f074de3..b3ad456 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,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 ``` ## Why? diff --git a/bin/cmd.js b/bin/cmd.js index 7d0b004..8d276ed 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -20,6 +20,8 @@ var gcr = require('../lib/gcr') , strictSSL: Boolean , timeout: Number , keypath: path + , shell: path + , shellFlag: String } , shortHand = { verbose: ['--loglevel', 'verbose'] , h: ['--help'] @@ -30,6 +32,8 @@ var gcr = require('../lib/gcr') , s: ['--strictSSL'] , T: ['--timeout'] , k: ['--keypath'] + , s: ['--shell'] + , sf: ['--shellFlag'] } , parsed = nopt(knownOpts, shortHand) diff --git a/bin/usage.txt b/bin/usage.txt index 483b2a1..9555544 100644 --- a/bin/usage.txt +++ b/bin/usage.txt @@ -16,3 +16,5 @@ 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 diff --git a/lib/build.js b/lib/build.js index df17129..5a33f63 100644 --- a/lib/build.js +++ b/lib/build.js @@ -173,11 +173,7 @@ Build.prototype.runCommand = function(cmd, dir, cb) { log.verbose('[builder]', 'cmd', cmd) this.append(util.format('\n%s\n', cmd)) - if(process.platform === 'win32'){ - var child = spawn('cmd.exe', ['/C', fixedCmd.join(' ')], opts) - }else{ - var child = spawn('/bin/bash', ['-c', fixedCmd.join(' ')], opts) - } + var child = spawn(gcr.config.get('shell'), [gcr.config.get('shellFlag'), fixedCmd.join(' ')], opts) var timedout = false var timer = setTimeout(function() { timedout = true diff --git a/lib/config.default.js b/lib/config.default.js index 3e8c49c..a4e5e6c 100644 --- a/lib/config.default.js +++ b/lib/config.default.js @@ -19,5 +19,8 @@ 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 e6dc759..0a7f595 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) + } gcr.config = nconf chain([ validateGit diff --git a/test/gcr.js b/test/gcr.js index 940abe5..2ec68f7 100644 --- a/test/gcr.js +++ b/test/gcr.js @@ -74,6 +74,11 @@ describe('gcr', function() { gcr.should.have.property('config') }) + it('should set the shell options', function(){ + gcr.config.get('shell').should.exist + gcr.config.get('shellFlag').should.exist + }) + describe('build', function() { var Build = require('../lib/build') var build From 58f7dcc2c0b3b65e29a08072db4f7635ea3a395b Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Mon, 17 Oct 2016 16:19:57 +0100 Subject: [PATCH 5/6] change -sf to -f --- bin/cmd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cmd.js b/bin/cmd.js index 5c9bc9f..3f59c6e 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -38,7 +38,7 @@ var gcr = require('../lib/gcr') , T: ['--timeout'] , k: ['--keypath'] , s: ['--shell'] - , sf: ['--shellFlag'] + , f: ['--shellFlag'] , C: ['--sslcert'] , K: ['--sslkey'] , A: ['--cacert'] From a941510f9f1b98c8caa28d136bccf635b1d1aef5 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Mon, 17 Oct 2016 16:24:24 +0100 Subject: [PATCH 6/6] fix failing test on unix --- test/gcr.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/gcr.js b/test/gcr.js index 8400755..64c90cf 100644 --- a/test/gcr.js +++ b/test/gcr.js @@ -64,8 +64,8 @@ test('load', (t) => { test('shell selection', (t) => { t.plan(2) t.match(gcr.config.get('shell') - , /cmd\.exe$|\/sh$/ - , 'Shell is either cmd.exe or /bin/sh' + , /cmd\.exe$|\/bash$/ + , 'Shell is either cmd.exe or /bin/bash' ) t.match(gcr.config.get('shellFlag')