deploy_ghpages.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. #
  3. # Script for travis-ci to sync apidoc dir from master branch to gh-pages branch
  4. # based on :
  5. # * https://github.com/steveklabnik/automatically_update_github_pages_with_travis_example
  6. # * https://github.com/gemini-testing/gemini/pull/352/files
  7. set -o errexit -o nounset
  8. if [ "$TRAVIS_BRANCH" != "master" ] ; then
  9. echo "This commit was made against the $TRAVIS_BRANCH and not the master! No deploy!"
  10. exit 0
  11. fi
  12. if [ "$GH_TOKEN" == "" ] ; then
  13. echo "GH_TOKEN is not defined"
  14. exit 1
  15. fi
  16. rev=$(git rev-parse --short HEAD)
  17. repo=$(git config --local --get-all remote.origin.url | awk -F'[:/]' 'NF && NF-1 {print ($(NF-1)"/"$NF)}')
  18. echo -e "Starting to update gh-pages of ${repo} at ${rev}\n"
  19. # on Travis, can't optimize by cloning itself and define remote as upstream
  20. # travis> "attempt to fetch/clone from a shallow repository"
  21. # So need to do a full clone
  22. rm -Rf gh-pages
  23. git clone -b gh-pages --single-branch https://${GH_TOKEN}@github.com/${repo} gh-pages > /dev/null
  24. cd gh-pages
  25. rsync -az --stats --delete --exclude .git --exclude CNAME --force ../build/asciidoc/html5/ .
  26. git config --local user.email "[email protected]"
  27. git config --local user.name "Travis"
  28. git add -A . > /dev/null
  29. git commit -m "Travis build $TRAVIS_BUILD_NUMBER pushed to gh-pages at ${rev}"
  30. git push --force --quiet origin gh-pages
  31. cd ..
  32. rm -Rf gh-pages