|
| 1 | +#!/bin/bash |
| 2 | +# Automatically deploy on gh-pages |
| 3 | + |
| 4 | +set -e |
| 5 | + |
| 6 | +SOURCE_BRANCH="master" |
| 7 | +TARGET_BRANCH="gh-pages" |
| 8 | + |
| 9 | +# Save some useful information |
| 10 | +REPO=$(git config remote.origin.url) |
| 11 | +SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:} |
| 12 | +SHA=$(git rev-parse --verify HEAD) |
| 13 | + |
| 14 | +# Clone the existing gh-pages for this repo into out/ |
| 15 | +( |
| 16 | + git clone "$REPO" out |
| 17 | + cd out |
| 18 | + git checkout $TARGET_BRANCH |
| 19 | +) |
| 20 | + |
| 21 | +# Remove the current doc for master |
| 22 | +rm -rf out/master/ || exit 0 |
| 23 | + |
| 24 | +# Make the doc for master |
| 25 | +mkdir out/master/ |
| 26 | +cp util/gh-pages/index.html out/master |
| 27 | +./util/export.py out/master/lints.json |
| 28 | + |
| 29 | +# Save the doc for the current tag and point current/ to it |
| 30 | +if [ -n "$TRAVIS_TAG" ]; then |
| 31 | + cp -r out/master "out/$TRAVIS_TAG" |
| 32 | + rm -f out/current |
| 33 | + ln -s "$TRAVIS_TAG" out/current |
| 34 | +fi |
| 35 | + |
| 36 | +# Pull requests and commits to other branches shouldn't try to deploy, just build to verify |
| 37 | +if [ "$TRAVIS_PULL_REQUEST" != "false" ] || [ "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then |
| 38 | + echo "Generated, won't push" |
| 39 | + exit 0 |
| 40 | +fi |
| 41 | + |
| 42 | +# Now let's go have some fun with the cloned repo |
| 43 | +cd out |
| 44 | +git config user.name "Travis CI" |
| 45 | +git config user.email "[email protected]" |
| 46 | + |
| 47 | +if [ -z "$(git diff --exit-code)" ]; then |
| 48 | + echo "No changes to the output on this push; exiting." |
| 49 | + exit 0 |
| 50 | +fi |
| 51 | + |
| 52 | +git add . |
| 53 | +git commit -m "Automatic 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_KEY" -iv "$ENCRYPTED_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