Skip to content

Instantly share code, notes, and snippets.

@thmsmlr
Created August 17, 2016 17:17
Show Gist options
  • Save thmsmlr/1b4b04c62fba1ee80ea2f066f92b2794 to your computer and use it in GitHub Desktop.
Save thmsmlr/1b4b04c62fba1ee80ea2f066f92b2794 to your computer and use it in GitHub Desktop.
GitHub Pages deploy script
#!/bin/sh
set -e
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" != "jekyll" ]; then
echo "ERROR! You can only deploy from jekyll branch"
exit 1
fi
CLEAN_REPO=$(git status --porcelain)
if [ -n "$CLEAN_REPO" ]; then
echo "ERROR! Untracked changes in the repo, commit all changes before deploying"
exit 2
fi
UNPUSHED_COMMITS=$(git cherry -v)
if [ -n "$UNPUSHED_COMMITS" ]; then
echo "ERROR! Unpushed commits on jekyll branch. Please push all commits before deploying"
exit 3
fi
CURRENT_SHA=$(git rev-parse HEAD)
echo ""
echo "=> Setting up clean build directory <="
echo ""
rm -rf _site
git clone -b master git@github.com:thmsmlr/thmsmlr.github.io.git _site
pushd _site
rm -rf $(git ls-tree --name-only master)
popd
echo ""
echo "=> Building site <="
echo ""
jekyll build
pushd _site
git aa
git commit -m "`date` ($CURRENT_SHA)"
echo ""
echo "=> Deploying site <="
echo ""
git push origin master
popd
echo ""
echo "=> Cleaning up <="
echo ""
rm -rf _site
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment