Merge pull request #69 from mlocati/test-more-environments

Test more environments
pull/70/head
Michele Locati 2019-12-20 12:17:06 +01:00 committed by GitHub
commit ece68a1e81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 171 additions and 47 deletions

View File

@ -19,12 +19,32 @@ test-extensions-job-template: &test-extensions-job-template
jobs: jobs:
include: include:
- <<: *test-extensions-job-template - <<: *test-extensions-job-template
name: Test extensions on Alpine Linux name: Test extensions on Alpine 3.7
env: DOCKER_DISTRO=alpine env: DOCKER_DISTRO=alpine3.7
- <<: *test-extensions-job-template - <<: *test-extensions-job-template
name: Test extensions on Debian Linux name: Test extensions on Alpine 3.8
env: DOCKER_DISTRO=debian env: DOCKER_DISTRO=alpine3.8
- <<: *test-extensions-job-template
name: Test extensions on Alpine 3.9
env: DOCKER_DISTRO=alpine3.9
- <<: *test-extensions-job-template
name: Test extensions on Alpine 3.10
env: DOCKER_DISTRO=alpine3.10
- <<: *test-extensions-job-template
name: Test extensions on Debian 8 (jessie)
env: DOCKER_DISTRO=jessie
- <<: *test-extensions-job-template
name: Test extensions on Debian 9 (stretch)
env: DOCKER_DISTRO=stretch
- <<: *test-extensions-job-template
name: Test extensions on Debian 10 (buster)
env: DOCKER_DISTRO=buster
- stage: Update docs - stage: Update docs
name: Update README.md name: Update README.md

View File

@ -5,17 +5,12 @@ set -o errexit
set -o nounset set -o nounset
echo 'Checking environment' echo 'Checking environment'
if test -z "${TRAVIS_BUILD_DIR:-}"; then if test -z "${TRAVIS_BUILD_DIR:-}" || test -z "${TRAVIS_COMMIT_RANGE:-}" || test -z "${DOCKER_DISTRO:-}"; then
echo 'Not in a TravisCI environment' >&2 echo 'Not in a TravisCI environment' >&2
exit 1 exit 1
fi fi
if test -z "${TRAVIS_COMMIT_RANGE:-}"; then . "$TRAVIS_BUILD_DIR/scripts/common"
echo 'The TravisCI commit range is empty' >&2
exit 0
fi
. "${TRAVIS_BUILD_DIR}/scripts/common"
ALREADY_TESTED_EXTENSIONS='' ALREADY_TESTED_EXTENSIONS=''
@ -28,30 +23,135 @@ ALREADY_TESTED_EXTENSIONS=''
# Outputs: # Outputs:
# the full docker image ID # the full docker image ID
getDockerImageName () { getDockerImageName () {
case "${2}" in case "$2" in
*) *)
getDockerImageName_version="${2}" getDockerImageName_version="$2"
;; ;;
esac esac
getDockerImageName_suffix='-cli' getDockerImageName_suffix='-cli'
getDockerImageName_reqs="${TRAVIS_BUILD_DIR}/data/special-requirements" getDockerImageName_reqs="$TRAVIS_BUILD_DIR/data/special-requirements"
if test -f "${getDockerImageName_reqs}"; then if test -f "$getDockerImageName_reqs"; then
IFS=' ' IFS=' '
for getDockerImageName_testExtension in $1; do for getDockerImageName_testExtension in $1; do
if test -n "$(cat "${getDockerImageName_reqs}" | grep -E "^${getDockerImageName_testExtension}[ \t]+zts[ \t]*$")"; then if test -n "$(cat "$getDockerImageName_reqs" | grep -E "^$getDockerImageName_testExtension[ \t]+zts[ \t]*$")"; then
getDockerImageName_suffix="-zts" getDockerImageName_suffix="-zts"
fi fi
done done
fi fi
case "${DOCKER_DISTRO:-}" in
alpine)
getDockerImageName_distro="-$DOCKER_DISTRO" getDockerImageName_distro="-$DOCKER_DISTRO"
case "$DOCKER_DISTRO" in
alpine3.4)
# available for PHP from version 5.6 to version 7.1
case "$2" in
5.*|7.0|7.1)
;; ;;
*) *)
getDockerImageName_distro='' return
;; ;;
esac esac
printf 'php:%s%s%s' "${getDockerImageName_version}" "${getDockerImageName_suffix}" "${getDockerImageName_distro}" ;;
alpine3.6)
# available for PHP 7.2
case "$2" in
7.2)
;;
*)
return
;;
esac
;;
alpine3.7)
# available for PHP from version 5.6 to version 7.2
# default Alpine one for PHP 7.0
case "$2" in
7.0)
#getDockerImageName_distro='-alpine'
;;
5.*|7.1|7.2)
;;
*)
return
;;
esac
;;
alpine3.8)
# available for PHP from version 5.6 to version 7.3 (except PHP 7.0)
# default Alpine one for PHP 5.6
case "$2" in
5.6)
#getDockerImageName_distro='-alpine'
;;
5.*|7.1|7.2|7.3)
;;
*)
return
;;
esac
;;
alpine3.9)
# available for PHP from version 7.1 to version 7.3
case "$2" in
7.1|7.2|7.3)
;;
*)
return
;;
esac
;;
alpine3.10)
# available for PHP from version 7.1
# default Alpine one for PHP 7.1 -> 7.4
case "$2" in
7.1|7.2|7.3|7.4)
#getDockerImageName_distro='-alpine'
;;
5.*|7.0)
return
;;
esac
;;
jessie) # Debian 8
# available for PHP up to version 7.1
case "$2" in
5.*|7.0|7.1)
;;
*)
return
;;
esac
;;
stretch) # Debian 9
# available for PHP up to version 7.3
# default one for PHP 5.6 -> 7.0
case "$2" in
5.*|7.0)
#getDockerImageName_distro=''
;;
7.1|7.2|7.3)
;;
*)
return
;;
esac
;;
buster) # Debian 10
# available for PHP from version 7.1
# default one for PHP 7.1 -> 7.4
case "$2" in
7.1|7.2|7.3|7.4)
#getDockerImageName_distro=''
;;
5.*|7.0)
return
;;
esac
;;
*)
printf 'Unrecognized value of DOCKER_DISTRO environment variable (%s)\n' "$DOCKER_DISTRO" >&2
return 1
;;
esac
printf 'php:%s%s%s' "$getDockerImageName_version" "$getDockerImageName_suffix" "$getDockerImageName_distro"
} }
@ -65,22 +165,26 @@ getDockerImageName () {
# 0 (true): if test passes # 0 (true): if test passes
# 1 (false): if test fails # 1 (false): if test fails
testExtension () { testExtension () {
printf 'PHP version: %s\n' "${2}" printf 'PHP version: %s\n' "$2"
if test -n "$(printf '%s' "${2}" | sed -E 's/^[0-9]+\.[0-9]+$//')"; then if test -n "$(printf '%s' "$2" | sed -E 's/^[0-9]+\.[0-9]+$//')"; then
printf ' INVALID PHP VERSION: %s\n' "${2}" >&2 printf ' INVALID PHP VERSION: %s\n' "$2" >&2
return 1 return 1
fi fi
testExtension_Image="$(getDockerImageName "${1}" "${2}")" testExtension_Image="$(getDockerImageName "$1" "$2")"
printf ' - Docker image: %s\n' "${testExtension_Image}" if test -z "$testExtension_Image"; then
printf ' - Docker image not available\n'
return 0
fi
printf ' - Docker image: %s\n' "$testExtension_Image"
testExtension_out=`mktemp` 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}" rm -rf "$testExtension_out"
printf ' - Passed\n' printf ' - Passed\n'
return 0 return 0
fi fi
printf ' - FAILED!\n' >&2 printf ' - FAILED!\n' >&2
tail -n500 "${testExtension_out}" >&2 tail -n500 "$testExtension_out" >&2
rm -rf "${testExtension_out}" rm -rf "$testExtension_out"
return 1 return 1
} }
@ -100,23 +204,23 @@ testNewExtensionLine () {
printf 'Missing PHP version list for the new extension %s\n' "${1:-}" printf 'Missing PHP version list for the new extension %s\n' "${1:-}"
testNewExtensionLine_rc=1 testNewExtensionLine_rc=1
elif ! stringInList "$1" "$ALREADY_TESTED_EXTENSIONS"; then elif ! stringInList "$1" "$ALREADY_TESTED_EXTENSIONS"; then
printf '### TESTING NEW EXTENSION %s ###\n' "${1}" printf '### TESTING NEW EXTENSION %s ###\n' "$1"
if test -n "$(printf '%s' "${1}" | sed -E 's/^[a-z][a-z0-9\-\_\.]+$//')"; then if test -n "$(printf '%s' "$1" | sed -E 's/^[a-z][a-z0-9\-\_\.]+$//')"; then
printf ' INVALID PHP EXTENSION NAME: %s\n' "${1}" >&2 printf ' INVALID PHP EXTENSION NAME: %s\n' "$1" >&2
testNewExtensionLine_rc=1 testNewExtensionLine_rc=1
else else
ALREADY_TESTED_EXTENSIONS="$ALREADY_TESTED_EXTENSIONS $1" ALREADY_TESTED_EXTENSIONS="$ALREADY_TESTED_EXTENSIONS $1"
testNewExtensionLine_extension="${1}" testNewExtensionLine_extension="$1"
while test $# -ge 2; do while test $# -ge 2; do
shift shift
testNewExtensionLine_phpVersion="${1}" testNewExtensionLine_phpVersion="$1"
if ! testExtension "${testNewExtensionLine_extension}" "${1}"; then if ! testExtension "$testNewExtensionLine_extension" "$1"; then
testNewExtensionLine_rc=1 testNewExtensionLine_rc=1
fi fi
done done
fi fi
fi fi
return ${testNewExtensionLine_rc} return $testNewExtensionLine_rc
} }
@ -182,7 +286,7 @@ getAllPHPVersionsForExtension () {
fi fi
done done
done < "$TRAVIS_BUILD_DIR/data/supported-extensions" done < "$TRAVIS_BUILD_DIR/data/supported-extensions"
printf '%s' "${getAllPHPVersionsForExtension_result}" printf '%s' "$getAllPHPVersionsForExtension_result"
} }
@ -201,7 +305,7 @@ testExtensionsFromMessage () {
testExtensionsFromMessage_result=0 testExtensionsFromMessage_result=0
TEST_EXTENSIONS= TEST_EXTENSIONS=
FIRST_LINE=1 FIRST_LINE=1
testExtensionsFromMessage_message="$(git -C "${TRAVIS_BUILD_DIR}" log --pretty='format:%B' -n 1 "$1")" testExtensionsFromMessage_message="$(git -C "$TRAVIS_BUILD_DIR" log --pretty='format:%B' -n 1 "$1")"
IFS=' IFS='
' '
@ -260,16 +364,16 @@ ADDED_EXTENSION_LINE=
FOUND_ATAT= FOUND_ATAT=
IFS=' IFS='
' '
for DIFF_LINE in $(git -C "${TRAVIS_BUILD_DIR}" diff --no-indent-heuristic --minimal --no-color --word-diff=none -no-renames --unified=0 "${TRAVIS_COMMIT_RANGE:-}" -- data/supported-extensions); do for DIFF_LINE in $(git -C "$TRAVIS_BUILD_DIR" diff --no-indent-heuristic --minimal --no-color --word-diff=none -no-renames --unified=0 "$TRAVIS_COMMIT_RANGE" -- data/supported-extensions); do
if test -n "${DIFF_LINE}"; then if test -n "$DIFF_LINE"; then
if test -z "${FOUND_ATAT}"; then if test -z "$FOUND_ATAT"; then
if test -z "${DIFF_LINE##@@*}"; then if test -z "${DIFF_LINE##@@*}"; then
FOUND_ATAT=y FOUND_ATAT=y
fi fi
elif test -z "${DIFF_LINE##+*}"; then elif test -z "${DIFF_LINE##+*}"; then
resetIFS resetIFS
ADDED_EXTENSION_LINE="${DIFF_LINE##+}" ADDED_EXTENSION_LINE="${DIFF_LINE##+}"
if ! testNewExtensionLine ${ADDED_EXTENSION_LINE}; then if ! testNewExtensionLine $ADDED_EXTENSION_LINE; then
TESTS_RESULTS=1 TESTS_RESULTS=1
fi fi
fi fi
@ -279,7 +383,7 @@ done
IFS=' IFS='
' '
for COMMIT_HASH in $(git -C "${TRAVIS_BUILD_DIR}" log --pretty='format:%H' "${TRAVIS_COMMIT_RANGE:-}"); do for COMMIT_HASH in $(git -C "$TRAVIS_BUILD_DIR" log --pretty='format:%H' "$TRAVIS_COMMIT_RANGE"); do
if ! testExtensionsFromMessage "$COMMIT_HASH"; then if ! testExtensionsFromMessage "$COMMIT_HASH"; then
TESTS_RESULTS=1 TESTS_RESULTS=1
fi fi
@ -288,10 +392,10 @@ for COMMIT_HASH in $(git -C "${TRAVIS_BUILD_DIR}" log --pretty='format:%H' "${TR
fi fi
done done
if test ${TESTS_RESULTS} -ne 0; then if test $TESTS_RESULTS -ne 0; then
exit ${TESTS_RESULTS} exit $TESTS_RESULTS
fi fi
if test -z "${ADDED_EXTENSION_LINE}"; then if test -z "$ADDED_EXTENSION_LINE"; then
echo 'No new extensions detected.' echo 'No new extensions detected.'
fi fi