Created
October 7, 2015 23:32
-
-
Save woodb/9d08947ef3bb18eaf10d to your computer and use it in GitHub Desktop.
pre-push git hook to build and upload Sphinx documentation to gh-pages branch
This file contains hidden or 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 | |
set -e | |
set -x | |
# Root path of the git repository that has this hook | |
LOCAL_CODE_PATH="/path/to/this/repository" | |
# Path to copy $LOCAL_CODE_PATH to for orphaned gh-pages branch | |
# | |
# See https://help.github.com/articles/creating-project-pages-manually/ | |
LOCAL_DOCS_PATH="/path/to/docs/gh-pages/branch/repo" | |
if [ `git symbolic-ref --short -q HEAD` == "master" ] | |
then | |
if [ ! -d "$LOCAL_CODE_PATH" ] | |
then | |
echo "Could not find $LOCAL_CODE_PATH, exiting" | |
exit 1 | |
fi | |
if [ "$LOCAL_CODE_PATH" == "$LOCAL_DOCS_PATH" ] | |
then | |
echo "Code and build directories cannot be the same, exiting" | |
exit 1 | |
fi | |
if [ ! -d "$LOCAL_DOCS_PATH" ] | |
then | |
# docs repository path bad, exit | |
echo "Could not find $LOCAL_DOCS_PATH" | |
echo "Please copy the directory $LOCAL_CODE_PATH to this location.\n\n" | |
echo "Follow instructions found in the GitHub documentation:" | |
echo "https://help.github.com/articles/creating-project-pages-manually/" | |
exit 1 | |
else | |
# check that the docs repository is setup correctly... | |
pushd $LOCAL_DOCS_PATH | |
if [ `git symbolic-ref --short -q HEAD` != "gh-pages" ] | |
then | |
echo "Build repository needs to be on gh-pages branch, exiting" | |
exit 1 | |
fi | |
popd | |
fi | |
pushd $LOCAL_CODE_PATH | |
commit=$(git log -1 --pretty=oneline | cat) | |
pushd docs | |
rm -rf _build | |
make html | |
rsync -aiuc --exclude=.git --delete ./_build/html/ $LOCAL_DOCS_PATH/ | |
popd | |
popd | |
pushd $LOCAL_DOCS_PATH | |
touch .nojekyll | |
git add -A | |
git commit -m "$commit [ci skip]" | |
# Uncomment the line below when you're sure everything is working | |
# git push origin gh-pages | |
popd | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment