deploy.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env bash
  2. # SPDX-License-Identifier: MIT
  3. # This script is executed by GitHub Actions when a PR is merged (i.e. in the `deploy` step).
  4. set -ex
  5. function initialize {
  6. if [ -z "$TLDRHOME" ]; then
  7. export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)}
  8. fi
  9. export TLDR_LANG_ARCHIVES_DIRECTORY="$TLDRHOME/language_archives"
  10. export TLDR_ARCHIVE="tldr.zip"
  11. export SITE_HOME="$HOME/site"
  12. export SITE_REPO_SLUG="tldr-pages/tldr-pages.github.io"
  13. # Configure git.
  14. git config --global user.email "tldrbotgithub@gmail.com"
  15. git config --global user.name "tldr bot"
  16. git config --global push.default simple
  17. git config --global diff.zip.textconv "unzip -c -a"
  18. # Decrypt and add deploy key.
  19. eval "$(ssh-agent -s)"
  20. echo "${DEPLOY_KEY}"> id_ed25519
  21. chmod 600 id_ed25519
  22. ssh-add id_ed25519
  23. }
  24. function upload_assets {
  25. git clone --quiet --depth 1 git@github.com:${SITE_REPO_SLUG}.git "$SITE_HOME"
  26. mv -f "$TLDR_ARCHIVE" "$SITE_HOME/assets/"
  27. mv -f "${TLDR_LANG_ARCHIVES_DIRECTORY}"/*.zip "$SITE_HOME/assets/"
  28. rm -rf "$TLDR_LANG_ARCHIVES_DIRECTORY"
  29. cp -f "$TLDRHOME/index.json" "$SITE_HOME/assets/"
  30. cp -f "${TLDRHOME}/scripts/pdf/tldr-pages.pdf" "${SITE_HOME}/assets/tldr-book.pdf"
  31. sha256sum \
  32. "${SITE_HOME}/assets/index.json" \
  33. "${SITE_HOME}/assets/"*.zip \
  34. "${SITE_HOME}/assets/tldr-book.pdf" \
  35. > "${SITE_HOME}/assets/tldr.sha256sums"
  36. cd "$SITE_HOME"
  37. git add -A
  38. git commit -m "[GitHub Actions] uploaded assets after commit tldr-pages/tldr@${GITHUB_SHA}"
  39. git push -q
  40. echo "Assets (pages archive, index) deployed to static site."
  41. }
  42. ###################################
  43. # MAIN
  44. ###################################
  45. initialize
  46. upload_assets