Created
March 16, 2017 22:33
Revisions
-
foxxyz revised this gist
Mar 16, 2017 . No changes.There are no files selected for viewing
-
foxxyz created this gist
Mar 16, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ #!/usr/bin/env python3 # post-receive hook for git-push deployments import sys from subprocess import call deploy_path = '/path/to/project/' deploy_branch = 'master' class Colors: FAIL = '\033[91m' OK = '\033[92m' END = '\033[0m' def error(msg): "Error message print" print(Colors.FAIL + msg + Colors.END, flush=True) def info(msg): "Info message print" print(Colors.OK + msg + Colors.END, flush=True) def post_receive(from_commit, to_commit, branch): # Only deploy if branch matches if not branch.endswith('/{}'.format(deploy_branch)): error('Received branch {}, not deploying'.format(branch)) return # Copy files info('Deploying {} ({}) to {}...'.format(branch, to_commit, deploy_path)) call('GIT_WORK_TREE="{}" git checkout -f {}'.format(deploy_path, branch), shell=True) # Install dependencies info('Installing dependencies...') call('/usr/bin/npm install', shell=True, cwd=deploy_path) # Compile with webpack info('Compiling code...') call('/usr/bin/npm run build', shell=True, cwd=deploy_path) if __name__ == '__main__': post_receive(*sys.stdin.read().split())