Created
May 22, 2015 19:39
-
-
Save junosuarez/039f9ed6c17a0e5f06c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var path = require('path') | |
var exec = require('child_process').execSync | |
function receive(then) { | |
process.stdin.on('data', function (data) { | |
then(null, parse(data)) | |
}) | |
} | |
function parse(data) { | |
var raw = String(data).trim().split(' ') | |
var args = { | |
fromCommit: raw[0], | |
toCommit: raw[1], | |
branch: path.basename(raw[2]) | |
} | |
return args | |
} | |
receive(function (err, args) { | |
if (err) { console.log(err); process.exit(1) } | |
if (args.branch !== 'master') { | |
console.log('%s is not master, skipping deploy', args.branch) | |
process.exit() | |
} | |
var dest = path.resolve('/var/www/', path.basename(path.dirname(__dirname)), 'public') | |
exec('mkdir -p ' + dest) | |
exec('git checkout -f master', { | |
env: {GIT_WORK_TREE: dest} | |
}) | |
exec('git clean -f', { | |
env: {GIT_WORK_TREE: dest} | |
}) | |
console.log('deployed %s (%s) to %s', args.toCommit, args.branch, dest) | |
}) | |
~ | |
~ | |
~ | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment