Created
February 17, 2017 11:58
-
-
Save victorloux/130cd82c5cb7d3bb931a8aae26986fab to your computer and use it in GitHub Desktop.
Automatic Harp deployment on git push
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 | |
# | |
# Put in .git/hooks/post-merge on your remote (staging or production) | |
# and chmod +x on it. | |
# Combine with a GH webhook script that will `git pull` | |
# every time you push to a repo | |
# If you get errors with a webhook script, note you might | |
# have to change the owner of your repository (+ log file) to "www-data" or similar | |
if [ -z "$GIT_WORK_TREE" ]; then | |
echo "GIT_WORK_TREE is not defined. This script should be run by a Git hook." | |
exit 1 | |
fi | |
# Set a location for your log | |
log=/var/www/yoursite/commit.log | |
harp=/usr/bin/harp | |
echo "Running post-merge script..." | |
# Output some debug info to our log file | |
{ | |
echo Arguments: "$@" | |
echo "Current working directory:" | |
pwd | |
echo "Environment variables:" | |
set | |
} > $log | |
# This deletes any file that shouldn't be here | |
# (ie if you made a modification on the live server, it'll be nuked) | |
GIT_DIR='.git' | |
umask 002 && git reset --hard | |
# Then we compile our Harp site to /dist/ | |
# and append any error to the log file | |
$harp compile "$GIT_WORK_TREE" "$GIT_WORK_TREE"/dist/ 2>>$log | |
# Harp can't ignore file and compiles any Markdown file it finds, | |
# including the README… so delete that | |
rm "$GIT_WORK_TREE"/dist/README.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment