1
0

deploy.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env bash
  2. # This script is executed by GitHub Actions 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=${GITHUB_WORKSPACE:-$(pwd)}
  7. fi
  8. export TLDR_ARCHIVE="tldr.zip"
  9. export SITE_HOME="$HOME/site"
  10. export SITE_REPO_SLUG="tldr-pages/tldr-pages.github.io"
  11. # Configure git.
  12. git config --global user.email "tldrbotgithub@gmail.com"
  13. git config --global user.name "tldr bot"
  14. git config --global push.default simple
  15. git config --global diff.zip.textconv "unzip -c -a"
  16. # Decrypt and add deploy key.
  17. eval "$(ssh-agent -s)"
  18. echo "${DEPLOY_KEY}"> id_ed25519
  19. chmod 600 id_ed25519
  20. ssh-add id_ed25519
  21. }
  22. function upload_assets {
  23. git clone --quiet --depth 1 git@github.com:${SITE_REPO_SLUG}.git "$SITE_HOME"
  24. mv -f "$TLDR_ARCHIVE" "$SITE_HOME/assets/"
  25. cp -f "$TLDRHOME/index.json" "$SITE_HOME/assets/"
  26. # Copy PDF to assets
  27. if [[ -f "${TLDRHOME}/scripts/pdf/tldr-pages.pdf" ]]; then
  28. cp -f "${TLDRHOME}/scripts/pdf/tldr-pages.pdf" "${SITE_HOME}/assets/tldr-book.pdf"
  29. fi
  30. cd "$SITE_HOME"
  31. git add -A
  32. git commit -m "[GitHub Actions] uploaded assets after commit tldr-pages/tldr@${GITHUB_SHA}"
  33. git push -q
  34. echo "Assets (pages archive, index) deployed to static site."
  35. }
  36. ###################################
  37. # MAIN
  38. ###################################
  39. initialize
  40. upload_assets