travis-deploy.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. # Inspired by: https://medium.com/@nthgergo/publishing-gh-pages-with-travis-ci-53a8270e87db
  3. set -o errexit
  4. # Info.
  5. echo "Running deploy script"
  6. echo "Branch: $TRAVIS_BRANCH"
  7. echo "Is a Pull Request: $TRAVIS_PULL_REQUEST"
  8. # Exit if the branch is not the master branch.
  9. if [ "$TRAVIS_BRANCH" != "master" ]
  10. then
  11. echo "This commit was made against the $TRAVIS_BRANCH and not the master. No deploy."
  12. exit 0
  13. fi
  14. # Exit if the commit is a pull request.
  15. # We only want to build / deploy when pull requests are merged into master.
  16. if [ "$TRAVIS_PULL_REQUEST" != "false" ]
  17. then
  18. echo "This commit is a pull request. No deploy."
  19. exit 0
  20. fi
  21. # Git config.
  22. git config --global user.email "nobody@nobody.org"
  23. git config --global user.name "Travis CI"
  24. COMMIT_MESSAGE=$(git log -1 --pretty=%B)
  25. # Build steps (optional).
  26. # Status (optional).
  27. # git status
  28. # git log
  29. # Deploy.
  30. cd out
  31. git init
  32. git add .
  33. git commit -m "Deploy: $COMMIT_MESSAGE"
  34. git push --force --quiet "https://${GITHUB_TOKEN}@github.com/${GITHUB_REPO}.git" master:gh-pages > /dev/null 2>&1
  35. cd ..
  36. # Add dist files.
  37. git commit -am "Adding dist files: $COMMIT_MESSAGE"
  38. git push --quiet "https://${GITHUB_TOKEN}@github.com/${GITHUB_REPO}.git" HEAD:master > /dev/null 2>&1