2019-07-10 17:38:59 +01:00
|
|
|
#!/usr/bin/env bash
|
2021-07-16 14:15:31 +01:00
|
|
|
# SPDX-License-Identifier: MIT
|
2019-07-10 17:38:59 +01:00
|
|
|
|
2020-06-09 15:03:35 +01:00
|
|
|
# This script is executed by GitHub Actions for every successful push (on any branch, PR or not).
|
2019-07-10 17:38:59 +01:00
|
|
|
set -ex
|
|
|
|
|
|
|
|
function initialize {
|
|
|
|
if [ -z "$TLDRHOME" ]; then
|
2020-06-09 15:03:35 +01:00
|
|
|
export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)}
|
2019-07-10 17:38:59 +01:00
|
|
|
fi
|
|
|
|
|
2023-08-16 06:09:53 +01:00
|
|
|
if [ -z "$TLDR_LANG_ARCHIVES_DIRECTORY" ]; then
|
|
|
|
export TLDR_LANG_ARCHIVES_DIRECTORY="${GITHUB_WORKSPACE:-$(pwd)}/language_archives"
|
|
|
|
fi
|
|
|
|
|
2019-07-10 17:38:59 +01:00
|
|
|
export TLDR_ARCHIVE="tldr.zip"
|
|
|
|
}
|
|
|
|
|
|
|
|
function build_index {
|
|
|
|
npm run build-index
|
2021-09-16 04:32:13 +01:00
|
|
|
echo "Pages index successfully built."
|
2019-07-10 17:38:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function build_archive {
|
|
|
|
rm -f "$TLDR_ARCHIVE"
|
|
|
|
cd "$TLDRHOME/"
|
|
|
|
zip -q -r "$TLDR_ARCHIVE" pages* LICENSE.md index.json
|
2021-09-16 04:32:13 +01:00
|
|
|
echo "Pages archive successfully built."
|
2019-07-10 17:38:59 +01:00
|
|
|
}
|
|
|
|
|
2023-08-16 06:09:53 +01:00
|
|
|
function build_translation_archives {
|
|
|
|
local source_directory="$TLDRHOME"
|
|
|
|
local target_directory="$TLDR_LANG_ARCHIVES_DIRECTORY"
|
|
|
|
mkdir -p "$target_directory"
|
|
|
|
rm -f "$target_directory/*"
|
|
|
|
|
|
|
|
for lang_dir in "$source_directory"/pages*; do
|
2023-10-21 21:02:19 +01:00
|
|
|
# Skip symlinks (pages.en) and things that are not directories
|
|
|
|
if [ ! -d "$lang_dir" ] || [ -h "$lang_dir" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2023-08-16 06:09:53 +01:00
|
|
|
|
2023-10-21 21:02:19 +01:00
|
|
|
local lang=$(basename "$lang_dir")
|
|
|
|
local archive_name="tldr-$lang.zip"
|
2023-08-16 06:09:53 +01:00
|
|
|
|
2023-10-21 21:02:19 +01:00
|
|
|
# Create the zip archive
|
2023-08-16 06:09:53 +01:00
|
|
|
|
2023-10-21 21:02:19 +01:00
|
|
|
cd "$lang_dir"
|
|
|
|
zip -q -r "$target_directory/$archive_name" .
|
|
|
|
zip -q -j "$target_directory/$archive_name" "$source_directory/LICENSE.md"
|
|
|
|
|
|
|
|
echo "Pages archive of $archive_name successfully created."
|
2023-08-16 06:09:53 +01:00
|
|
|
done
|
2023-10-21 21:02:19 +01:00
|
|
|
|
|
|
|
cd "$target_directory"
|
2023-10-24 12:14:27 +01:00
|
|
|
cp tldr-pages.zip tldr-pages.en.zip
|
2023-08-16 06:09:53 +01:00
|
|
|
}
|
|
|
|
|
2019-07-10 17:38:59 +01:00
|
|
|
###################################
|
|
|
|
# MAIN
|
|
|
|
###################################
|
|
|
|
|
|
|
|
initialize
|
|
|
|
build_index
|
|
|
|
build_archive
|
2023-08-16 06:09:53 +01:00
|
|
|
build_translation_archives
|