Last active
August 29, 2015 14:08
-
-
Save dustinboston/c12747ad20129b55b733 to your computer and use it in GitHub Desktop.
Git push-to-deply post-receive hook
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/sh | |
# $HOME/opt/git/example.git/hooks/post-receive | |
# | |
# The "post-receive" script is run after receive-pack has accepted a pack | |
# and the repository has been updated. It is passed arguments in through | |
# stdin in the form | |
# <oldrev> <newrev> <refname> | |
# For example: | |
# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master | |
# | |
# Start a post-receive hook as a background task | |
# http://stackoverflow.com/a/8132845 | |
read oldrev newrev refname | |
if [ "${refname}" == "refs/heads/master" ]; then | |
nohup $HOME/usr/local/bin/publish >& /dev/null & | |
fi | |
exit 0 | |
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/sh | |
# $HOME/usr/local/bin/publish | |
TEMP_DIR=$HOME/tmp/example | |
LOGFILE=$HOME/example.log | |
source $HOME/.bash_profile | |
echo -e "Received push request at $( date +%c )" > $LOGFILE | |
git clone example.git $TEMP_DIR | |
cd "$TEMP_DIR" | |
bundle exec jekyll build -s $TEMP_DIR -d example.com | |
rm -rf $TEMP_DIR | |
echo "Finished request at $( date +%c )" >> $LOGFILE | |
cat $LOGFILE | mail -s "Publish completed" you@example.com | |
rm $LOGFILE | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment