1 | #!/bin/bash
|
2 | set -e
|
3 |
|
4 | SOURCE_BRANCH="master"
|
5 | TARGET_BRANCH="gh-pages"
|
6 |
|
7 | function doCompile {
|
8 | bundle exec jekyll build
|
9 | }
|
10 |
|
11 |
|
12 | if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
|
13 | echo "Skipping deploy; just doing a build."
|
14 | doCompile
|
15 | exit 0
|
16 | fi
|
17 |
|
18 |
|
19 | REPO=`git config remote.origin.url`
|
20 | SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
|
21 | SHA=`git rev-parse --verify HEAD`
|
22 | OUT=_gh_pages
|
23 |
|
24 |
|
25 |
|
26 | git clone $REPO $OUT
|
27 | cd $OUT
|
28 | git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH
|
29 | cd ..
|
30 |
|
31 |
|
32 | rm -rf $OUT/**/* || exit 0
|
33 |
|
34 |
|
35 | doCompile
|
36 |
|
37 |
|
38 | cd $OUT
|
39 | git config user.name "Travis CI"
|
40 | git config user.email "$COMMIT_AUTHOR_EMAIL"
|
41 |
|
42 |
|
43 | if git diff --quiet; then
|
44 | echo "No changes to the output on this push; exiting."
|
45 | exit 0
|
46 | fi
|
47 |
|
48 |
|
49 |
|
50 | git add -A .
|
51 | git commit -m "Deploy to GitHub Pages: ${SHA}"
|
52 |
|
53 |
|
54 | ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
|
55 | ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
|
56 | ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
|
57 | ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
|
58 | openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in ../deploy_key.enc -out ../deploy_key -d
|
59 | chmod 600 ../deploy_key
|
60 | eval `ssh-agent -s`
|
61 | ssh-add ../deploy_key
|
62 |
|
63 |
|
64 | git push $SSH_REPO $TARGET_BRANCH
|