|
| 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 |
0 commit comments