Created
May 23, 2015 10:17
-
-
Save lilac/3376c1bb3a3a356bb934 to your computer and use it in GitHub Desktop.
Git deploy
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
#!/bin/bash | |
function pychanged { | |
git diff --name-only $1 $2 |grep -q ".py$" | |
} | |
while read oldrev newrev ref | |
do | |
branch=`echo $ref | cut -d/ -f3` | |
if [ "production" == "$branch" -o "master" == "$branch" ]; then | |
worktree='/var/www' | |
changed=0 | |
if pychanged $oldrev $newrev; then changed=1; fi | |
if [ 1 == $changed ]; then | |
# stop gunicorn | |
sudo supervisorctl stop gunicorn | |
fi | |
git --work-tree=$worktree checkout -f $branch | |
echo 'Changes pushed to Amazon EC2 PROD.' | |
if [ 1 == $changed ]; then | |
# start gunicorn | |
sudo supervisorctl start gunicorn | |
fi | |
elif [ "dev" == "$branch" ]; then | |
worktree='/var/www-dev' | |
git --work-tree=$worktree checkout -f $branch | |
echo 'Changes pushed to Amazon EC2 PROD development box.' | |
fi | |
# detect [i18n] command | |
# if git log $oldrev..$newrev |grep -q "[i18n]"; then | |
# detect i18n files change | |
if git diff --name-only $oldrev $newrev |grep -q ".po$"; then | |
cd $worktree | |
pybabel compile -d rewen/translations | |
echo 'Compiled translations.' | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment