deploy.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env bash
  2. # This script is executed by Travis CI when a PR is merged (i.e. in the `deploy` step).
  3. set -ex
  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. export SITE_REPO_SLUG="tldr-pages/tldr-pages.github.io"
  12. # Configure git.
  13. git config --global user.email "travis@travis-ci.org"
  14. git config --global user.name "Travis CI"
  15. git config --global push.default simple
  16. git config --global diff.zip.textconv "unzip -c -a"
  17. # Decrypt and add deploy key.
  18. eval "$(ssh-agent -s)"
  19. openssl aes-256-cbc -K $encrypted_973441be79af_key -iv $encrypted_973441be79af_iv -in ./scripts/id_ed25519_tldr_asset_upload.enc -out id_ed25519 -d
  20. chmod 600 id_ed25519
  21. ssh-add id_ed25519
  22. }
  23. function rebuild_index {
  24. npm run build-index
  25. echo "Rebuilding index done."
  26. }
  27. function build_archive {
  28. rm -f $TLDR_ARCHIVE
  29. cd $TLDRHOME/
  30. zip -r $TLDR_ARCHIVE pages*/ LICENSE.md
  31. echo "Pages archive created."
  32. }
  33. function upload_assets {
  34. git clone --quiet --depth 1 git@github.com:${SITE_REPO_SLUG}.git $SITE_HOME
  35. mv -f $TLDR_ARCHIVE $SITE_HOME/assets/
  36. cp -f $TLDRHOME/pages/index.json $SITE_HOME/assets/
  37. cd $SITE_HOME
  38. git add -A
  39. git commit -m "[TravisCI] uploaded assets after commits ${TRAVIS_COMMIT_RANGE}"
  40. git push -q
  41. echo "Assets (pages archive, index) deployed to static site."
  42. }
  43. ###################################
  44. # MAIN
  45. ###################################
  46. initialize
  47. rebuild_index
  48. build_archive
  49. upload_assets