Improve deploy script (addresses #6)
This commit is contained in:
parent
3277b4e96e
commit
a47b1acd21
77
bin/deploy
77
bin/deploy
|
|
@ -1,35 +1,82 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Run this script to deploy the app to Github Pages.
|
# Run this script to deploy the app to Github Pages
|
||||||
|
|
||||||
# Exit if any subcommand fails.
|
# Parse cmd arguments
|
||||||
|
|
||||||
|
SRC_BRANCH="master"
|
||||||
|
DEPLOY_BRANCH="gh-pages"
|
||||||
|
|
||||||
|
USAGE_MSG="usage: deploy [-h|--help] [-u|--user] [-s|--src SRC_BRANCH] [-d|--deploy DEPLOY_BRANCH]"
|
||||||
|
|
||||||
|
while [[ $# > 0 ]]; do
|
||||||
|
key="$1"
|
||||||
|
|
||||||
|
case $key in
|
||||||
|
-h|--help)
|
||||||
|
echo $USAGE_MSG
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-u|--user)
|
||||||
|
SRC_BRANCH="source"
|
||||||
|
DEPLOY_BRANCH="master"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-s|--src)
|
||||||
|
SRC_BRANCH="$2"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-d|--deploy)
|
||||||
|
DEPLOY_BRANCH="$2"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Option $1 is unknown."
|
||||||
|
echo $USAGE_MSG
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
# Exit if any subcommand fails
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "Started deploying"
|
echo "Deploying..."
|
||||||
|
echo "Source branch: $SRC_BRANCH"
|
||||||
|
echo "Deploy branch: $DEPLOY_BRANCH"
|
||||||
|
|
||||||
# Checkout gh-pages branch.
|
# Switch to source branch (creates it if necessary from the current branch)
|
||||||
if [ `git branch | grep gh-pages` ]
|
if [ `git branch | grep $SRC_BRANCH | tr ' ' '\n' | tail -1` ]
|
||||||
then
|
then
|
||||||
git branch -D gh-pages
|
git checkout $SRC_BRANCH
|
||||||
|
else
|
||||||
|
git checkout -b $SRC_BRANCH
|
||||||
fi
|
fi
|
||||||
git checkout -b gh-pages
|
|
||||||
|
|
||||||
# Build site.
|
# Checkout DEPLOY_BRANCH branch
|
||||||
|
if [ `git branch | grep $DEPLOY_BRANCH` ]
|
||||||
|
then
|
||||||
|
git branch -D $DEPLOY_BRANCH
|
||||||
|
fi
|
||||||
|
git checkout -b $DEPLOY_BRANCH
|
||||||
|
|
||||||
|
# Build site
|
||||||
bundle exec jekyll build
|
bundle exec jekyll build
|
||||||
|
|
||||||
# Delete and move files.
|
# Delete and move files
|
||||||
find . -maxdepth 1 ! -name '_site' ! -name '.git' ! -name '.gitignore' -exec rm -rf {} \;
|
find . -maxdepth 1 ! -name '_site' ! -name '.git' ! -name '.gitignore' -exec rm -rf {} \;
|
||||||
mv _site/* .
|
mv _site/* .
|
||||||
rm -R _site/
|
rm -R _site/
|
||||||
|
|
||||||
# Push to gh-pages.
|
# Push to DEPLOY_BRANCH
|
||||||
git add -fA
|
git add -fA
|
||||||
git commit --allow-empty -m "$(git log -1 --pretty=%B) [ci skip]"
|
git commit --allow-empty -m "$(git log -1 --pretty=%B) [ci skip]"
|
||||||
git push -f -q origin gh-pages
|
git push -f -q origin $DEPLOY_BRANCH
|
||||||
|
|
||||||
# Move back to previous branch.
|
# Move back to SRC_BRANCH
|
||||||
git checkout -
|
git checkout $SRC_BRANCH
|
||||||
|
|
||||||
echo "Deployed Successfully!"
|
echo "Deployed successfully!"
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue