deploy.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. # Clean out existing contents except versions
  36. mv versions ..
  37. ls | xargs rm -rf
  38. cd ..
  39. # Run our compile script
  40. doCompile
  41. mv versions $OUT
  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 "$COMMIT_AUTHOR_EMAIL"
  46. # If there are no changes to the compiled dist (e.g. this is a README update) then just bail.
  47. if git diff --quiet; then
  48. echo "No changes to the output on this push; exiting."
  49. exit 0
  50. fi
  51. # Commit the "changes", i.e. the new version.
  52. # The delta will show diffs between new and old versions.
  53. git add -A .
  54. git commit -m "Deploy to GitHub Pages: ${SHA}"
  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. # Now that we're all set up, we can push.
  65. git push $SSH_REPO $TARGET_BRANCH