refactor(ci): Move translations to scripts/ folder

And refactor the script a little
This commit is contained in:
roschaefer 2020-02-12 13:38:13 +01:00 committed by Moriz Wahl
parent d9fcc9f720
commit 9011f922bb
3 changed files with 26 additions and 44 deletions

View File

@ -24,6 +24,8 @@ script:
- export CYPRESS_RETRIES=1 - export CYPRESS_RETRIES=1
- export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi) - 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" - echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, PR=$PR, BRANCH=$BRANCH"
# Miscellaneous
- ./scripts/sort-translations.sh
# Backend # Backend
- docker-compose exec backend yarn run lint - docker-compose exec backend yarn run lint
- docker-compose exec backend yarn run test --ci --verbose=false --coverage - docker-compose exec backend yarn run test --ci --verbose=false --coverage

24
scripts/sort-translations.sh Executable file
View File

@ -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

View File

@ -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