Skip to content

Instantly share code, notes, and snippets.

@meandavejustice
Last active August 29, 2015 14:09
Show Gist options
  • Save meandavejustice/8a2039e766bfcc7a6f4a to your computer and use it in GitHub Desktop.
Save meandavejustice/8a2039e766bfcc7a6f4a to your computer and use it in GitHub Desktop.
#!/bin/bash
git pull origin master
npm install
node server.js &
var path = require('path');
var spawn = require('child_process').spawn;
var createHandler = require("github-webhook-handler");
var handler = createHandler({
path: '/deploy',
secret: '***************************'
});
handler.on('error', function (err) {
console.log('Error:', err.message)
});
handler.on('push', function (event) {
setTimeout(function() {
var shell = process.env.SHELL;
var args = ['-c', 'bash deploy.sh'];
var projectPath = '/home/dave/www/project-name';
var opts = { cwd: projectPath };
console.log('[GITHUB] Spawning...', opts);
var spawnProcess = spawn(shell, args, opts);
spawnProcess.on('close', function(exitCode) {
console.log('[GITHUB] Spawn finished', exitCode);
console.log('[GITHUB] Exiting...');
console.log('-------------------------------------------------------');
});
}, 1000);
})
module.exports = function(req, res) {
handler(req, res, function(err) {
if (err) console.error(err);
res.statusCode = 404;
res.end('no such location');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment