Created
January 15, 2019 21:24
-
-
Save Br3nda/93c69e27b8ad454707839ee8541a909a to your computer and use it in GitHub Desktop.
Build and deploy jekyll site 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 | |
# based on https://gist.github.com/cobyism/4730490 | |
DIST_FOLDER='_site' | |
PUBLISH_BRANCH='gh-pages' | |
REMOTE='origin' | |
GIT_USER=`git config user.name` | |
if [ -z "$1" ] | |
then | |
echo | |
echo "Usage: deploy-to-gh-pages [release number]" | |
echo | |
echo "e.g." | |
echo | |
echo " deploy-to-gh-pages 1" | |
exit 1 | |
fi | |
RELEASE="release$1" | |
echo | |
echo "Creating branch ${RELEASE}" | |
git checkout origin/dev > /dev/null | |
git checkout -b ${RELEASE} > /dev/null | |
echo | |
echo "Installing dependencies" | |
bundle > /dev/null | |
echo | |
echo "Building Jekyll app" | |
bundle exec jekyll build > /dev/null | |
echo | |
echo "Committing _site into branch ${RELEASE}" | |
git add --force _site && git commit ${DIST_FOLDER} -m "Build $1 of ${DIST_FOLDER} by ${GIT_USER}" > /dev/null | |
echo | |
echo "Pushing a copy of ${RELEASE} branch to remote ${REMOTE}" | |
git push ${REMOTE} ${RELEASE} --force > /dev/null | |
## Can't force push this, so we delete the branch then push newly made one. | |
echo | |
echo "Removing existing ${PUBLISH_BRANCH} branch on remote ${REMOTE}" | |
git push ${REMOTE} ":${PUBLISH_BRANCH}" | |
echo | |
echo "Moving ${DIST_FOLDER} files to / in branch ${PUBLISH_BRANCH}" | |
git subtree push --prefix ${DIST_FOLDER} ${REMOTE} ${PUBLISH_BRANCH} | |
echo | |
echo "Returning to dev branch" | |
git checkout dev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment