forked from gdcc/pyDataverse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-tests.sh
87 lines (73 loc) · 2.18 KB
/
run-tests.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
79
80
81
82
83
84
85
86
87
#!bin/bash
# Parse arguments
usage() {
echo "Usage: $0 [-p Python version (e.g. 3.10, 3.11, ...)]" 1>&2
exit 1
}
while getopts ":p:d:" o; do
case "${o}" in
p)
p=${OPTARG}
;;
*) ;;
esac
done
shift $((OPTIND - 1))
# Fall back to Python 3.11 if no Python version is specified
if [ -z "${p}" ]; then
printf "\n⚠️ No Python version specified falling back to '3.11'\n"
p=3.11
fi
# Validate Python version
if [[ ! "${p}" =~ ^3\.[0-9]+$ ]]; then
echo "\n❌ Invalid Python version. Please specify a valid Python version (e.g. 3.10, 3.11, ...)\n"
exit 1
fi
# Check if Docker is installed
if ! command -v docker &>/dev/null; then
echo "✋ Docker is not installed. Please install Docker before running this script."
exit 1
fi
# Prepare the environment for the test
mkdir dv >>/dev/null 2>&1
touch dv/bootstrap.exposed.env >>/dev/null 2>&1
# Add python version to the environment
export PYTHON_VERSION=${p}
printf "\n🚀 Preparing containers\n"
printf " Using PYTHON_VERSION=${p}\n\n"
# Run all containers
docker compose \
-f docker/docker-compose-base.yml \
-f ./docker/docker-compose-test-all.yml \
--env-file local-test.env \
up -d
printf "\n🔎 Running pyDataverse tests\n"
printf " Logs will be printed once finished...\n\n"
# Check if "unit-test" container has finished
while [ -n "$(docker ps -f "name=unit-tests" -f "status=running" -q)" ]; do
printf " Waiting for unit-tests container to finish...\n"
sleep 5
done
# Check if "unit-test" container has failed
if [ "$(docker inspect -f '{{.State.ExitCode}}' unit-tests)" -ne 0 ]; then
printf "\n❌ Unit tests failed. Printing logs...\n"
docker logs unit-tests
printf "\n Stopping containers\n"
docker compose \
-f docker/docker-compose-base.yml \
-f ./docker/docker-compose-test-all.yml \
--env-file local-test.env \
down
exit 1
fi
# Print test results
printf "\n"
cat dv/unit-tests.log
printf "\n\n✅ Unit tests passed\n\n"
# Stop all containers
docker compose \
-f docker/docker-compose-base.yml \
-f ./docker/docker-compose-test-all.yml \
--env-file local-test.env \
down
printf "\n🎉 Done\n\n"