Skip to content

Commit a47b1ac

Browse files
committed
Improve deploy script (addresses #6)
1 parent 3277b4e commit a47b1ac

File tree

1 file changed

+62
-15
lines changed

1 file changed

+62
-15
lines changed

bin/deploy

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,82 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
22

3-
# Run this script to deploy the app to Github Pages.
3+
# Run this script to deploy the app to Github Pages
44

5-
# Exit if any subcommand fails.
5+
# Parse cmd arguments
6+
7+
SRC_BRANCH="master"
8+
DEPLOY_BRANCH="gh-pages"
9+
10+
USAGE_MSG="usage: deploy [-h|--help] [-u|--user] [-s|--src SRC_BRANCH] [-d|--deploy DEPLOY_BRANCH]"
11+
12+
while [[ $# > 0 ]]; do
13+
key="$1"
14+
15+
case $key in
16+
-h|--help)
17+
echo $USAGE_MSG
18+
exit 0
19+
;;
20+
-u|--user)
21+
SRC_BRANCH="source"
22+
DEPLOY_BRANCH="master"
23+
shift
24+
;;
25+
-s|--src)
26+
SRC_BRANCH="$2"
27+
shift
28+
;;
29+
-d|--deploy)
30+
DEPLOY_BRANCH="$2"
31+
shift
32+
;;
33+
*)
34+
echo "Option $1 is unknown."
35+
echo $USAGE_MSG
36+
exit 0
37+
;;
38+
esac
39+
shift
40+
done
41+
42+
# Exit if any subcommand fails
643
set -e
744

8-
echo "Started deploying"
45+
echo "Deploying..."
46+
echo "Source branch: $SRC_BRANCH"
47+
echo "Deploy branch: $DEPLOY_BRANCH"
48+
49+
# Switch to source branch (creates it if necessary from the current branch)
50+
if [ `git branch | grep $SRC_BRANCH | tr ' ' '\n' | tail -1` ]
51+
then
52+
git checkout $SRC_BRANCH
53+
else
54+
git checkout -b $SRC_BRANCH
55+
fi
956

10-
# Checkout gh-pages branch.
11-
if [ `git branch | grep gh-pages` ]
57+
# Checkout DEPLOY_BRANCH branch
58+
if [ `git branch | grep $DEPLOY_BRANCH` ]
1259
then
13-
git branch -D gh-pages
60+
git branch -D $DEPLOY_BRANCH
1461
fi
15-
git checkout -b gh-pages
62+
git checkout -b $DEPLOY_BRANCH
1663

17-
# Build site.
64+
# Build site
1865
bundle exec jekyll build
1966

20-
# Delete and move files.
67+
# Delete and move files
2168
find . -maxdepth 1 ! -name '_site' ! -name '.git' ! -name '.gitignore' -exec rm -rf {} \;
2269
mv _site/* .
2370
rm -R _site/
2471

25-
# Push to gh-pages.
72+
# Push to DEPLOY_BRANCH
2673
git add -fA
2774
git commit --allow-empty -m "$(git log -1 --pretty=%B) [ci skip]"
28-
git push -f -q origin gh-pages
75+
git push -f -q origin $DEPLOY_BRANCH
2976

30-
# Move back to previous branch.
31-
git checkout -
77+
# Move back to SRC_BRANCH
78+
git checkout $SRC_BRANCH
3279

33-
echo "Deployed Successfully!"
80+
echo "Deployed successfully!"
3481

3582
exit 0

0 commit comments

Comments
 (0)