1
0

deploy.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. # Copy PDF to assets
  28. if [[ -f "${TLDRHOME}/scripts/pdf/tldr-pages.pdf" ]]; then
  29. cp -f "${TLDRHOME}/scripts/pdf/tldr-pages.pdf" "${SITE_HOME}/assets/tldr-book.pdf"
  30. fi
  31. cd "$SITE_HOME"
  32. git add -A
  33. git commit -m "[GitHub Actions] uploaded assets after commit tldr-pages/tldr@${GITHUB_SHA}"
  34. git push -q
  35. echo "Assets (pages archive, index) deployed to static site."
  36. }
  37. ###################################
  38. # MAIN
  39. ###################################
  40. initialize
  41. upload_assets