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
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
coverage
test/home/.config
test/home/builds
.nyc_output
node_modules/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <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.

-C, --sslcert <path> enable/disable strict ssl
-K, --sslkey <path> run npm install/test if no commands are present
-A, --cacert <path> specify path to rsa key
4 changes: 4 additions & 0 deletions bin/cmd.js
Original file line number Diff line number Diff line change
@@ -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']
2 changes: 2 additions & 0 deletions bin/usage.txt
Original file line number Diff line number Diff line change
@@ -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 <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
-C, --sslcert <path> enable/disable strict ssl
-K, --sslkey <path> run npm install/test if no commands are present
-A, --cacert <path> specify path to rsa key
7 changes: 6 additions & 1 deletion lib/build.js
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions lib/config.default.js
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions lib/gcr.js
Original file line number Diff line number Diff line change
@@ -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)
}
21 changes: 18 additions & 3 deletions test/gcr.js
Original file line number Diff line number Diff line change
@@ -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'))
Copy link
Author

Choose a reason for hiding this comment

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

This fixes the tests having the path seperator / hard coded. Windows can pass this no problem but its returned paths use \

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