2025-03-14 21:59:59 -06:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
|
|
# This script is executed by GitHub Actions when a PR is merged (i.e. in the `deploy` step).
|
|
|
|
|
set -ex
|
|
|
|
|
|
|
|
|
|
function initialize {
|
|
|
|
|
export TLDR_ARCHIVE="tldr.zip"
|
|
|
|
|
|
|
|
|
|
if [[ ! -f $TLDR_ARCHIVE ]]; then
|
|
|
|
|
echo "No changes to deploy."
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
export ASSETS="$HOME/assets"
|
2025-03-14 21:59:59 -06:00
|
|
|
export LANG_ARCHIVES="$GITHUB_WORKSPACE/language_archives"
|
|
|
|
|
export PDFS="$GITHUB_WORKSPACE/scripts/pdf"
|
|
|
|
|
export INDEX="$GITHUB_WORKSPACE/index.json"
|
|
|
|
|
RELEASE_TAG="$(git describe --tags --abbrev=0)"
|
|
|
|
|
export RELEASE_TAG
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function upload_assets {
|
2026-02-18 06:55:01 -07:00
|
|
|
mkdir "$ASSETS"
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
# Assets are built only for changed directories.
|
|
|
|
|
# We need the old zip archives to update `tldr.sha256sums`.
|
|
|
|
|
gh release --repo tldr-pages/tldr download "$RELEASE_TAG" --dir "$ASSETS" --pattern "*.zip"
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
# Suppress errors from unmatched patterns if some files don't exist.
|
|
|
|
|
shopt -s nullglob
|
2026-02-18 06:55:01 -07:00
|
|
|
cp -t "$ASSETS" "$TLDR_ARCHIVE" "$INDEX" "$LANG_ARCHIVES"/*.zip "$PDFS"/*.pdf
|
|
|
|
|
|
|
|
|
|
cd "$ASSETS"
|
|
|
|
|
sha256sum -- index.json *.zip > tldr.sha256sums
|
|
|
|
|
|
2025-03-14 21:59:59 -06:00
|
|
|
gh release --repo tldr-pages/tldr upload --clobber "$RELEASE_TAG" -- \
|
|
|
|
|
tldr.sha256sums \
|
|
|
|
|
"$TLDR_ARCHIVE" \
|
|
|
|
|
"$INDEX" \
|
|
|
|
|
"$LANG_ARCHIVES/"*.zip \
|
|
|
|
|
"$PDFS/"*.pdf
|
2026-02-18 06:55:01 -07:00
|
|
|
|
2025-03-14 21:59:59 -06:00
|
|
|
shopt -u nullglob
|
|
|
|
|
echo "Assets deployed to GitHub releases."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
###################################
|
|
|
|
|
# MAIN
|
|
|
|
|
###################################
|
|
|
|
|
|
|
|
|
|
initialize
|
|
|
|
|
upload_assets
|