|
1 | | -#!/usr/bin/env sh |
| 1 | +#!/usr/bin/env bash |
2 | 2 |
|
3 | | -# Run this script to deploy the app to Github Pages. |
| 3 | +# Run this script to deploy the app to Github Pages |
4 | 4 |
|
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 |
6 | 43 | set -e |
7 | 44 |
|
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 |
9 | 56 |
|
10 | | -# Checkout gh-pages branch. |
11 | | -if [ `git branch | grep gh-pages` ] |
| 57 | +# Checkout DEPLOY_BRANCH branch |
| 58 | +if [ `git branch | grep $DEPLOY_BRANCH` ] |
12 | 59 | then |
13 | | - git branch -D gh-pages |
| 60 | + git branch -D $DEPLOY_BRANCH |
14 | 61 | fi |
15 | | -git checkout -b gh-pages |
| 62 | +git checkout -b $DEPLOY_BRANCH |
16 | 63 |
|
17 | | -# Build site. |
| 64 | +# Build site |
18 | 65 | bundle exec jekyll build |
19 | 66 |
|
20 | | -# Delete and move files. |
| 67 | +# Delete and move files |
21 | 68 | find . -maxdepth 1 ! -name '_site' ! -name '.git' ! -name '.gitignore' -exec rm -rf {} \; |
22 | 69 | mv _site/* . |
23 | 70 | rm -R _site/ |
24 | 71 |
|
25 | | -# Push to gh-pages. |
| 72 | +# Push to DEPLOY_BRANCH |
26 | 73 | git add -fA |
27 | 74 | 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 |
29 | 76 |
|
30 | | -# Move back to previous branch. |
31 | | -git checkout - |
| 77 | +# Move back to SRC_BRANCH |
| 78 | +git checkout $SRC_BRANCH |
32 | 79 |
|
33 | | -echo "Deployed Successfully!" |
| 80 | +echo "Deployed successfully!" |
34 | 81 |
|
35 | 82 | exit 0 |
0 commit comments