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