Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows command runner #20

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
coverage
test/home/.config
test/home/builds
node_modules/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path> specify path to rsa key
-s, --shell <path> specify path to shell e.g. /bin/bash
-sf, --shellFlag <flag> set the flag to run commands on your shell e.g. -c
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need single character only for - flags.

```

## Why?
Expand Down
4 changes: 4 additions & 0 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -30,6 +32,8 @@ var gcr = require('../lib/gcr')
, s: ['--strictSSL']
, T: ['--timeout']
, k: ['--keypath']
, s: ['--shell']
, sf: ['--shellFlag']
}
, parsed = nopt(knownOpts, shortHand)

Expand Down
2 changes: 2 additions & 0 deletions bin/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path> specify path to rsa key
-s, --shell <path> specify path to shell e.g. /bin/bash
-sf, --shellFlag <flag> set the flag to run commands on your shell e.g. -c
2 changes: 1 addition & 1 deletion lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ 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)
var child = spawn(gcr.config.get('shell'), [gcr.config.get('shellFlag'), fixedCmd.join(' ')], opts)
var timedout = false
var timer = setTimeout(function() {
timedout = true
Expand Down
3 changes: 3 additions & 0 deletions lib/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 9 additions & 2 deletions lib/gcr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -56,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
Expand Down
17 changes: 15 additions & 2 deletions test/gcr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
})
Expand All @@ -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
Expand All @@ -66,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
Expand All @@ -89,7 +102,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')
})

Expand Down