-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathlib.sh
78 lines (67 loc) · 2.04 KB
/
lib.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Copyright © Michal Čihař <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# shell library to help executing tests
# shellcheck shell=sh
if [ -z "$TERM" ]; then
export TERM=xterm-256color
fi
check() {
RET=$?
if [ $RET -ne 0 ]; then
exit $RET
fi
}
run_coverage() {
uv run --no-sources --all-extras coverage run --source . --append "$@"
}
get_mysql_args() {
# shellcheck disable=SC2153
args="--host=$CI_DB_HOST --user=root"
if [ -n "$CI_DB_PORT" ]; then
args="$args --port=$CI_DB_PORT"
fi
echo "$args"
}
cleanup_database() {
rm -f weblate.db
if [ "$CI_DATABASE" = "mysql" ] || [ "$CI_DATABASE" = 'mariadb' ]; then
if [ -n "$CI_DB_PASSWORD" ]; then
export MYSQL_PWD="$CI_DB_PASSWORD"
fi
# shellcheck disable=SC2046
mysql $(get_mysql_args) -e 'SET GLOBAL character_set_server=utf8mb4'
# shellcheck disable=SC2046
mysql $(get_mysql_args) -e 'SET GLOBAL collation_server=utf8mb4_general_ci'
# shellcheck disable=SC2046
mysql $(get_mysql_args) -e 'DROP DATABASE IF EXISTS weblate;'
# shellcheck disable=SC2046
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
export PGPASSWORD="$CI_DB_PASSWORD"
fi
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
psql --host="$CI_DB_HOST" -c 'CREATE DATABASE weblate;' -U postgres
# Replaces weblate/utils/migrations/0001_alter_role.py
psql --host="$CI_DB_HOST" -c 'ALTER ROLE postgres SET timezone = UTC;' -U postgres
fi
}
print_step() {
tput setaf 2
echo "$@"
tput sgr0
}
print_version() {
for cmd in "$@"; do
if command -v "$cmd"; then
$cmd --version
return
fi
done
echo "not found..."
}