diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c0101aa --- /dev/null +++ b/.editorconfig @@ -0,0 +1,34 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +spaces_around_operators = true + +[*.bat] +end_of_line = crlf + +[*.html] +indent_size = 2 + +[*.py] +indent_size = 4 + +[*.rst] +indent_size = 3 + +[*.js] +quote_type = double + +[*.{markdown,md}] +trim_trailing_whitespace = false + +[[shell]] +indent_style = space +indent_size = 4 +space_redirects = true +simplify = true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e10d54c..04145e9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,6 +41,10 @@ repos: hooks: - id: shellcheck require_serial: true +- repo: https://github.com/scop/pre-commit-shfmt + rev: v3.10.0-2 + hooks: + - id: shfmt ci: autoupdate_schedule: quarterly diff --git a/test-content b/test-content index e350e0f..569605a 100755 --- a/test-content +++ b/test-content @@ -1,7 +1,7 @@ #!/bin/sh STORAGE=$(mktemp) -cleanup(){ +cleanup() { rm "$STORAGE" } trap cleanup EXIT @@ -15,7 +15,7 @@ docker rm tmp_$$ echo "Checking content..." # /app/data is not checked because it contains stub for customization -if grep -E '^(app/cache|tmp|run)/.+' "$STORAGE" ; then +if grep -E '^(app/cache|tmp|run)/.+' "$STORAGE"; then echo "Volumes contain files!" exit 1 fi diff --git a/test-generate b/test-generate index 648dba7..2af9123 100755 --- a/test-generate +++ b/test-generate @@ -1,13 +1,13 @@ #!/bin/sh -if [ "$3" = "saml" ] ; then +if [ "$3" = "saml" ]; then TEST_EXTRA_ENV='WEBLATE_SAML_IDP_URL: https://example.com/idp' -elif [ "$3" = "celery-single" ] ; then +elif [ "$3" = "celery-single" ]; then TEST_EXTRA_ENV='CELERY_SINGLE_PROCESS: 1' else TEST_EXTRA_ENV='' fi -cat > docker-compose.override.yml < docker-compose.override.yml << EOT services: weblate: image: ${TEST_CONTAINER:-weblate/weblate:edge} @@ -22,10 +22,10 @@ services: - 4443:4443 EOT -if [ "$3" = "split" ] ; then - mv docker-compose-split.yml docker-compose.yml - for service in celery-backup celery-beat celery-celery celery-memory celery-notify celery-translate ; do - cat >> docker-compose.override.yml <> docker-compose.override.yml << EOT weblate-${service}: image: ${TEST_CONTAINER:-weblate/weblate:edge} restart: no @@ -33,11 +33,11 @@ if [ "$3" = "split" ] ; then WEBLATE_TIME_ZONE: Europe/Prague WEBLATE_SITE_DOMAIN: test.example.com EOT - done + done fi -if [ "$3" = "read-write" ] || [ "$3" = "localtime" ] ; then - sed -i -e '/tmpfs:/D' -e '/- \/run/D' -e '/- \/tmp/D' -e '/read_only: true/D' docker-compose.yml - if [ "$3" = "localtime" ] ; then +if [ "$3" = "read-write" ] || [ "$3" = "localtime" ]; then + sed -i -e '/tmpfs:/D' -e '/- \/run/D' -e '/- \/tmp/D' -e '/read_only: true/D' docker-compose.yml + if [ "$3" = "localtime" ]; then sed -i -e '/weblate-cache:\/app\/cache/a\ - /etc/localtime:/etc/localtime:ro' docker-compose.yml fi @@ -46,12 +46,11 @@ else sed -i 's/- \/tmp/- \/tmp:exec/' docker-compose.yml fi - IP=127.0.0.1 PORT=${1:-8080} PROTO=${2:-http} -cat > .test.env < .test.env << EOT URL=$PROTO://$IP:$PORT/ EOT diff --git a/test-online b/test-online index 085f174..8a1512c 100755 --- a/test-online +++ b/test-online @@ -3,10 +3,10 @@ . ./.test.env echo "Checking $URL..." TIMEOUT=0 -while ! curl --insecure --fail --max-time 5 --silent --output /dev/null "$URL" ; do +while ! curl --insecure --fail --max-time 5 --silent --output /dev/null "$URL"; do sleep 5 TIMEOUT=$((TIMEOUT + 1)) - if [ $TIMEOUT -gt 300 ] ; then + if [ $TIMEOUT -gt 300 ]; then break fi done @@ -17,6 +17,6 @@ RET2=$? # Display logs so far docker compose logs -if [ $RET2 -ne 0 ] || [ $RET -ne 0 ] ; then +if [ $RET2 -ne 0 ] || [ $RET -ne 0 ]; then exit 1 fi diff --git a/test-saml b/test-saml index f3c62ff..9bc8c30 100755 --- a/test-saml +++ b/test-saml @@ -1,6 +1,6 @@ #!/bin/sh -if [ "$1" = "saml" ] ; then - docker compose exec -T weblate openssl x509 -in /app/data/ssl/saml.crt -text -noout +if [ "$1" = "saml" ]; then + docker compose exec -T weblate openssl x509 -in /app/data/ssl/saml.crt -text -noout else - docker compose exec -T weblate test ! -f /app/data/ssl/saml.crt + docker compose exec -T weblate test ! -f /app/data/ssl/saml.crt fi diff --git a/test-supervisor b/test-supervisor index 08d4a34..a968a73 100755 --- a/test-supervisor +++ b/test-supervisor @@ -2,7 +2,7 @@ docker compose exec -T weblate supervisorctl status all RET=$? # The 3 happens with EXITED check and supervisor 4 -if [ $RET -ne 0 ] && [ $RET -ne 3 ] ; then +if [ $RET -ne 0 ] && [ $RET -ne 3 ]; then docker compose logs exit 1 fi