build.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env bash
  2. # SPDX-License-Identifier: MIT
  3. # This script is executed by GitHub Actions for every successful push (on any branch, PR or not).
  4. set -ex
  5. function initialize {
  6. if [[ -z $TLDRHOME ]]; then
  7. export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)}
  8. fi
  9. if [[ -z $TLDR_LANG_ARCHIVES_DIRECTORY ]]; then
  10. export TLDR_LANG_ARCHIVES_DIRECTORY="${GITHUB_WORKSPACE:-$(pwd)}/language_archives"
  11. fi
  12. export TLDR_ARCHIVE="tldr.zip"
  13. }
  14. function build_index {
  15. npm run build-index
  16. echo "Pages index successfully built."
  17. }
  18. function build_archive {
  19. rm -f "$TLDR_ARCHIVE"
  20. cd "$TLDRHOME/"
  21. zip -q -r "$TLDR_ARCHIVE" pages* LICENSE.md index.json
  22. echo "Pages archive successfully built."
  23. }
  24. function build_translation_archives {
  25. local source_directory="$TLDRHOME"
  26. local target_directory="$TLDR_LANG_ARCHIVES_DIRECTORY"
  27. mkdir -p "$target_directory"
  28. rm -f "$target_directory"/*
  29. for lang_dir in "$source_directory"/pages*; do
  30. # Skip symlinks (pages.en) and things that are not directories
  31. if [[ ! -d $lang_dir || -h $lang_dir ]]; then
  32. continue
  33. fi
  34. local lang=$(basename "$lang_dir")
  35. local archive_name="tldr-$lang.zip"
  36. # Create the zip archive
  37. cd "$lang_dir"
  38. zip -q -r "$target_directory/$archive_name" .
  39. zip -q -j "$target_directory/$archive_name" "$source_directory/LICENSE.md"
  40. echo "Pages archive of $archive_name successfully created."
  41. done
  42. cd "$target_directory"
  43. cp tldr-pages.zip tldr-pages.en.zip
  44. }
  45. ###################################
  46. # MAIN
  47. ###################################
  48. initialize
  49. build_index
  50. build_archive
  51. build_translation_archives