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 {
|
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)}
|
2019-07-10 17:38:59 +01:00
|
|
|
fi
|
|
|
|
|
2023-10-26 17:41:24 +01:00
|
|
|
if [[ -z $TLDR_LANG_ARCHIVES_DIRECTORY ]]; then
|
2023-08-16 06:09:53 +01:00
|
|
|
export TLDR_LANG_ARCHIVES_DIRECTORY="${GITHUB_WORKSPACE:-$(pwd)}/language_archives"
|
|
|
|
fi
|
|
|
|
|
2019-07-10 17:38:59 +01:00
|
|
|
export TLDR_ARCHIVE="tldr.zip"
|
2023-12-25 18:39:17 +00:00
|
|
|
DIFF="$(git diff --name-only @^ @ | cut -d'/' -f1)"
|
|
|
|
export DIFF
|
2019-07-10 17:38:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function build_index {
|
2023-12-25 18:39:17 +00:00
|
|
|
if ! grep -xq "pages.*" <<< "$DIFF"; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2019-07-10 17:38:59 +01:00
|
|
|
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 {
|
2023-12-25 18:39:17 +00:00
|
|
|
if ! grep -xq "pages.*" <<< "$DIFF"; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2019-07-10 17:38:59 +01:00
|
|
|
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 {
|
2023-12-25 18:39:17 +00:00
|
|
|
local source_directory target_directory lang archive_name
|
|
|
|
source_directory="$TLDRHOME"
|
|
|
|
target_directory="$TLDR_LANG_ARCHIVES_DIRECTORY"
|
2023-08-16 06:09:53 +01:00
|
|
|
mkdir -p "$target_directory"
|
2023-10-26 17:41:24 +01:00
|
|
|
rm -f "$target_directory"/*
|
2023-08-16 06:09:53 +01:00
|
|
|
|
|
|
|
for lang_dir in "$source_directory"/pages*; do
|
2023-12-25 18:39:17 +00:00
|
|
|
lang=$(basename "$lang_dir")
|
|
|
|
# Skip symlinks (pages.en), files outside pages* and directories that haven't been changed.
|
|
|
|
if [[ ! -d $lang_dir || -h $lang_dir ]] || ! grep -Fxq "$lang" <<< "$DIFF"; then
|
2023-10-21 21:02:19 +01:00
|
|
|
continue
|
|
|
|
fi
|
2023-08-16 06:09:53 +01:00
|
|
|
|
2023-12-25 18:39:17 +00:00
|
|
|
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-12-25 18:39:17 +00:00
|
|
|
if grep -Fxq pages <<< "$DIFF"; then
|
|
|
|
cp tldr-pages.zip tldr-pages.en.zip
|
|
|
|
fi
|
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
|