deploy.sh 2.2 KB

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