diff --git a/.github/workflows/check_shell_scripts.yml b/.github/workflows/check_shell_scripts.yml new file mode 100644 index 000000000000..1a80281ec50a --- /dev/null +++ b/.github/workflows/check_shell_scripts.yml @@ -0,0 +1,30 @@ +--- +name: check_shell_scripts + +# yamllint disable-line rule:truthy +on: + workflow_dispatch: + push: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + run_shellcheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install shellcheck + run: | + sudo apt-get install shellcheck + + - name: display shellcheck version + run: | + shellcheck --version + + - name: run check_shell_scripts + run: | + ./scripts/checkShellScripts.sh +... diff --git a/apps/librelingo-standalone-server/build.sh b/apps/librelingo-standalone-server/build.sh index 0a637439cc42..bdebe3cc2dcb 100755 --- a/apps/librelingo-standalone-server/build.sh +++ b/apps/librelingo-standalone-server/build.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -euo pipefail + DIRNAME=$(dirname "$0") DEFAULT_OUTPUT_DIR="$DIRNAME/bin" if [ -n "$1" ]; then @@ -29,7 +31,7 @@ cp -r "$WEBSITE_DIR" "$BUILD_DIR/static" cd "$DIRNAME" cp -r ./* "$BUILD_DIR" -set -eux +set -x cd "$BUILD_DIR" # prepare pkger diff --git a/apps/web/package.json b/apps/web/package.json index b2a5077dadc6..128e162059f7 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -15,7 +15,7 @@ "installAllExternalCourses": "./scripts/installExternalCourses.sh", "fetchPhotos": "./scripts/fetchPhotos.sh", "fetchAudios": "./scripts/fetchAudios.sh", - "percypress": "sh ./percypress.sh", + "percypress": "bash ./percypress.sh", "test": "yarn dev & yarn percypress", "test:ci": "npx serve __sapper__/export -l 3000 & yarn percypress", "prettierfix": "yarn prettierfix:src && yarn prettierfix:cypress && yarn prettierfix:svelte", diff --git a/apps/web/percypress.sh b/apps/web/percypress.sh index 39b7211c3cfa..f53245f44dff 100644 --- a/apps/web/percypress.sh +++ b/apps/web/percypress.sh @@ -1,9 +1,12 @@ #!/bin/bash + +set -euo pipefail + # if [ "$KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC" = "" ]; then # echo "KNAPSACK PRO NOT ENABLED" # KNAPSACK_PRO_ENDPOINT=https://api-disabled-for-fork.knapsackpro.com \ # KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=disabled-for-fork \ -# KNAPSACK_PRO_MAX_REQUEST_RETRIES=0 +# KNAPSACK_PRO_MAX_REQUEST_RETRIES=0 # # percy exec -- yarn cy:run # yarn cy:run # else diff --git a/apps/web/scripts/fetchPhoto.sh b/apps/web/scripts/fetchPhoto.sh index 71d1d041a6c8..aec10834b1db 100755 --- a/apps/web/scripts/fetchPhoto.sh +++ b/apps/web/scripts/fetchPhoto.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -euo pipefail + url=$(echo "$1" | cut -d',' -f2) image_name=$(echo "$1" | cut -d',' -f1) image_id=$(echo "$url" | cut -d'/' -f5) diff --git a/apps/web/scripts/fetchPhotos.sh b/apps/web/scripts/fetchPhotos.sh index 0de7f97a692e..74a406eb799d 100755 --- a/apps/web/scripts/fetchPhotos.sh +++ b/apps/web/scripts/fetchPhotos.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -euo pipefail + tail -n +2 ../../docs/image_attributions.csv | while read -r photo_description; do \ ./scripts/fetchPhoto.sh "$photo_description"; \ done diff --git a/apps/web/scripts/installExternalCourse.sh b/apps/web/scripts/installExternalCourse.sh index 127134b1ed0c..e0b4e124d54c 100755 --- a/apps/web/scripts/installExternalCourse.sh +++ b/apps/web/scripts/installExternalCourse.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -euo pipefail + wget "$1" -O temp.zip unzip temp.zip "*/course/*" -d ../../courses/"$2" mv ../../courses/"$2"/*/course/* ../../courses/"$2" diff --git a/apps/web/scripts/installExternalCourses.sh b/apps/web/scripts/installExternalCourses.sh index f84019b81ee1..1cfd959ae66c 100755 --- a/apps/web/scripts/installExternalCourses.sh +++ b/apps/web/scripts/installExternalCourses.sh @@ -1,8 +1,9 @@ #!/usr/bin/env bash +set -euo pipefail + yarn installCourse "https://github.com/LibreLingo/LibreLingo-ES-from-EN/archive/refs/heads/main.zip" spanish-from-english yarn installCourse https://codeberg.org/Lamdarer/LibreLingo-DE-from-EN/archive/main.zip german-from-english yarn installCourse "https://github.com/szabgab/LibreLingo-Judeo-Spanish-from-English/archive/refs/heads/main.zip" ladino-from-english yarn installCourse "https://github.com/szabgab/LibreLingo-Judeo-Spanish-from-Spanish/archive/refs/heads/main.zip" ladino-from-spanish yarn installCourse "https://github.com/szabgab/LibreLingo-Judeo-Spanish-from-Hebrew/archive/refs/heads/main.zip" ladino-from-hebrew - diff --git a/apps/web/scripts/updateAllCourseData.sh b/apps/web/scripts/updateAllCourseData.sh index 1a4b5d6883d8..8332c222848b 100755 --- a/apps/web/scripts/updateAllCourseData.sh +++ b/apps/web/scripts/updateAllCourseData.sh @@ -1,8 +1,10 @@ #!/usr/bin/env bash +set -euo pipefail + if output=$(git status --porcelain) && [ -z "$output" ]; then echo "Working directory clean. Fetching course data..." -else +else echo "Working directory not clean. Please commit your changes before running this script." exit 1 fi diff --git a/scripts/checkShellScripts.sh b/scripts/checkShellScripts.sh new file mode 100755 index 000000000000..76d3ab6ba799 --- /dev/null +++ b/scripts/checkShellScripts.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -euo pipefail + +declare -i exit_code=0 + +if [[ $(basename "$PWD") != "LibreLingo" ]]; then + printf "Start this script from the root directory of the project.\n" + exit 2 +fi + +while IFS="" read -r cur_script +do + printf "Checking \"%s\"\n" "${cur_script}" + if ! shellcheck "$cur_script"; then + exit_code=1 + fi + if ! grep -q "set -euo pipefail" "$cur_script"; then + printf "add \"set -euo pipefail\"\n" + exit_code=1 + fi +done < <(find . -name "*.sh" -not -path "./node_modules/*") + +exit "$exit_code" diff --git a/scripts/exportAllYamlCourses.sh b/scripts/exportAllYamlCourses.sh index f996a29d4a93..184e3da344c6 100755 --- a/scripts/exportAllYamlCourses.sh +++ b/scripts/exportAllYamlCourses.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -euo pipefail + ANY_FAILED="0" for d in ./courses/*/ ; do d=$(echo "$d" | sed 's/[^/]*\/[^/]*\///' | sed 's/\///') diff --git a/scripts/exportYamlCourse.sh b/scripts/exportYamlCourse.sh index da5241e73397..6381b79a8aef 100755 --- a/scripts/exportYamlCourse.sh +++ b/scripts/exportYamlCourse.sh @@ -1,13 +1,14 @@ #!/bin/bash +set -euo pipefail + echo -en "⏳ Exporting course $1" cd ./apps/librelingo_json_export/ || { echo -en "\r⚠️ Wrong folder structure" exit 1 } -poetry run export-cli ../../courses/"$1" ../../apps/web/src/courses/"$1" -if [ $? -eq 0 ]; then +if poetry run export-cli ../../courses/"$1" ../../apps/web/src/courses/"$1"; then echo -en "\r✅ Exported course $1" else echo -en "\r⚠️ Couldn't export course $1" diff --git a/scripts/runAutoMaintenance.sh b/scripts/runAutoMaintenance.sh index 8f58143a1599..ad8e2dc65cac 100755 --- a/scripts/runAutoMaintenance.sh +++ b/scripts/runAutoMaintenance.sh @@ -1,4 +1,6 @@ #!/bin/bash +set -euo pipefail + yarn exportAllCourses ./scripts/updatePypiReadmeFiles.sh diff --git a/scripts/updateAudioForAllYamlCourses.sh b/scripts/updateAudioForAllYamlCourses.sh index 262117912ecc..7b26317e3f2d 100755 --- a/scripts/updateAudioForAllYamlCourses.sh +++ b/scripts/updateAudioForAllYamlCourses.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -euo pipefail + for d in ./courses/*/ ; do d=$(echo "$d" | sed 's/[^/]*\/[^/]*\///' | sed 's/\///') ./scripts/updateAudioForYamlCourse.sh "$d" "$@" diff --git a/scripts/updateAudioForYamlCourse.sh b/scripts/updateAudioForYamlCourse.sh index efe5a5fd642b..64f3b5d65ea9 100755 --- a/scripts/updateAudioForYamlCourse.sh +++ b/scripts/updateAudioForYamlCourse.sh @@ -1,13 +1,14 @@ #!/bin/bash +set -euo pipefail + echo -en "⏳ Updating audio for course $1" cd ./apps/librelingo_audios/ || { echo -en "\r⚠️ Wrong folder structure" exit 1 } -poetry run python librelingo_audios/cli.py ../../courses/"$1" ../../apps/web/static/voice "$1" "${@:2}" -if [ $? -eq 0 ]; then +if poetry run python librelingo_audios/cli.py ../../courses/"$1" ../../apps/web/static/voice "$1" "${@:2}"; then echo -en "\r✅ Updated audio for course $1" else echo -en "\r⚠️ Couldn't update audio for course $1" diff --git a/scripts/updatePypiReadmeFiles.sh b/scripts/updatePypiReadmeFiles.sh index ec145d7746a9..e5f5fac3b57e 100755 --- a/scripts/updatePypiReadmeFiles.sh +++ b/scripts/updatePypiReadmeFiles.sh @@ -1,14 +1,25 @@ #!/bin/bash -for directory in $(find apps/ -name pyproject.toml | xargs -n1 dirname); do - echo "Updating README.md for Python package '$(basename "$directory")'..." - cd "$directory" || - { - echo -en "\r⚠️ Could not enter $directory" - exit 1 - } - poetry install - make README.md -B "$1" - cd - - echo -done +set -euo pipefail + +find apps/ -name pyproject.toml -exec dirname {} \; | + while IFS="" read -r directory + do + echo "Updating README.md for Python package '$(basename "$directory")'..." + cd "$directory" || + { + echo -en "\r⚠️ Could not enter $directory" + exit 1 + } + poetry install + make README.md -B || + { + echo -en "\r⚠️ Could not update README.md for Python package '$(basename "$directory")'..." + } + cd - || + { + echo -en "\r⚠️ Could not return to previous directory" + exit 1 + } + echo + done diff --git a/scripts/verifyPypiReadmeFiles.sh b/scripts/verifyPypiReadmeFiles.sh index 69b29e70319a..e04b800e8344 100755 --- a/scripts/verifyPypiReadmeFiles.sh +++ b/scripts/verifyPypiReadmeFiles.sh @@ -1,6 +1,8 @@ #!/bin/bash -./scripts/updatePypiReadmeFiles.sh -B +set -euo pipefail + +./scripts/updatePypiReadmeFiles.sh if git diff --exit-code --name-only; then echo "🎉 Amazing, PyPi readme files are up to date" diff --git a/scripts/verifyTestCourseJsonFiles.sh b/scripts/verifyTestCourseJsonFiles.sh index ab4ec0445a86..57236ff1dc28 100755 --- a/scripts/verifyTestCourseJsonFiles.sh +++ b/scripts/verifyTestCourseJsonFiles.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -euo pipefail + yarn exportCourse test if git diff --exit-code --name-only; then