Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

thread deploy errors through

  • Loading branch information...
commit 5f6d8814647df1c387980b9b4da563c6cf975459 1 parent df90a3c
@substack authored
Showing with 87 additions and 50 deletions.
  1. +6 −1 bin/cli.js
  2. +70 −45 index.js
  3. +4 −4 package.json
  4. +7 −0 test/command.js
View
7 bin/cli.js
@@ -66,9 +66,14 @@ else if (cmd === 'deploy') {
var repo = argv._[1];
var commit = argv._[2];
- var deploy = propagit(argv).deploy({
+ var opts = {
repo : repo,
commit : commit,
+ };
+ var deploy = propagit(argv).deploy(opts, function (errors) {
+ if (errors) errors.forEach(function (err) {
+ console.error(err);
+ });
});
deploy.on('deploy', function () {
deploy.hub.close();
View
115 index.js
@@ -172,29 +172,22 @@ Propagit.prototype.createService = function (remote, conn) {
drones.forEach(function (drone) {
self.emit('deploy', drone.id, opts);
- drone.fetch(opts.repo, function (code, sig) {
- if (code) {
- pending --;
- var err = new Error(
- 'git fetch exited with error code ' + code
+ drone.fetch(opts.repo, function (err) {
+ pending --;
+
+ if (err) {
+ errors.push(
+ 'Error fetching from drone ' + drone.id + ':\n'
+ + err
);
- err.command = 'fetch';
- err.drone = drone.id;
- err.code = code;
- err.signal = sig;
- errors.push(err);
+ if (pending === 0) cb(errors.length && errors);
}
- else drone.deploy(opts, function (code, sig) {
- pending --;
- if (code) {
- var err = new Error(
- 'deploy exited with error code ' + code
+ else drone.deploy(opts, function (err) {
+ if (err) {
+ errors.push(
+ 'Error deploying to drone ' + drone.id + ':\n'
+ + err
);
- err.command = 'deploy';
- err.drone = drone.id;
- err.code = code;
- err.signal = sig;
- errors.push(err);
}
if (pending === 0) cb(errors.length && errors);
})
@@ -288,14 +281,11 @@ Propagit.prototype.drone = function (fn) {
actions.fetch = function (repo, cb) {
var p = refs(repo);
- spawn('git', [ 'init', '--bare', p.repodir ])
- .on('exit', function (code, sig) {
- if (code) cb(code, sig)
- else spawn('git', [ 'fetch', p.origin ], { cwd : p.repodir })
- .on('exit', cb)
- ;
- })
- ;
+ runCmd([ 'git', 'init', '--bare', p.repodir ], function (err) {
+ if (err) return cb(err);
+
+ runCmd([ 'git', 'fetch', p.origin ], { cwd : p.repodir }, cb);
+ });
};
actions.deploy = function (opts, cb) {
@@ -308,22 +298,21 @@ Propagit.prototype.drone = function (fn) {
process.env.COMMIT = commit;
process.env.REPO = repo;
- spawn('git', [ 'clone', p.repodir, dir ])
- .on('exit', function (code, sig) {
- if (code) cb(code, sig)
- else spawn('git', [ 'checkout', commit ], { cwd : dir })
- .on('exit', function (code, sig) {
- self.emit('deploy', {
- drone : actions.id,
- commit : commit,
- repo : repo,
- cwd : dir,
- });
- cb(code, sig)
- })
- ;
- })
- ;
+ runCmd([ 'git', 'clone', p.repodir, dir ], function (err) {
+ if (err) return cb(err);
+
+ runCmd([ 'git', 'checkout', commit ], { cwd : dir },
+ function (err) {
+ if (err) return cb(err);
+ self.emit('deploy', {
+ drone : actions.id,
+ commit : commit,
+ repo : repo,
+ cwd : dir,
+ });
+ cb(null)
+ });
+ });
};
actions.stop = function (ids, cb) {
@@ -495,7 +484,9 @@ Propagit.prototype.deploy = function (opts, cb) {
var self = this;
self.hub(function (hub) {
- hub.deploy(opts, function () {
+ hub.deploy(opts, function (err) {
+ if (err) return cb && cb(err);
+
self.emit('deploy');
if (cb) cb();
});
@@ -512,3 +503,37 @@ Propagit.prototype.ps = function () {
});
return stream;
};
+
+function runCmd (cmd, opts, cb) {
+ if (typeof opts === 'function') {
+ cb = opts;
+ opts = {};
+ }
+
+ var ps = spawn(cmd[0], cmd.slice(1));
+ var data = '';
+ ps.stdout.on('data', function (buf) { data += buf });
+ ps.stderr.on('data', function (buf) { data += buf });
+
+ var code, sig;
+ var pending = 3;
+ function onend () {
+ if (--pending !== 0) return;
+
+ if (code) {
+ cb([
+ 'Exited with code ' + code + ':',
+ 'Command: ' + cmd.join(' '),
+ data
+ ].join('\n'))
+ }
+ else cb(null)
+ }
+
+ ps.on('exit', function (c, s) {
+ code = c, sig = s;
+ });
+ ps.on('exit', onend);
+ ps.stdout.on('end', onend);
+ ps.stderr.on('end', onend);
+}
View
8 package.json
@@ -25,10 +25,10 @@
"test" : "tap test/*.js"
},
"dependencies" : {
- "optimist" : "0.3.x",
- "upnode" : "~0.2.0",
- "pushover" : "0.1.x",
- "mkdirp" : "0.3.x"
+ "optimist" : "~0.3.4",
+ "upnode" : "~0.2.4",
+ "pushover" : "~0.1.4",
+ "mkdirp" : "~0.3.3"
},
"devDependencies" : {
"tap" : "~0.2.3"
View
7 test/command.js
@@ -63,6 +63,7 @@ test('command line deploy', function (t) {
if (!cmd) return;
else if (typeof cmd === 'string') {
exec(cmd, opts, function (err, out) {
+ if (err) t.fail(err);
pop(out);
});
}
@@ -78,10 +79,14 @@ test('command line deploy', function (t) {
'deploy', '--hub=localhost:' + port, '--secret=beepboop',
'webapp', commit
]);
+ ps.deploy.stderr.pipe(process.stdout, { end : false });
+ ps.deploy.stdout.pipe(process.stderr, { end : false });
+
ps.deploy.on('exit', run.bind(null, commit));
}
function run (commit) {
+console.log('run!');
ps.run = spawn(cmd, [
'spawn', '--hub=localhost:' + port, '--secret=beepboop',
'--env.PROPAGIT_BEEPITY=boop',
@@ -94,6 +99,7 @@ test('command line deploy', function (t) {
function testServer () {
var opts = { host : 'localhost', port : httpPort, path : '/' };
http.get(opts, function (res) {
+console.log('get!');
var data = '';
res.on('data', function (buf) { data += buf });
res.on('end', function () {
@@ -116,6 +122,7 @@ test('command line deploy', function (t) {
}
function readPs (p, droneId) {
+console.log('readPs!');
var json = '';
p.stdout.on('data', function (buf) { json += buf });
p.stdout.on('end', function () {
Please sign in to comment.
Something went wrong with that request. Please try again.