2015-12-04 14:54:05 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-07-16 14:15:31 +01:00
|
|
|
# SPDX-License-Identifier: MIT
|
2015-12-04 14:54:05 +00:00
|
|
|
|
2020-06-09 15:03:35 +01:00
|
|
|
# This script is executed by GitHub Actions when a PR is merged (i.e. in the `deploy` step).
|
2019-02-04 22:34:33 +00:00
|
|
|
set -ex
|
2015-12-04 14:54:05 +00:00
|
|
|
|
|
|
|
function initialize {
|
2023-10-26 17:41:24 +01:00
|
|
|
if [[ -z $TLDRHOME ]]; then
|
2020-06-09 15:03:35 +01:00
|
|
|
export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)}
|
2015-12-04 14:54:05 +00:00
|
|
|
fi
|
2019-07-10 17:38:59 +01:00
|
|
|
|
2023-08-16 06:09:53 +01:00
|
|
|
export TLDR_LANG_ARCHIVES_DIRECTORY="$TLDRHOME/language_archives"
|
2023-10-21 22:04:22 +01:00
|
|
|
export TLDR_PDF_FILES_DIRECTORY="$TLDRHOME/scripts/pdf"
|
2015-12-04 14:54:05 +00:00
|
|
|
export TLDR_ARCHIVE="tldr.zip"
|
|
|
|
export SITE_HOME="$HOME/site"
|
2019-02-03 13:57:35 +00:00
|
|
|
export SITE_REPO_SLUG="tldr-pages/tldr-pages.github.io"
|
2015-12-04 14:54:05 +00:00
|
|
|
|
2019-02-04 13:59:17 +00:00
|
|
|
# Configure git.
|
2021-02-22 12:45:12 +00:00
|
|
|
git config --global user.email "tldrbotgithub@gmail.com"
|
|
|
|
git config --global user.name "tldr bot"
|
2015-12-04 14:54:05 +00:00
|
|
|
git config --global push.default simple
|
|
|
|
git config --global diff.zip.textconv "unzip -c -a"
|
2019-02-04 13:59:17 +00:00
|
|
|
|
|
|
|
# Decrypt and add deploy key.
|
|
|
|
eval "$(ssh-agent -s)"
|
2020-06-24 13:30:09 +01:00
|
|
|
echo "${DEPLOY_KEY}"> id_ed25519
|
2019-02-04 13:59:17 +00:00
|
|
|
chmod 600 id_ed25519
|
|
|
|
ssh-add id_ed25519
|
2015-12-04 14:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function upload_assets {
|
2019-05-23 14:27:29 +01:00
|
|
|
git clone --quiet --depth 1 git@github.com:${SITE_REPO_SLUG}.git "$SITE_HOME"
|
2023-12-25 07:10:22 +00:00
|
|
|
[[ -f "$TLDR_ARCHIVE" ]] && mv -f "$TLDR_ARCHIVE" "$SITE_HOME/assets/"
|
2023-12-19 16:36:17 +00:00
|
|
|
find "$TLDR_LANG_ARCHIVES_DIRECTORY" -maxdepth 1 -name "*.zip" -exec mv -f {} "$SITE_HOME/assets/" \;
|
2023-08-16 06:09:53 +01:00
|
|
|
rm -rf "$TLDR_LANG_ARCHIVES_DIRECTORY"
|
2023-12-25 07:10:22 +00:00
|
|
|
[[ -f "$TLDRHOME/index.json" ]] && cp -f "$TLDRHOME/index.json" "$SITE_HOME/assets/"
|
2023-12-19 16:36:17 +00:00
|
|
|
find "$TLDR_PDF_FILES_DIRECTORY" -maxdepth 1 -name "*.pdf" -exec mv -f {} "$SITE_HOME/assets/" \;
|
2023-10-21 22:04:22 +01:00
|
|
|
rm -rf "$TLDR_PDF_FILES_DIRECTORY"
|
2015-12-04 14:54:05 +00:00
|
|
|
|
2023-12-24 16:51:07 +00:00
|
|
|
cd "$SITE_HOME/assets"
|
|
|
|
sha256sum -- index.json *.zip > tldr.sha256sums
|
2020-11-27 09:29:09 +00:00
|
|
|
|
2023-12-25 07:10:22 +00:00
|
|
|
# Check if there are changes before committing and pushing.
|
|
|
|
if git diff --quiet; then
|
|
|
|
echo "No changes to deploy."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2019-02-03 13:57:35 +00:00
|
|
|
git add -A
|
2021-01-03 21:48:47 +00:00
|
|
|
git commit -m "[GitHub Actions] uploaded assets after commit tldr-pages/tldr@${GITHUB_SHA}"
|
2015-12-04 23:09:18 +00:00
|
|
|
git push -q
|
2023-12-25 07:10:22 +00:00
|
|
|
echo "Assets (pages archive, index and checksum) deployed to the static site."
|
2015-12-04 14:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# MAIN
|
|
|
|
###################################
|
|
|
|
|
2019-02-04 13:59:17 +00:00
|
|
|
initialize
|
2019-02-04 22:34:33 +00:00
|
|
|
upload_assets
|