-
Notifications
You must be signed in to change notification settings - Fork 7
/
worker.js
67 lines (61 loc) · 1.77 KB
/
worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var fs = require('fs')
, path = require('path');
require('js-yaml');
var TRAVIS_YML = '.travis.yml';
var runScript = function(ctx, phase, script, cb) {
if (typeof(script) === 'string') {
return runCmd(ctx, phase, script, cb);
}
// assume it's a list of shell commands
var next = function (i) {
runCmd(ctx, phase, script[i], function (exitCode) {
if (exitCode !== 0 || i + 1 >= script.length) return cb(exitCode);
next(i + 1);
});
};
next(0);
};
var runCmd = function(ctx, phase, cmd, cb){
var sh = ctx.shellWrap(cmd);
ctx.forkProc(ctx.workingDir, sh.cmd, sh.args, function(exitCode) {
if (exitCode !== 0) {
ctx.striderMessage("Custom " + phase + " command `" +
cmd + "` failed with exit code " + exitCode);
return cb(exitCode);
}
return cb(0);
});
};
module.exports = function (ctx, cb) {
ctx.addDetectionRule({
filename:TRAVIS_YML,
exists: true,
language: 'travis',
framework: null,
prepare:function (ctx, cb) {
var config;
try {
config = require(path.join(ctx.workingDir, TRAVIS_YML));
} catch (e) {
cb(null);
}
ctx.travisConfig = config;
var prepare = [];
if (config.install) {
runScript(ctx, 'prepare', config.install, function (err) {
if (err) return cb(err);
if (!config.before_script) return cb(0);
runScript(ctx, 'prepare', config.before_script, cb);
});
} else if (config.before_script) {
runScript(ctx, 'prepare', config.before_script, cb);
} else {
cb(0);
}
},
test: function (ctx, cb) {
if (!ctx.travisConfig || !ctx.travisConfig.script) return cb(0);
runScript(ctx, 'test', ctx.travisConfig.script, cb);
}
});
};