You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

deploy.sh 1.8KB

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