Skip to content

Commit

Permalink
feat: use shellcheck in CI (#2010)
Browse files Browse the repository at this point in the history
* fix: use while read with find

* style: use safe cd

* feat: add checkSellScripts.sh

* fix: use set -euo pipefail

* fix: use "set -euo pipefail"

* fix: use "set -euo pipefail"

* fix: use "set -euo pipefail"

* fix: use "set -euo pipefail"

* fix: use "set -euo pipefail"

* fix: use "set -euo pipefail"

* fix: use "set -euo pipefail"

* chore: update repository URL in configuration file

* fix: update links to point to https://github.com/LibreLingo/LibreLingo instead of https://github.com/kantord/LibreLingo

* fix: linking the contributors batch to the contributors section

* fix: use "set -euo pipefail"

* fix: revert change

* fix: use bash

* fix: use "set -euo pipefail"

* style: avoid using $?

* style: avoid using $?

* fix: remove redundant command line arguments

* fix: use "set -euo pipefail"

* fix: add warning

* fix: fix spacing

* feat: add check_shell_scripts.sh

Co-authored-by: Gabor Szabo <gabor@szabgab.com>
  • Loading branch information
vil02 and szabgab committed Jan 22, 2022
1 parent 99ffe7a commit d98dab8
Show file tree
Hide file tree
Showing 18 changed files with 113 additions and 22 deletions.
30 changes: 30 additions & 0 deletions .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
...
4 changes: 3 additions & 1 deletion 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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion 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
Expand Down
2 changes: 2 additions & 0 deletions 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)
Expand Down
2 changes: 2 additions & 0 deletions 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
2 changes: 2 additions & 0 deletions 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"
Expand Down
3 changes: 2 additions & 1 deletion 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

4 changes: 3 additions & 1 deletion 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
Expand Down
24 changes: 24 additions & 0 deletions 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"
2 changes: 2 additions & 0 deletions 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/\///')
Expand Down
5 changes: 3 additions & 2 deletions 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"
Expand Down
2 changes: 2 additions & 0 deletions scripts/runAutoMaintenance.sh
@@ -1,4 +1,6 @@
#!/bin/bash

set -euo pipefail

yarn exportAllCourses
./scripts/updatePypiReadmeFiles.sh
2 changes: 2 additions & 0 deletions 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" "$@"
Expand Down
5 changes: 3 additions & 2 deletions 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"
Expand Down
35 changes: 23 additions & 12 deletions 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
4 changes: 3 additions & 1 deletion 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"
Expand Down
2 changes: 2 additions & 0 deletions scripts/verifyTestCourseJsonFiles.sh
@@ -1,5 +1,7 @@
#!/bin/bash

set -euo pipefail

yarn exportCourse test

if git diff --exit-code --name-only; then
Expand Down

0 comments on commit d98dab8

Please sign in to comment.