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