| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
topdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 4 |
|
| 5 |
function usage () { |
| 6 |
echo "Usage: " |
| 7 |
echo " run-ci.sh [OPTIONS] [TEST NAME [TEST NAME...]]" |
| 8 |
echo |
| 9 |
echo "Runs the CI tests locally using docker" |
| 10 |
echo |
| 11 |
echo "The test names are based on the names of tests in the CI yaml files" |
| 12 |
echo |
| 13 |
echo "If no test names are specified, all tests will be run" |
| 14 |
echo |
| 15 |
echo "Options:" |
| 16 |
echo |
| 17 |
echo " -h --help Display this help message and exit" |
| 18 |
echo " " |
| 19 |
exit 1; |
| 20 |
} |
| 21 |
|
| 22 |
arg_service=false |
| 23 |
|
| 24 |
while : ; do |
| 25 |
case "$1" in |
| 26 |
-h|--help) |
| 27 |
usage; |
| 28 |
shift ;; |
| 29 |
-s|--service) |
| 30 |
arg_service=true |
| 31 |
shift ;; |
| 32 |
*) |
| 33 |
break ;; |
| 34 |
esac |
| 35 |
done |
| 36 |
|
| 37 |
test_names="${@}" |
| 38 |
|
| 39 |
|
| 40 |
# We need to give ownership to the docker image user `testuser`, |
| 41 |
# chances are high that this will be the same UID as the primary |
| 42 |
# user on this host |
| 43 |
# |
| 44 |
user_uid="$(id -u)" |
| 45 |
user_gid="$(id -g)" |
| 46 |
if [ "${user_uid}" -ne "1000" ] || [ "${user_gid}" -ne "1000" ]; then |
| 47 |
sudo chown -R 1000:1000 "${topdir}/.." |
| 48 |
fi |
| 49 |
|
| 50 |
|
| 51 |
# runTest() |
| 52 |
# |
| 53 |
# $1 = test name |
| 54 |
# |
| 55 |
function runTest() { |
| 56 |
test_name=$1 |
| 57 |
|
| 58 |
# Run docker-compose from it's directory, because it will use |
| 59 |
# relative paths |
| 60 |
cd "${topdir}/compose" |
| 61 |
docker compose \ |
| 62 |
--env-file ${topdir}/common.env \ |
| 63 |
--file ${topdir}/compose/ci.docker-compose.yml \ |
| 64 |
run "${test_name}" |
| 65 |
return $? |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
if [ -z "${test_names}" ]; then |
| 70 |
for test_name in "mypy debian-12 debian-13 fedora-42 fedora-43 fedora-missing-deps ubuntu-22.04"; do |
| 71 |
if ! runTest "${test_name}"; then |
| 72 |
echo "Tests failed" |
| 73 |
exit 1 |
| 74 |
fi |
| 75 |
done |
| 76 |
else |
| 77 |
for test_name in "${test_names}"; do |
| 78 |
if ! runTest "${test_name}"; then |
| 79 |
echo "Tests failed" |
| 80 |
exit 1 |
| 81 |
fi |
| 82 |
done |
| 83 |
fi |