-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrun-tests.sh
executable file
·65 lines (48 loc) · 1.68 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
#!/bin/bash
set -e
DOCKERFILE_TEMPLATE="tests/Dockerfile.template"
PY_DOCKER_IMAGES=()
PY_DOCKER_IMAGES+=("2.7.16-slim")
PY_DOCKER_IMAGES+=("3.7.4-slim")
PY_DOCKER_IMAGES+=("3.8-slim")
PY_DOCKER_IMAGES+=("3.9-slim")
PY_DOCKER_IMAGES+=("3.10-slim")
PY_DOCKER_IMAGES+=("3.11-slim")
create_docker_file() {
local package="$1"
# Generate a valid Dockerfile from a template file
local dockerfile="tests/Dockerfile-$py_docker_image-$package"
cp "$DOCKERFILE_TEMPLATE" "$dockerfile"
# Replace docker image
sed -i '' "s/\$IMAGE/$py_docker_image/g" "$dockerfile"
# Replace package name
if [[ "$package" == "local" ]]; then
package="."
fi
sed -i '' "s/\$PACKAGE/$package/g" "$dockerfile"
echo "$dockerfile"
}
build_docker_image_and_run() {
local py_docker_image="$1"
local package="$2"
local dockerfile="$3"
# Build
local docker_image="editorconfig-checker-$py_docker_image-$package:latest"
docker build -t "$docker_image" -f "$dockerfile" --no-cache --quiet .
# Run `editorconfig-checker`
docker run --rm "$docker_image" ec -version
}
main() {
echo -e "Running tests...\n\n"
for py_docker_image in "${PY_DOCKER_IMAGES[@]}"; do
for package in local editorconfig-checker; do
local dockerfile=$(create_docker_file "$package")
echo "Dockerfile created at \"$dockerfile\" (\"$py_docker_image\" image and \"$package\" package)"
echo "Building docker image. It could take some time..."
build_docker_image_and_run "$py_docker_image" "$package" "$dockerfile"
# docker image rm "$docker_image" &> /dev/null
echo -e "\n"
done
done
}
main