build.sh 1.6 KB

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