Skip to content

Instantly share code, notes, and snippets.

@keepitsimple
Last active August 29, 2015 14:04
Show Gist options
  • Save keepitsimple/9c904a72dbeeb2bcbfe4 to your computer and use it in GitHub Desktop.
Save keepitsimple/9c904a72dbeeb2bcbfe4 to your computer and use it in GitHub Desktop.
Git post-receive hook on python
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#post-receive
import sys
import subprocess
# 1. Read STDIN (Format: "from_commit to_commit branch_name")
(old, new, branch) = sys.stdin.read().split()
# 2. Only deploy if master branch was pushed
if branch == 'refs/heads/master':
subprocess.call('date >> ~/prod-deployment.log', shell=True)
subprocess.call('GIT_WORK_TREE=/home/ft/app.prod git checkout master -f', shell=True)
subprocess.call('cd ../../app.prod;bower update', shell=True)
#3. Only deploy if develop branch was pushed
if branch == 'refs/heads/develop':
subprocess.call('date >> ~/dev-deployment.log', shell=True)
subprocess.call('GIT_WORK_TREE=/home/ft/app.dev git checkout develop -f', shell=True)
subprocess.call('cd ../../app.dev;bower update', shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment