Skip to content

Commit

Permalink
chore: introduce shellfmt for formatting shell files
Browse files Browse the repository at this point in the history
This makes them look consistent and formatting is now enforced.
  • Loading branch information
nijel committed Oct 4, 2024
1 parent e2a35d8 commit 45b066d
Show file tree
Hide file tree
Showing 21 changed files with 160 additions and 169 deletions.
13 changes: 11 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ spaces_around_operators = true
[*.bat]
end_of_line = crlf

[*.{py,rst,sh}]
[*.py]
indent_size = 4

[*.{js}]
[*.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
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ repos:
- mdformat-ruff==0.1.3
- mdformat-shfmt==0.1.0
- mdformat_tables==1.0.0
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.9.0-1
hooks:
- id: shfmt
- repo: https://github.com/awebdeveloper/pre-commit-stylelint
rev: 0.0.2
hooks:
Expand Down
2 changes: 1 addition & 1 deletion ci/apt-install
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ apt-get install -y \
apt-get install -y libleptonica-dev libtesseract-dev

# Remove MySQL 8.x client, use older MariaDB one to ensure compatibility
if [ "$CI_DATABASE" = "mariadb" ] ; then
if [ "$CI_DATABASE" = "mariadb" ]; then
apt-get purge 'mysql-client.*'
apt-get install -y mariadb-client
fi
20 changes: 10 additions & 10 deletions ci/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

# shellcheck shell=sh

if [ -z "$TERM" ] ; then
if [ -z "$TERM" ]; then
export TERM=xterm-256color
fi

check() {
RET=$?
if [ $RET -ne 0 ] ; then
if [ $RET -ne 0 ]; then
exit $RET
fi
}
Expand All @@ -24,7 +24,7 @@ run_coverage() {
get_mysql_args() {
# shellcheck disable=SC2153
args="--host=$CI_DB_HOST --user=root"
if [ -n "$CI_DB_PORT" ] ; then
if [ -n "$CI_DB_PORT" ]; then
args="$args --port=$CI_DB_PORT"
fi
echo "$args"
Expand All @@ -33,8 +33,8 @@ get_mysql_args() {
cleanup_database() {
rm -f weblate.db

if [ "$CI_DATABASE" = "mysql" ] || [ "$CI_DATABASE" = 'mariadb' ] ; then
if [ -n "$CI_DB_PASSWORD" ] ; then
if [ "$CI_DATABASE" = "mysql" ] || [ "$CI_DATABASE" = 'mariadb' ]; then
if [ -n "$CI_DB_PASSWORD" ]; then
export MYSQL_PWD="$CI_DB_PASSWORD"
fi
# shellcheck disable=SC2046
Expand All @@ -47,11 +47,11 @@ cleanup_database() {
mysql $(get_mysql_args) -e 'CREATE DATABASE weblate CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;'
fi

if [ "$CI_DATABASE" = "postgresql" ] ; then
if [ -n "$CI_DB_PASSWORD" ] ; then
if [ "$CI_DATABASE" = "postgresql" ]; then
if [ -n "$CI_DB_PASSWORD" ]; then
export PGPASSWORD="$CI_DB_PASSWORD"
fi
if [ -n "$CI_DB_PORT" ] ; then
if [ -n "$CI_DB_PORT" ]; then
export PGPORT="$CI_DB_PORT"
fi
psql --host="$CI_DB_HOST" -c 'DROP DATABASE IF EXISTS weblate;' -U postgres
Expand All @@ -66,8 +66,8 @@ print_step() {
}

print_version() {
for cmd in "$@" ; do
if command -v "$cmd" ; then
for cmd in "$@"; do
if command -v "$cmd"; then
$cmd --version
return
fi
Expand Down
26 changes: 13 additions & 13 deletions ci/pip-install
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@

set -e -x

if [ "${1:-latest}" = migrations ] ; then
if [ "${1:-latest}" = migrations ]; then
uv pip install --system -e ".[all,mysql,ci]"
else
if [ "${1:-latest}" = minimal ] ; then
if [ "${1:-latest}" = minimal ]; then
# Adjust deps to force minimal version
sed -i '/^ *"/ s/>=/==/' pyproject.toml
fi

if [ "${1:-latest}" = mypy ] ; then
uv pip install --system -e ".[all,mysql,ci,mypy,test]"
if [ "${1:-latest}" = mypy ]; then
uv pip install --system -e ".[all,mysql,ci,mypy,test]"
else
# TODO: lxml can use wheels once xmlsec has one
# see https://github.com/xmlsec/python-xmlsec/issues/327
if python -c 'import sys; sys.exit(0 if sys.version_info >= (3,13) else 1)' ; then
uv pip install --system --no-binary=lxml -e ".[all,mysql,ci,test]"
else
uv pip install --system -e ".[all,mysql,ci,test]"
fi
# TODO: lxml can use wheels once xmlsec has one
# see https://github.com/xmlsec/python-xmlsec/issues/327
if python -c 'import sys; sys.exit(0 if sys.version_info >= (3,13) else 1)'; then
uv pip install --system --no-binary=lxml -e ".[all,mysql,ci,test]"
else
uv pip install --system -e ".[all,mysql,ci,test]"
fi
fi
if [ "${1:-latest}" = edge ] ; then
if [ "${1:-latest}" = edge ]; then
uv pip install --system --upgrade -e ".[all,mysql,test,ci]"
# Install from git / pre-release
uv pip install --system --no-deps --upgrade --force-reinstall \
Expand All @@ -37,6 +37,6 @@ else
fi

# Verify that deps are consistent
if [ "${1:-latest}" != edge ] ; then
if [ "${1:-latest}" != edge ]; then
uv pip check
fi
8 changes: 4 additions & 4 deletions ci/prepare-database
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ set -e

cleanup_database

if [ "$CI_DATABASE" = "mysql" ] || [ "$CI_DATABASE" = 'mariadb' ] ; then
if [ "$CI_DATABASE" = "mysql" ] || [ "$CI_DATABASE" = 'mariadb' ]; then
# shellcheck disable=SC2046
mysql $(get_mysql_args) -e 'SHOW VARIABLES LIKE "%version%";'
fi
if [ "$CI_DATABASE" = "postgresql" ] ; then
if [ -n "$CI_DB_PASSWORD" ] ; then
if [ "$CI_DATABASE" = "postgresql" ]; then
if [ -n "$CI_DB_PASSWORD" ]; then
export PGPASSWORD="$CI_DB_PASSWORD"
fi
if [ -n "$CI_DB_PORT" ] ; then
if [ -n "$CI_DB_PORT" ]; then
export PGPORT="$CI_DB_PORT"
fi
psql --host="$CI_DB_HOST" -c 'SELECT version();' -U postgres
Expand Down
4 changes: 2 additions & 2 deletions ci/run-checkmigrate
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ cleanup_database
run_coverage ./manage.py migrate
run_coverage ./manage.py makemigrations
check
if [ "$(git status -s -- '*/migrations/*' | wc -l)" -gt 0 ] ; then
if [ "$(git status -s -- '*/migrations/*' | wc -l)" -gt 0 ]; then
echo 'There are untracked migrations:'
git status -s --porcelain -- '*/migrations/*' | sed -n '/^??/ s/^?? \(.*\)/\1/p' | while read -r migration ; do
git status -s --porcelain -- '*/migrations/*' | sed -n '/^??/ s/^?? \(.*\)/\1/p' | while read -r migration; do
echo "$migration"
cat "$migration"
echo
Expand Down
4 changes: 1 addition & 3 deletions ci/run-docs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

set -e

if ! command -v dot &> /dev/null
then
if ! command -v dot &> /dev/null; then
echo "dot command could not be found, please install graphviz"
exit 1
fi


# Build documentation with warnings treated as errors
make -C docs "${1:-html}" SPHINXOPTS='-n -W -a --keep-going'
9 changes: 4 additions & 5 deletions ci/run-migrate
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

. ci/lib.sh

if [ -n "$1" ] ; then
if [ -n "$1" ]; then
TAG="weblate-$1"
else
echo "Missing version to migrate from!"
Expand All @@ -20,7 +20,7 @@ HEAD_COMMIT=$(git rev-parse HEAD)
print_step "Testing migration from $TAG on $CI_DATABASE..."
cleanup_database
check
if ! git fetch --depth 1 origin tag "$TAG" ; then
if ! git fetch --depth 1 origin tag "$TAG"; then
git remote add upstream https://github.com/WeblateOrg/weblate.git
git fetch --depth 1 upstream tag "$TAG"
fi
Expand All @@ -36,11 +36,11 @@ uv pip install -e ".[all,mysql]"
check
echo "DATABASES['default']['HOST'] = '$CI_DB_HOST'" >> weblate/settings_test.py
check
if [ -n "$CI_DB_PASSWORD" ] ; then
if [ -n "$CI_DB_PASSWORD" ]; then
echo "DATABASES['default']['PASSWORD'] = '$CI_DB_PASSWORD'" >> weblate/settings_test.py
check
fi
if [ -n "$CI_DB_PORT" ] ; then
if [ -n "$CI_DB_PORT" ]; then
echo "DATABASES['default']['PORT'] = '$CI_DB_PORT'" >> weblate/settings_test.py
check
fi
Expand Down Expand Up @@ -77,7 +77,6 @@ check
./manage.py shell -c 'from weblate.memory.models import Memory; from weblate.lang.models import Language; Memory.objects.create(source_language=Language.objects.get(code="en"), target_language=Language.objects.get(code="cs"), source="source"*1000, target="target"*1000, origin="origin"*1000)'
check


git reset --hard
check
git checkout "$HEAD_COMMIT"
Expand Down
2 changes: 1 addition & 1 deletion ci/services-down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

set -e

if [ ! -f services-down ] ; then
if [ ! -f services-down ]; then
cd ci
fi

Expand Down
2 changes: 1 addition & 1 deletion ci/services-up
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

set -e

if [ ! -f services-up ] ; then
if [ ! -f services-up ]; then
cd ci
fi

Expand Down
81 changes: 40 additions & 41 deletions rundev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export USER_ID
GROUP_ID=$(id -g)
export GROUP_ID


cd dev-docker/

build() {
Expand All @@ -37,45 +36,45 @@ build() {
}

case $1 in
stop)
docker compose down
;;
logs)
shift
docker compose logs "$@"
;;
test)
shift
docker compose exec -T -e WEBLATE_DATA_DIR=/tmp/test-data -e WEBLATE_CELERY_EAGER=1 -e WEBLATE_SITE_TITLE=Weblate -e WEBLATE_ADD_APPS=weblate.billing,weblate.legal -e WEBLATE_VCS_FILE_PROTOCOL=1 -e WEBLATE_VCS_API_DELAY=0 weblate weblate test --noinput "$@"
;;
check)
shift
docker compose exec -T weblate weblate check "$@"
;;
build)
build
;;
wait)
TIMEOUT=0
while ! docker compose ps | grep healthy ; do
echo "Waiting for the container startup..."
sleep 1
docker compose ps
TIMEOUT=$((TIMEOUT + 1))
if [ $TIMEOUT -gt 120 ] ; then
docker compose logs
exit 1
fi
done
;;
start|restart|"")
build
stop)
docker compose down
;;
logs)
shift
docker compose logs "$@"
;;
test)
shift
docker compose exec -T -e WEBLATE_DATA_DIR=/tmp/test-data -e WEBLATE_CELERY_EAGER=1 -e WEBLATE_SITE_TITLE=Weblate -e WEBLATE_ADD_APPS=weblate.billing,weblate.legal -e WEBLATE_VCS_FILE_PROTOCOL=1 -e WEBLATE_VCS_API_DELAY=0 weblate weblate test --noinput "$@"
;;
check)
shift
docker compose exec -T weblate weblate check "$@"
;;
build)
build
;;
wait)
TIMEOUT=0
while ! docker compose ps | grep healthy; do
echo "Waiting for the container startup..."
sleep 1
docker compose ps
TIMEOUT=$((TIMEOUT + 1))
if [ $TIMEOUT -gt 120 ]; then
docker compose logs
exit 1
fi
done
;;
start | restart | "")
build

# Start it up
docker compose up -d --force-recreate
echo -e "\n${GREEN}Running development version of Weblate on http://${WEBLATE_HOST}/${NC}\n"
;;
*)
docker compose "$@"
;;
# Start it up
docker compose up -d --force-recreate
echo -e "\n${GREEN}Running development version of Weblate on http://${WEBLATE_HOST}/${NC}\n"
;;
*)
docker compose "$@"
;;
esac
9 changes: 4 additions & 5 deletions scripts/create-release
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@

set -e

if [ "$1" = "--help" ] || [ "$1" = "-h" ] ; then
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "Usage: ./scripts/create-release [--tag]"
exit 1
fi

if ! git diff --exit-code --quiet ; then
if ! git diff --exit-code --quiet; then
echo "There are not committed changes!"
exit 1
fi

DO_TAG=0
if [ "$1" = "--tag" ] ; then
if [ "$1" = "--tag" ]; then
DO_TAG=1
shift
fi


# What are we going to build?
if [ "$DO_TAG" -eq 1 ] ; then
if [ "$DO_TAG" -eq 1 ]; then
./scripts/prepare-release

# Grab version
Expand Down
Loading

0 comments on commit 45b066d

Please sign in to comment.