Created
March 7, 2019 19:25
-
-
Save foxxyz/4334ad3afbc0e6ebee9886133c24f7ec to your computer and use it in GitHub Desktop.
Python post-receive hook for Windows deployments
This file contains 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 python3 | |
# post-receive hook for git-push deployments on Windows | |
import sys | |
from os.path import join | |
from subprocess import call | |
deploy_path = 'C:\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 "{}" checkout -f {}'.format(deploy_path, branch), shell=True) | |
# Install dependencies | |
info('Installing dependencies for GUI...') | |
call('npm install', shell=True, cwd=join(deploy_path, "gui")) | |
info('Installing dependencies for server...') | |
call('npm install', shell=True, cwd=join(deploy_path, "server")) | |
# Compile | |
info('Compiling GUI...') | |
call('npm run build', shell=True, cwd=join(deploy_path, "gui")) | |
if __name__ == '__main__': | |
post_receive(*sys.stdin.read().split()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment