From 2de4f3462dab367ec8e2a21affee401bdb9cd27b Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Wed, 18 Dec 2019 16:45:20 +0100 Subject: [PATCH] Add support for testing more than one PHP extension at once --- README.md | 14 ++++- scripts/check-installed-extension.php | 45 ++++++++------ scripts/travisci-test-extensions | 84 +++++++++++++++++++-------- 3 files changed, 99 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index d8addbd..6c85015 100644 --- a/README.md +++ b/README.md @@ -155,8 +155,8 @@ See [this pull request](https://github.com/mlocati/docker-php-extension-installe ### Changing the supported PHP versions for an already supported PHP extension? 1. change the `install-php-extensions` script -2. update the `data/supported-extensions` file, adding the new PHP version to the existing line corresponding to the updated extension - +2. update the `data/supported-extensions` file, adding the new PHP version to the existing line corresponding to the updated extension + See [this pull request](https://github.com/mlocati/docker-php-extension-installer/pull/62) for an example. ### Improving code for an already supported extension? @@ -172,6 +172,16 @@ Improve the GD and ZIP extensions Test: gd, zip ``` +Tests only check the installation of a single PHP extension at a time. +If you want to test installing more PHP extensions at the same time, use a commit message like this: + +``` +Improve the GD and ZIP extensions + +Test: gd+zip +``` + + If your pull request contains multiple commits, we'll check the "Test:" message of every commit. If you want to stop parsing next commits, add `-STOP-` in the "Test:" line, for example: diff --git a/scripts/check-installed-extension.php b/scripts/check-installed-extension.php index 6921181..9a78e24 100644 --- a/scripts/check-installed-extension.php +++ b/scripts/check-installed-extension.php @@ -1,24 +1,35 @@ 'Zend OPcache', - ); - $extensionLowerCase = strtolower($extension); - if (isset($nameMap[$extensionLowerCase])) { - $extension = $nameMap[$extensionLowerCase]; - } - if (!extension_loaded($extension)) { - fprintf(STDERR, sprintf("Extension not loaded: %s\n", $extension)); +$rc = 0; +$numTestedExtensions = 0; +$nameMap = array( + 'opcache' => 'Zend OPcache', +); +for ($index = 1, $count = isset($argv) ? count($argv) : 0; $index < $count; $index++) { + $numTestedExtensions++; + $rcThis = 1; + $extension = $argv[$index]; + if ($extension === '') { + fprintf(STDERR, "Missing extension handle.\n"); } else { - fprintf(STDOUT, sprintf("Extension correctly loaded: %s\n", $extension)); - $rc = 0; + $extensionLowerCase = strtolower($extension); + if (isset($nameMap[$extensionLowerCase])) { + $extension = $nameMap[$extensionLowerCase]; + } + if (!extension_loaded($extension)) { + fprintf(STDERR, sprintf("Extension not loaded: %s\n", $extension)); + } else { + fprintf(STDOUT, sprintf("Extension correctly loaded: %s\n", $extension)); + $rcThis = 0; + } } + if ($rcThis !== 0) { + $rc = $rcThis; + } +} +if ($numTestedExtensions === 0) { + fprintf(STDERR, "No extension handles specified.\n"); + $rc = 1; } exit($rc); diff --git a/scripts/travisci-test-extensions b/scripts/travisci-test-extensions index d02a764..a9aaf0f 100755 --- a/scripts/travisci-test-extensions +++ b/scripts/travisci-test-extensions @@ -22,7 +22,7 @@ ALREADY_TESTED_EXTENSIONS='' # Get the docker image ID for a PHP extension and a PHP version # # Arguments: -# $1: the extension name +# $1: space-separated list with the names of the PHP extensions # $2: the PHP version # # Outputs: @@ -36,9 +36,12 @@ getDockerImageName () { getDockerImageName_suffix='-cli' getDockerImageName_reqs="${TRAVIS_BUILD_DIR}/data/special-requirements" if test -f "${getDockerImageName_reqs}"; then - if test -n "$(cat "${getDockerImageName_reqs}" | grep -E "^${1}[ \t]+zts[ \t]*$")"; then - getDockerImageName_suffix="-zts" - fi + IFS=' ' + for getDockerImageName_testExtension in $1; do + if test -n "$(cat "${getDockerImageName_reqs}" | grep -E "^${getDockerImageName_testExtension}[ \t]+zts[ \t]*$")"; then + getDockerImageName_suffix="-zts" + fi + done fi case "${DOCKER_DISTRO:-}" in alpine) @@ -55,7 +58,7 @@ getDockerImageName () { # Test an extension # # Arguments: -# $1: the extension name +# $1: space-separated list with the names of the PHP extensions to be tested # $2: the PHP version # # Return: @@ -70,7 +73,7 @@ testExtension () { testExtension_Image="$(getDockerImageName "${1}" "${2}")" printf ' - Docker image: %s\n' "${testExtension_Image}" testExtension_out=`mktemp` - if $(docker run --rm --volume "${TRAVIS_BUILD_DIR}:/app" --workdir /app "${testExtension_Image}" sh -c "./install-php-extensions '${1}' && php ./scripts/check-installed-extension.php '${1}'" >"${testExtension_out}" 2>&1); then + if $(docker run --rm --volume "${TRAVIS_BUILD_DIR}:/app" --workdir /app "${testExtension_Image}" sh -c "./install-php-extensions ${1} && php ./scripts/check-installed-extension.php ${1}" >"${testExtension_out}" 2>&1); then rm -rf "${testExtension_out}" printf ' - Passed\n' return 0 @@ -117,39 +120,69 @@ testNewExtensionLine () { } -#Get the list of all supported PHP versions +# Get the list of all supported PHP versions # # Arguments: -# $1: the extension name +# $1: space-separated list with the names of the PHP extensions to be tested # # Outputs: # the space-separated list of supported PHP versions -getAllPHPVersionsFor () { - getAllPHPVersionsFor_result='' - while IFS= read -r getAllPHPVersionsFor_line; do - getAllPHPVersionsFor_ok= +getAllPHPVersionsForExtensions () { + getAllPHPVersionsForExtensions_result='' + IFS=' ' + for getAllPHPVersionsForExtensions_extension in $1; do + getAllPHPVersionsForExtensions_this="$(getAllPHPVersionsForExtension "$getAllPHPVersionsForExtensions_extension")" + if test -z "$getAllPHPVersionsForExtensions_this"; then + return + fi + if test -z "$getAllPHPVersionsForExtensions_result"; then + getAllPHPVersionsForExtensions_result="$getAllPHPVersionsForExtensions_this" + else + getAllPHPVersionsForExtensions_tmp='' + for getAllPHPVersionsForExtensions_php1 in $getAllPHPVersionsForExtensions_this; do + if stringInList "$getAllPHPVersionsForExtensions_php1" "$getAllPHPVersionsForExtensions_result"; then + getAllPHPVersionsForExtensions_tmp="$getAllPHPVersionsForExtensions_tmp $getAllPHPVersionsForExtensions_php1" + fi + done + getAllPHPVersionsForExtensions_result="${getAllPHPVersionsForExtensions_tmp# }" + fi + done + printf '%s' "$getAllPHPVersionsForExtensions_result" +} + +# Get the list of all supported PHP versions +# +# Arguments: +# $1: the names of a PHP extension to be tested +# +# Outputs: +# the space-separated list of supported PHP versions +getAllPHPVersionsForExtension () { + getAllPHPVersionsForExtension_result='' + while IFS= read -r getAllPHPVersionsForExtension_line; do + getAllPHPVersionsForExtension_ok= IFS=' ' - for getAllPHPVersionsFor_chunk in $getAllPHPVersionsFor_line; do - if test -z "$getAllPHPVersionsFor_ok"; then - if test "$getAllPHPVersionsFor_chunk" = "$1"; then - getAllPHPVersionsFor_ok=y + for getAllPHPVersionsForExtension_chunk in $getAllPHPVersionsForExtension_line; do + if test -z "$getAllPHPVersionsForExtension_ok"; then + if test "$getAllPHPVersionsForExtension_chunk" = "$1"; then + getAllPHPVersionsForExtension_ok=y else - getAllPHPVersionsFor_ok=n + getAllPHPVersionsForExtension_ok=n fi else - if test $getAllPHPVersionsFor_ok = 'y'; then - if test -z "$getAllPHPVersionsFor_result"; then - getAllPHPVersionsFor_result="$getAllPHPVersionsFor_chunk" + if test $getAllPHPVersionsForExtension_ok = 'y'; then + if test -z "$getAllPHPVersionsForExtension_result"; then + getAllPHPVersionsForExtension_result="$getAllPHPVersionsForExtension_chunk" else - if ! stringInList "$getAllPHPVersionsFor_chunk" "$getAllPHPVersionsFor_result"; then - getAllPHPVersionsFor_result="$getAllPHPVersionsFor_result $getAllPHPVersionsFor_chunk" + if ! stringInList "$getAllPHPVersionsForExtension_chunk" "$getAllPHPVersionsForExtension_result"; then + getAllPHPVersionsForExtension_result="$getAllPHPVersionsForExtension_result $getAllPHPVersionsForExtension_chunk" fi fi fi fi done done < "$TRAVIS_BUILD_DIR/data/supported-extensions" - printf '%s' "${getAllPHPVersionsFor_result}" + printf '%s' "${getAllPHPVersionsForExtension_result}" } @@ -207,8 +240,9 @@ testExtensionsFromMessage () { for TEST_EXTENSION in $TEST_EXTENSIONS; do if ! stringInList "$TEST_EXTENSION" "$ALREADY_TESTED_EXTENSIONS"; then ALREADY_TESTED_EXTENSIONS="$ALREADY_TESTED_EXTENSIONS $TEST_EXTENSION" - printf '### TESTING EXTENSION %s ###\n' "$TEST_EXTENSION" - for TEST_PHPVERSION in $(getAllPHPVersionsFor $TEST_EXTENSION); do + TEST_EXTENSION="$(printf '%s' "$TEST_EXTENSION" | sed 's/\+/ /g')" + printf '### TESTING EXTENSION(S) %s ###\n' "$TEST_EXTENSION" + for TEST_PHPVERSION in $(getAllPHPVersionsForExtensions "$TEST_EXTENSION"); do if ! testExtension "$TEST_EXTENSION" "$TEST_PHPVERSION"; then testExtensionsFromMessage_result=1 fi