deploy.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. cd site/_themes
  7. yarn
  8. yarn build
  9. mv dist/js ../assets/js/themes
  10. cd ../assets/js/themes
  11. FILE=../../../_includes/themes.html
  12. echo "" > $FILE
  13. for f in *.js; do
  14. echo "<script src=/assets/js/themes/$f></script>" >> $FILE
  15. done
  16. cd ../../../../
  17. bundle exec jekyll build
  18. }
  19. # Pull requests and commits to other branches shouldn't try to deploy, just build to verify
  20. if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
  21. echo "Skipping deploy; just doing a build."
  22. doCompile
  23. exit 0
  24. fi
  25. # Save some useful information
  26. REPO=`git config remote.origin.url`
  27. SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
  28. SHA=`git rev-parse --verify HEAD`
  29. OUT=_gh_pages
  30. # Clone the existing gh-pages for this repo into dist/
  31. # Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deply)
  32. git clone $REPO $OUT
  33. cd $OUT
  34. git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH
  35. cd ..
  36. # Clean out existing contents
  37. rm -rf $OUT/**/* || exit 0
  38. # Run our compile script
  39. doCompile
  40. # Now let's go have some fun with the cloned repo
  41. cd $OUT
  42. git config user.name "Travis CI"
  43. git config user.email "$COMMIT_AUTHOR_EMAIL"
  44. # If there are no changes to the compiled dist (e.g. this is a README update) then just bail.
  45. if git diff --quiet; then
  46. echo "No changes to the output on this push; exiting."
  47. exit 0
  48. fi
  49. # Commit the "changes", i.e. the new version.
  50. # The delta will show diffs between new and old versions.
  51. git add -A .
  52. git commit -m "Deploy to GitHub Pages: ${SHA}"
  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 ../deploy_key.enc -out ../deploy_key -d
  59. chmod 600 ../deploy_key
  60. eval `ssh-agent -s`
  61. ssh-add ../deploy_key
  62. # Now that we're all set up, we can push.
  63. git push $SSH_REPO $TARGET_BRANCH