1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-07-01 23:35:24 +02:00

scripts: use [[ instead of [, fix literal shell globs (#11290)

* build.sh: move `*` outside quotes (it doesn't get expanded)

* scripts: use `[[` instead of `[` in if statements
This commit is contained in:
Lena 2023-10-26 18:41:24 +02:00 committed by GitHub
parent 1ba64fc0d7
commit 250b9d7c21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 18 deletions

View file

@ -5,11 +5,11 @@
set -ex set -ex
function initialize { function initialize {
if [ -z "$TLDRHOME" ]; then if [[ -z $TLDRHOME ]]; then
export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)} export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)}
fi fi
if [ -z "$TLDR_LANG_ARCHIVES_DIRECTORY" ]; then if [[ -z $TLDR_LANG_ARCHIVES_DIRECTORY ]]; then
export TLDR_LANG_ARCHIVES_DIRECTORY="${GITHUB_WORKSPACE:-$(pwd)}/language_archives" export TLDR_LANG_ARCHIVES_DIRECTORY="${GITHUB_WORKSPACE:-$(pwd)}/language_archives"
fi fi
@ -32,11 +32,11 @@ function build_translation_archives {
local source_directory="$TLDRHOME" local source_directory="$TLDRHOME"
local target_directory="$TLDR_LANG_ARCHIVES_DIRECTORY" local target_directory="$TLDR_LANG_ARCHIVES_DIRECTORY"
mkdir -p "$target_directory" mkdir -p "$target_directory"
rm -f "$target_directory/*" rm -f "$target_directory"/*
for lang_dir in "$source_directory"/pages*; do for lang_dir in "$source_directory"/pages*; do
# Skip symlinks (pages.en) and things that are not directories # Skip symlinks (pages.en) and things that are not directories
if [ ! -d "$lang_dir" ] || [ -h "$lang_dir" ]; then if [[ ! -d $lang_dir || -h $lang_dir ]]; then
continue continue
fi fi

View file

@ -30,14 +30,14 @@ function check_duplicates {
case "$platform" in case "$platform" in
common) # check if page already exists in other platforms common) # check if page already exists in other platforms
for other in ${PLATFORMS/common/}; do for other in ${PLATFORMS/common/}; do
if [ -f "pages/$other/$file" ]; then if [[ -f "pages/$other/$file" ]]; then
printf "\x2d $MSG_EXISTS" "$page" "$other" printf "\x2d $MSG_EXISTS" "$page" "$other"
fi fi
done done
;; ;;
*) # check if page already exists under common *) # check if page already exists under common
if [ -f "pages/common/$file" ]; then if [[ -f "pages/common/$file" ]]; then
printf "\x2d $MSG_EXISTS" "$page" 'common' printf "\x2d $MSG_EXISTS" "$page" 'common'
fi fi
;; ;;
@ -52,7 +52,7 @@ function check_diff {
git_diff=$(git diff --name-status --find-copies-harder --diff-filter=AC --relative=pages/ remotes/origin/main) git_diff=$(git diff --name-status --find-copies-harder --diff-filter=AC --relative=pages/ remotes/origin/main)
if [ -n "$git_diff" ]; then if [[ -n $git_diff ]]; then
echo -e "Check PR: git diff:\n$git_diff" >&2 echo -e "Check PR: git diff:\n$git_diff" >&2
else else
echo 'Check PR: git diff looks fine, no interesting changes detected.' >&2 echo 'Check PR: git diff looks fine, no interesting changes detected.' >&2
@ -85,13 +85,13 @@ function check_diff {
# Recursively check the pages/ folder for anomalies. # Recursively check the pages/ folder for anomalies.
function check_structure { function check_structure {
for platform in $PLATFORMS; do for platform in $PLATFORMS; do
if [ ! -d "pages/$platform" ]; then if [[ ! -d "pages/$platform" ]]; then
printf "\x2d $MSG_NOT_DIR" "pages/$platform" printf "\x2d $MSG_NOT_DIR" "pages/$platform"
else else
for page in "pages/$platform"/*; do for page in "pages/$platform"/*; do
if [ ! -f "$page" ]; then if [[ ! -f $page ]]; then
printf "\x2d $MSG_NOT_FILE" "$page" printf "\x2d $MSG_NOT_FILE" "$page"
elif [ "${page:(-3)}" != ".md" ]; then elif [[ ${page:(-3)} != ".md" ]]; then
printf "\x2d $MSG_NOT_MD" "$page" printf "\x2d $MSG_NOT_MD" "$page"
fi fi
done done
@ -111,7 +111,7 @@ MSG_NOT_MD='The file `%s` does not have a `.md` extension.\n'
PLATFORMS=$(ls pages/) PLATFORMS=$(ls pages/)
if [ "$CI" = "true" ] && [ "$GITHUB_REPOSITORY" = "tldr-pages/tldr" ] && [ "$PULL_REQUEST_ID" != "" ]; then if [[ $CI == true && $GITHUB_REPOSITORY == "tldr-pages/tldr" && $PULL_REQUEST_ID != "" ]]; then
check_diff check_diff
check_structure check_structure
else else

View file

@ -5,7 +5,7 @@
set -ex set -ex
function initialize { function initialize {
if [ -z "$TLDRHOME" ]; then if [[ -z $TLDRHOME ]]; then
export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)} export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)}
fi fi

View file

@ -24,9 +24,9 @@ function run_black {
errs=$(python3 -m black scripts --check --required-version ${target_black_version} 2>&1 || true) errs=$(python3 -m black scripts --check --required-version ${target_black_version} 2>&1 || true)
fi fi
if [ -z "${errs}" ]; then if [[ -z $errs ]]; then
# skip black check if command is not available in the system. # skip black check if command is not available in the system.
if [ "$CI" != "true" ] && ! exists black; then if [[ $CI != true ]] && ! exists black; then
echo "Skipping black check, command not available." echo "Skipping black check, command not available."
return 0 return 0
fi fi
@ -49,7 +49,7 @@ function run_black {
function run_flake8 { function run_flake8 {
# skip flake8 check if command is not available in the system. # skip flake8 check if command is not available in the system.
if [ "$CI" != "true" ] && ! exists flake8; then if [[ $CI != true ]] && ! exists flake8; then
echo "Skipping flake8 check, command not available." echo "Skipping flake8 check, command not available."
return 0 return 0
fi fi
@ -73,7 +73,7 @@ function run_tests {
function run_tests_pr { function run_tests_pr {
errs=$(run_tests 2>&1) errs=$(run_tests 2>&1)
if [ -n "$errs" ]; then if [[ -n $errs ]]; then
echo -e "Test failed!\n$errs\n" >&2 echo -e "Test failed!\n$errs\n" >&2
echo 'Sending errors to tldr-bot.' >&2 echo 'Sending errors to tldr-bot.' >&2
echo -n "$errs" | python3 scripts/send-to-bot.py report-errors echo -n "$errs" | python3 scripts/send-to-bot.py report-errors
@ -86,7 +86,7 @@ function run_tests_pr {
function run_checks_pr { function run_checks_pr {
msgs=$(bash scripts/check-pr.sh) msgs=$(bash scripts/check-pr.sh)
if [ -n "$msgs" ]; then if [[ -n $msgs ]]; then
echo -e "\nCheck PR reported the following message(s):\n$msgs\n" >&2 echo -e "\nCheck PR reported the following message(s):\n$msgs\n" >&2
echo 'Sending check results to tldr-bot.' >&2 echo 'Sending check results to tldr-bot.' >&2
echo -n "$msgs" | python3 scripts/send-to-bot.py report-check-results echo -n "$msgs" | python3 scripts/send-to-bot.py report-check-results
@ -97,7 +97,7 @@ function run_checks_pr {
# MAIN # MAIN
################################### ###################################
if [ "$CI" = "true" ] && [ "$GITHUB_REPOSITORY" = "tldr-pages/tldr" ] && [ "$PULL_REQUEST_ID" != "" ]; then if [[ $CI == true && $GITHUB_REPOSITORY == "tldr-pages/tldr" && $PULL_REQUEST_ID != "" ]]; then
run_checks_pr run_checks_pr
run_tests_pr run_tests_pr
else else