Last active
August 30, 2016 06:52
-
-
Save morrelinko/5707626a837b9e03bb1c to your computer and use it in GitHub Desktop.
Git deploy NodeJS script
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 fs = require('fs'), | |
path = require('path'), | |
child = require('child_process'), | |
argf = '', | |
deployDir = '/home/morrelinko/socialinko'; | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf8'); | |
process.stdin.on('data', function(data) { | |
argf += data; | |
}); | |
process.stdin.on('end', function () { | |
argf = argf.trim().split(' '); | |
var fromCommit = argf[0], | |
toCommit = argf[1], | |
branch = argf[2]; | |
// Ensure we only deploy if master branch is pushed | |
if (/master$/.test(branch) == false) { | |
console.log(['Received branch', branch, ', not deploying.'].join(' ')); | |
process.exit; | |
} | |
// Copy files to the deploy directory | |
child.exec('git --work-tree ' + deployDir + ' checkout -f master', function(error, stdout, stderr) { | |
if (error) { | |
console.log('DEPLOY: An error occured: ', error.message || error); | |
return process.exit(); | |
} | |
console.log('DEPLOY: <master>(' + toCommit + ' copied to ' + deployDir); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a NodeJs port of the Ruby code used in this blog post
http://krisjordan.com/essays/setting-up-push-to-deploy-with-git