Skip to content

Commit 39ed1e4

Browse files
committed
make runtests and runcoverage build and start the container if needed
1 parent ca69257 commit 39ed1e4

2 files changed

Lines changed: 131 additions & 8 deletions

File tree

tests/ci/matrix.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
VM_CMD='./vm.sh'
6+
LOGS_DIR='./var/logs/matrix'
7+
8+
# @todo use better config for this. If yq is present, we could eg. parse the github config
9+
OS_LIST=${OS_LIST:-focal jammy noble}
10+
# NB: as of 2025/06, the php install scripts fail for focal with php 5.6, 7.x except 7.4, and 8.x
11+
# Default php versions: focal 7.4.3, jammy 8.1.1, noble 8.3.6
12+
PHP_LIST_focal=${PHP_LIST_focal:-default 5.4}
13+
PHP_LIST_jammy=${PHP_LIST_jammy:-default 5.5 7.1 7.3 8.2 8.3}
14+
PHP_LIST_noble=${PHP_LIST_noble:-default 5.6 7.2 7.4 8.1 8.4}
15+
16+
STARTING_HTTPPORT="${STARTING_HTTPPORT:-81}"
17+
STARTING_HTTPSPORT="${STARTING_HTTPSPORT:-444}"
18+
STARTING_PROXYPORT="${STARTING_PROXYPORT:-8081}"
19+
20+
ACTION="${1}"
21+
22+
cd "$(dirname -- "$(readlink -f "$0")")"
23+
24+
help() {
25+
printf "Usage: matrix.sh [OPTIONS] ACTION [OPTARGS]
26+
27+
Builds and runs a Test Matrix (ie. using different OS/PHP versions)
28+
29+
Commands:
30+
build build or rebuild the containers and set up the test env
31+
runtests [\$suite] execute the test suite using the test containers (or a single test scenario eg. tests/1ParsingBugsTest.php)
32+
cleanup removes the docker containers and their images
33+
exec \$command
34+
inspect
35+
logs
36+
pause
37+
ps
38+
start
39+
stop
40+
top
41+
unpause
42+
43+
Options:
44+
-h print help
45+
46+
Environment variables:
47+
see output of 'vm.sh -h'
48+
"
49+
}
50+
51+
loop() {
52+
if [ ! -d "$LOGS_DIR" ]; then
53+
mkdir -p "$LOGS_DIR"
54+
fi
55+
export HOST_HTTPPORT="$STARTING_HTTPPORT"
56+
export HOST_HTTPSPORT="$STARTING_HTTPSPORT"
57+
export HOST_PROXYPORT="$STARTING_PROXYPORT"
58+
if [ "$1" = build ] || [ "$1" = start ] || [ "$1" = stop ] || [ "$1" = pause ] || [ "$1" = unpause ]; then
59+
PARALLEL=true
60+
fi
61+
for ubuntu_version in ${OS_LIST}
62+
do
63+
php_var="PHP_LIST_${ubuntu_version}"
64+
set +e
65+
for php_version in ${!php_var}
66+
do
67+
export UBUNTU_VERSION=$ubuntu_version
68+
export PHP_VERSION=$php_version
69+
case "${ACTION}" in
70+
build)
71+
$VM_CMD build 2>"${LOGS_DIR}/${ubuntu_version}_${php_version}.build.log" &
72+
;;
73+
start | stop | pause | unpause)
74+
### @todo force start process not to run composer
75+
$VM_CMD $1 &
76+
;;
77+
runtests | diff | inspect | kill | logs | port | ps | top)
78+
### @todo force runtests process to run composer; clean that up after testing
79+
$VM_CMD $1
80+
;;
81+
exec)
82+
$VM_CMD "$@"
83+
;;
84+
esac
85+
export HOST_HTTPPORT=$((HOST_HTTPPORT + 1))
86+
export HOST_HTTSPPORT=$((HOST_HTTPSPORT + 1))
87+
export HOST_PROXYPORT=$((HOST_PROXYPORT + 1))
88+
done
89+
set -e
90+
done
91+
if [ "$PARALLEL" = true ]; then
92+
wait
93+
fi
94+
}
95+
96+
case "${ACTION}" in
97+
98+
exec)
99+
shift
100+
loop exec "$@"
101+
;;
102+
103+
build | start | runtests | stop | cleanup | diff | inspect | kill | logs | pause | port | ps | top | unpause)
104+
loop "${ACTION}"
105+
;;
106+
107+
*)
108+
printf "\n\e[31mERROR:\e[0m unknown action '%s'\n\n" "${ACTION}" >&2
109+
help
110+
exit 1
111+
;;
112+
esac

tests/ci/vm.sh

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,24 @@ cd "$(dirname -- "$(readlink -f "$0")")"
3434
help() {
3535
printf "Usage: vm.sh [OPTIONS] ACTION [OPTARGS]
3636
37-
Manages the Test Environment Docker Stack
37+
Manages the Test Environment Docker Container
3838
3939
Commands:
40-
build build or rebuild the containers and set up the test env
41-
cleanup removes the docker containers and their images
42-
enter enter the test container
40+
build build or rebuild the container image with the test env
41+
cleanup remove the container and its image
42+
enter start a shell session in the container
43+
exec [\$command] runs a single command in the container
4344
inspect
4445
logs
46+
port
4547
ps
46-
runtests [\$suite] execute the test suite using the test container (or a single test scenario eg. tests/1ParsingBugsTest.php)
47-
runcoverage execute the test suite and generate a code coverage report (in build/coverage)
48-
start start the containers
49-
stop stop containers
48+
runtests [\$suite] execute the test suite using the test container (or a single test scenario eg. tests/1ParsingBugsTest.php);
49+
build and start the container if required
50+
runcoverage execute the test suite and generate a code coverage report (in build/coverage);
51+
build and start the container if required
52+
start start the container; build it if required
53+
stats
54+
stop stop the container
5055
top
5156
5257
Options:
@@ -196,6 +201,9 @@ case "${ACTION}" in
196201
;;
197202

198203
runcoverage)
204+
if [ "$(docker inspect --format '{{.State.Status}}' ${CONTAINER_NAME} 2>/dev/null)" != running ]; then
205+
start
206+
fi
199207
test -t 1 && USE_TTY="-t"
200208
# @todo clean up /tmp/phpxmlrpc and .phpunit.result.cache
201209
# @todo run composer install if it was not yet run or we are asked to
@@ -211,6 +219,9 @@ case "${ACTION}" in
211219
;;
212220

213221
runtests)
222+
if [ "$(docker inspect --format '{{.State.Status}}' ${CONTAINER_NAME} 2>/dev/null)" != running ]; then
223+
start
224+
fi
214225
test -t 1 && USE_TTY="-t"
215226
# @todo clean up /tmp/phpxmlrpc and .phpunit.result.cache
216227
# @todo run composer install if it was not yet run or we are asked to

0 commit comments

Comments
 (0)