From 9011f922bb4bfd4d68953dd7636c5011642b3ac2 Mon Sep 17 00:00:00 2001 From: roschaefer Date: Wed, 12 Feb 2020 13:38:13 +0100 Subject: [PATCH] refactor(ci): Move translations to scripts/ folder And refactor the script a little --- .travis.yml | 2 ++ scripts/sort-translations.sh | 24 ++++++++++++++++++++ webapp/check-json.sh | 44 ------------------------------------ 3 files changed, 26 insertions(+), 44 deletions(-) create mode 100755 scripts/sort-translations.sh delete mode 100755 webapp/check-json.sh diff --git a/.travis.yml b/.travis.yml index 621453bc7..f8c869972 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,8 @@ script: - export CYPRESS_RETRIES=1 - export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi) - echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, PR=$PR, BRANCH=$BRANCH" + # Miscellaneous + - ./scripts/sort-translations.sh # Backend - docker-compose exec backend yarn run lint - docker-compose exec backend yarn run test --ci --verbose=false --coverage diff --git a/scripts/sort-translations.sh b/scripts/sort-translations.sh new file mode 100755 index 000000000..5bb5e988e --- /dev/null +++ b/scripts/sort-translations.sh @@ -0,0 +1,24 @@ +#! /usr/bin/env bash + +ROOT_DIR=$(dirname "$0")/.. +tmp=$(mktemp) +exit_code=0 + +for locale_file in $ROOT_DIR/webapp/locales/*.json +do + jq --sort-keys . $locale_file > "$tmp" + if [ "$*" == "--fix" ] + then + mv "$tmp" $locale_file + else + if diff -q "$tmp" $locale_file > /dev/null ; + then + : # all good + else + exit_code=$? + echo "$locale_file is not sorted by keys" + fi + fi +done + +exit $exit_code diff --git a/webapp/check-json.sh b/webapp/check-json.sh deleted file mode 100755 index 2f39bbccb..000000000 --- a/webapp/check-json.sh +++ /dev/null @@ -1,44 +0,0 @@ -#! /usr/bin/env bash - -ERRORS=false -FIX=false - -for arg in "$@" -do - if [ "$arg" == "--fix" ] - then - FIX=true - fi -done - -# normalize the locale file. WS 2 blanks, keys are sorted -if $FIX ; then - for locale_file in locales/*.json - do - jq --sort-keys . $locale_file > locales/tmp.json - mv locales/tmp.json $locale_file - done - exit 0 -fi - -# check if keys are sorted alphabetically and WS is two blanks -for locale_file in locales/*.json -do - jq --sort-keys . $locale_file | diff -q $locale_file - > /dev/null && echo "$locale_file is OK" || - { ERRORS=true ; echo "$locale_file is not normalized" ; } -done - -# check if all the keys in en.json are present in de.json and vice versa - -# TO DO!! - - -# Exit with status 1 if there were errors - -if $ERRORS ; then - echo "Some locale files are not normalized." - exit 1 -else - echo "All locales are normalized." - exit 0 -fi