1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-23 13:02:08 +02:00
tldr/scripts/build.sh
Lena d123d51d17
scripts: don't build archives when pages haven't been changed (#11825)
* scripts/build.sh: don't build archives when pages haven't been changed

* scripts: don't build the index when pages haven't been changed, fix
deploy.sh

* feat: check for changes before committing in deploy.sh

* cleanup: update scripts/deploy.sh

Co-authored-by: Lena <126529524+acuteenvy@users.noreply.github.com>

---------

Co-authored-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com>
2023-12-25 12:40:22 +05:30

79 lines
1.9 KiB
Bash
Executable file

#!/usr/bin/env bash
# SPDX-License-Identifier: MIT
# This script is executed by GitHub Actions for every successful push (on any branch, PR or not).
set -ex
function initialize {
if [[ -z $TLDRHOME ]]; then
export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)}
fi
if [[ -z $TLDR_LANG_ARCHIVES_DIRECTORY ]]; then
export TLDR_LANG_ARCHIVES_DIRECTORY="${GITHUB_WORKSPACE:-$(pwd)}/language_archives"
fi
export TLDR_ARCHIVE="tldr.zip"
DIFF="$(git diff --name-only @^ @ | cut -d'/' -f1)"
export DIFF
}
function build_index {
if ! grep -xq "pages.*" <<< "$DIFF"; then
return
fi
npm run build-index
echo "Pages index successfully built."
}
function build_archive {
if ! grep -xq "pages.*" <<< "$DIFF"; then
return
fi
rm -f "$TLDR_ARCHIVE"
cd "$TLDRHOME/"
zip -q -r "$TLDR_ARCHIVE" pages* LICENSE.md index.json
echo "Pages archive successfully built."
}
function build_translation_archives {
local source_directory target_directory lang archive_name
source_directory="$TLDRHOME"
target_directory="$TLDR_LANG_ARCHIVES_DIRECTORY"
mkdir -p "$target_directory"
rm -f "$target_directory"/*
for lang_dir in "$source_directory"/pages*; do
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
continue
fi
archive_name="tldr-$lang.zip"
# Create the zip archive
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."
done
cd "$target_directory"
if grep -Fxq pages <<< "$DIFF"; then
cp tldr-pages.zip tldr-pages.en.zip
fi
}
###################################
# MAIN
###################################
initialize
build_index
build_archive
build_translation_archives