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