build.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env bash
  2. set -ev
  3. function initialize {
  4. if [ -z "$TLDRHOME" ]; then
  5. export TLDRHOME=${TRAVIS_BUILD_DIR:-`pwd`}
  6. fi
  7. export TLDR_ARCHIVE="tldr.zip"
  8. export SITE_HOME="$HOME/site"
  9. export SITE_URL="github.com/tldr-pages/tldr-pages.github.io"
  10. git config --global user.email "travis@travis-ci.org"
  11. git config --global user.name "Travis CI"
  12. git config --global push.default simple
  13. git config --global diff.zip.textconv "unzip -c -a"
  14. }
  15. function rebuild_index {
  16. npm run build-index
  17. }
  18. function build_archive {
  19. rm -f $TLDR_ARCHIVE
  20. cd $TLDRHOME/
  21. zip -r $TLDR_ARCHIVE pages/ LICENSE.md
  22. }
  23. function upload_assets {
  24. git clone --quiet --depth 1 https://${GH_TOKEN}@${SITE_URL} $SITE_HOME
  25. mv -f $TLDR_ARCHIVE $SITE_HOME/assets/
  26. cp -f $TLDRHOME/pages/index.json $SITE_HOME/assets/
  27. cd $SITE_HOME
  28. git add -A
  29. git commit -m "[TravisCI] uploaded assets after commits ${TRAVIS_COMMIT_RANGE}"
  30. git push -q
  31. }
  32. ###################################
  33. # MAIN
  34. ###################################
  35. if [ ! "$TRAVIS_PULL_REQUEST" == "false" ]; then
  36. echo "This is a Pull Request, no index rebuild needed"
  37. elif [ ! "$TRAVIS_BRANCH" == "master" ]; then
  38. echo "This is not a master branch, no index rebuild needed"
  39. else
  40. initialize
  41. rebuild_index && echo "Rebuilding index is done"
  42. build_archive && echo "Pages archive is created"
  43. upload_assets && echo "Assets (pages archive, index) deployed to static site"
  44. fi