deploy.sh 1.9 KB

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