deploy.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_ARCHIVE="tldr.zip"
  10. export SITE_HOME="$HOME/site"
  11. export SITE_REPO_SLUG="tldr-pages/tldr-pages.github.io"
  12. # Configure git.
  13. git config --global user.email "tldrbotgithub@gmail.com"
  14. git config --global user.name "tldr bot"
  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. echo "${DEPLOY_KEY}"> id_ed25519
  20. chmod 600 id_ed25519
  21. ssh-add id_ed25519
  22. }
  23. function upload_assets {
  24. git clone --quiet --depth 1 git@github.com:${SITE_REPO_SLUG}.git "$SITE_HOME"
  25. mv -f "$TLDR_ARCHIVE" "$SITE_HOME/assets/"
  26. cp -f "$TLDRHOME/index.json" "$SITE_HOME/assets/"
  27. cp -f "${TLDRHOME}/scripts/pdf/tldr-pages.pdf" "${SITE_HOME}/assets/tldr-book.pdf"
  28. sha256sum \
  29. "${SITE_HOME}/assets/index.json" \
  30. "${SITE_HOME}/assets/${TLDR_ARCHIVE}" \
  31. "${SITE_HOME}/assets/tldr-book.pdf" \
  32. > "${SITE_HOME}/assets/tldr.sha256sums"
  33. cd "$SITE_HOME"
  34. git add -A
  35. git commit -m "[GitHub Actions] uploaded assets after commit tldr-pages/tldr@${GITHUB_SHA}"
  36. git push -q
  37. echo "Assets (pages archive, index) deployed to static site."
  38. }
  39. ###################################
  40. # MAIN
  41. ###################################
  42. initialize
  43. upload_assets