deploy.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 "actions@github.com"
  13. git config --global user.name "GitHub Actions"
  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. cd "$SITE_HOME"
  27. git add -A
  28. git commit -m "[GitHub Actions] uploaded assets after commit ${GITHUB_SHA}"
  29. git push -q
  30. echo "Assets (pages archive, index) deployed to static site."
  31. }
  32. ###################################
  33. # MAIN
  34. ###################################
  35. initialize
  36. upload_assets