deploy.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. export TLDR_ARCHIVE="tldr.zip"
  7. if [[ ! -f $TLDR_ARCHIVE ]]; then
  8. echo "No changes to deploy."
  9. exit 0
  10. fi
  11. if [[ -z $TLDRHOME ]]; then
  12. export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)}
  13. fi
  14. export SITE_HOME="$HOME/site"
  15. # Configure git.
  16. git config --global user.email "tldrbotgithub@gmail.com"
  17. git config --global user.name "tldr bot"
  18. git config --global push.default simple
  19. git config --global diff.zip.textconv "unzip -c -a"
  20. # Decrypt and add deploy key.
  21. eval "$(ssh-agent -s)"
  22. echo "$DEPLOY_KEY"> id_ed25519
  23. chmod 600 id_ed25519
  24. ssh-add id_ed25519
  25. }
  26. function upload_assets {
  27. git clone --quiet --depth 1 "git@github.com:tldr-pages/tldr-pages.github.io.git" "$SITE_HOME"
  28. mv -f "$TLDR_ARCHIVE" "$SITE_HOME/assets/"
  29. find "$TLDRHOME/language_archives" -maxdepth 1 -name "*.zip" -exec mv -f {} "$SITE_HOME/assets/" \;
  30. cp -f "$TLDRHOME/index.json" "$SITE_HOME/assets/"
  31. find "$TLDRHOME/scripts/pdf" -maxdepth 1 -name "*.pdf" -exec mv -f {} "$SITE_HOME/assets/" \;
  32. cd "$SITE_HOME/assets"
  33. sha256sum -- index.json *.zip > tldr.sha256sums
  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 and checksums) deployed to the static site."
  38. }
  39. ###################################
  40. # MAIN
  41. ###################################
  42. initialize
  43. upload_assets