|
| 1 | +#!/bin/bash |
| 2 | +set -e # Exit with nonzero exit code if anything fails |
| 3 | + |
| 4 | +# From https://gist.github.com/domenic/ec8b0fc8ab45f39403dd |
| 5 | + |
| 6 | +SOURCE_BRANCH="master" |
| 7 | +TARGET_BRANCH="gh-pages" |
| 8 | + |
| 9 | +function doCompile { |
| 10 | + chmod 755 ./compile.sh |
| 11 | + ./compile.sh |
| 12 | +} |
| 13 | + |
| 14 | +# Pull requests and commits to other branches shouldn't try to deploy, just build to verify |
| 15 | +if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then |
| 16 | + echo "Skipping deploy; just doing a build." |
| 17 | + doCompile |
| 18 | + exit 0 |
| 19 | +fi |
| 20 | + |
| 21 | +# Save some useful information |
| 22 | +REPO=`git config remote.origin.url` |
| 23 | +SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:} |
| 24 | +SHA=`git rev-parse --verify HEAD` |
| 25 | + |
| 26 | +# Clone the existing gh-pages for this repo into out/ |
| 27 | +# Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deply) |
| 28 | +git clone $REPO out |
| 29 | +cd out |
| 30 | +git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH |
| 31 | +cd .. |
| 32 | + |
| 33 | +# Clean out existing contents |
| 34 | +rm -rf out/**/* || exit 0 |
| 35 | + |
| 36 | +# Run our compile script |
| 37 | +doCompile |
| 38 | + |
| 39 | +# Now let's go have some fun with the cloned repo |
| 40 | +cd out |
| 41 | +git config user.name "Travis CI" |
| 42 | +git config user.email "$COMMIT_AUTHOR_EMAIL" |
| 43 | + |
| 44 | +# If there are no changes to the compiled out (e.g. this is a README update) then just bail. |
| 45 | +if git diff --quiet; then |
| 46 | + echo "No changes to the output on this push; exiting." |
| 47 | + exit 0 |
| 48 | +fi |
| 49 | + |
| 50 | +# Commit the "changes", i.e. the new version. |
| 51 | +# The delta will show diffs between new and old versions. |
| 52 | +git add -A . |
| 53 | +git commit -m "Deploy to GitHub Pages: ${SHA}" |
| 54 | + |
| 55 | +# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc |
| 56 | +ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key" |
| 57 | +ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv" |
| 58 | +ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR} |
| 59 | +ENCRYPTED_IV=${!ENCRYPTED_IV_VAR} |
| 60 | +openssl aes-256-cbc -K $encrypted_4571b087bd76_key -iv $encrypted_4571b087bd76_iv -in ../deploy_key.enc -out ../deploy_key -d |
| 61 | +chmod 600 ../deploy_key |
| 62 | +eval `ssh-agent -s` |
| 63 | +ssh-add ../deploy_key |
| 64 | + |
| 65 | +# Now that we're all set up, we can push. |
| 66 | +git push $SSH_REPO $TARGET_BRANCH |
0 commit comments