2018-04-12 09:41:16 +00:00
#!/bin/sh
# Let's set a sane environment
set -o errexit
set -o nounset
echo 'Checking environment'
2019-12-20 10:51:20 +00:00
if test -z "${TRAVIS_BUILD_DIR:-}" || test -z "${TRAVIS_COMMIT_RANGE:-}" || test -z "${DOCKER_DISTRO:-}"; then
2018-04-12 09:41:16 +00:00
echo 'Not in a TravisCI environment' >&2
exit 1
fi
2019-12-20 10:51:20 +00:00
. "$TRAVIS_BUILD_DIR/scripts/common"
2018-04-12 09:41:16 +00:00
2019-12-17 08:48:49 +00:00
ALREADY_TESTED_EXTENSIONS=''
2018-04-12 09:41:16 +00:00
# Get the docker image ID for a PHP extension and a PHP version
#
# Arguments:
2019-12-18 15:45:20 +00:00
# $1: space-separated list with the names of the PHP extensions
2018-04-12 09:41:16 +00:00
# $2: the PHP version
#
# Outputs:
# the full docker image ID
2019-12-20 15:52:00 +00:00
getDockerImageName() {
2019-12-20 10:51:20 +00:00
case "$2" in
2019-12-06 16:12:05 +00:00
*)
2019-12-20 10:51:20 +00:00
getDockerImageName_version="$2"
2019-12-06 16:12:05 +00:00
;;
esac
2019-12-23 10:51:19 +00:00
getDockerImageName_suffix='cli'
2019-12-20 10:51:20 +00:00
getDockerImageName_reqs="$TRAVIS_BUILD_DIR/data/special-requirements"
if test -f "$getDockerImageName_reqs"; then
2019-12-18 15:45:20 +00:00
IFS=' '
for getDockerImageName_testExtension in $1; do
2019-12-20 10:51:20 +00:00
if test -n "$(cat "$getDockerImageName_reqs" | grep -E "^$getDockerImageName_testExtension[ \t]+zts[ \t]*$")"; then
2019-12-23 10:51:19 +00:00
getDockerImageName_suffix='zts'
2019-12-18 15:45:20 +00:00
fi
done
2018-04-12 09:41:16 +00:00
fi
2019-12-23 10:51:19 +00:00
getDockerImageName_imageName="$(printf 'php:%s-%s-%s' "$getDockerImageName_version" "$getDockerImageName_suffix" "$DOCKER_DISTRO")"
2020-01-31 10:09:13 +00:00
case "$getDockerImageName_imageName" in
php:5.5-cli-jessie)
getDockerImageName_imageName='php:5.5-cli'
;;
php:5.5-zts-jessie)
getDockerImageName_imageName='php:5.5-zts'
;;
esac
2019-12-23 10:51:19 +00:00
if test -z "$(docker images -q "$getDockerImageName_imageName" 2>/dev/null)"; then
getDockerImageName_log="$(docker pull "$getDockerImageName_imageName" 2>&1 || true)"
if test -z "$(docker images -q "$getDockerImageName_imageName" 2>/dev/null)"; then
if test "${getDockerImageName_log#*manifest unknown}" != "$getDockerImageName_log" || test "${getDockerImageName_log#*manifest for * not found}" != "$getDockerImageName_log"; then
true
return
fi
printf '%s\n' "$getDockerImageName_log" >&2
exit 1
fi
fi
printf '%s' "$getDockerImageName_imageName"
2018-04-12 09:41:16 +00:00
}
# Test an extension
#
# Arguments:
2019-12-18 15:45:20 +00:00
# $1: space-separated list with the names of the PHP extensions to be tested
2018-04-12 09:41:16 +00:00
# $2: the PHP version
#
# Return:
# 0 (true): if test passes
# 1 (false): if test fails
2019-12-20 15:52:00 +00:00
testExtension() {
2019-12-20 10:51:20 +00:00
printf 'PHP version: %s\n' "$2"
if test -n "$(printf '%s' "$2" | sed -E 's/^[0-9]+\.[0-9]+$//')"; then
printf ' INVALID PHP VERSION: %s\n' "$2" >&2
2018-12-11 13:33:31 +00:00
return 1
2018-04-12 09:41:16 +00:00
fi
2019-12-20 10:51:20 +00:00
testExtension_Image="$(getDockerImageName "$1" "$2")"
2019-12-23 10:51:19 +00:00
if test $? -ne 0; then
exit 1
fi
2019-12-20 10:51:20 +00:00
if test -z "$testExtension_Image"; then
printf ' - Docker image not available\n'
return 0
fi
printf ' - Docker image: %s\n' "$testExtension_Image"
2019-12-20 15:52:00 +00:00
testExtension_out="$(mktemp)"
2019-12-20 10:51:20 +00:00
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"
2018-12-11 13:33:31 +00:00
printf ' - Passed\n'
return 0
fi
printf ' - FAILED!\n' >&2
2019-12-20 10:51:20 +00:00
tail -n500 "$testExtension_out" >&2
rm -rf "$testExtension_out"
2018-12-11 13:33:31 +00:00
return 1
2018-04-12 09:41:16 +00:00
}
# Test a new extension line
#
# Arguments:
# $1: the extension name
# $@: the list of PHP versions
#
# Return:
# 0 (true): if test passes
# 1 (false): if test fails
2019-12-20 15:52:00 +00:00
testNewExtensionLine() {
2018-04-12 09:41:16 +00:00
testNewExtensionLine_rc=0
2018-12-11 13:21:07 +00:00
if test $# -lt 2; then
2018-04-12 09:41:16 +00:00
printf 'Missing PHP version list for the new extension %s\n' "${1:-}"
testNewExtensionLine_rc=1
2019-12-17 08:48:49 +00:00
elif ! stringInList "$1" "$ALREADY_TESTED_EXTENSIONS"; then
2019-12-20 10:51:20 +00:00
printf '### TESTING NEW EXTENSION %s ###\n' "$1"
if test -n "$(printf '%s' "$1" | sed -E 's/^[a-z][a-z0-9\-\_\.]+$//')"; then
printf ' INVALID PHP EXTENSION NAME: %s\n' "$1" >&2
2018-04-12 09:41:16 +00:00
testNewExtensionLine_rc=1
else
2019-12-17 08:48:49 +00:00
ALREADY_TESTED_EXTENSIONS="$ALREADY_TESTED_EXTENSIONS $1"
2019-12-20 10:51:20 +00:00
testNewExtensionLine_extension="$1"
2018-12-11 13:21:07 +00:00
while test $# -ge 2; do
2018-04-12 09:41:16 +00:00
shift
2019-12-20 10:51:20 +00:00
testNewExtensionLine_phpVersion="$1"
if ! testExtension "$testNewExtensionLine_extension" "$1"; then
2018-04-12 09:41:16 +00:00
testNewExtensionLine_rc=1
fi
done
fi
fi
2019-12-20 10:51:20 +00:00
return $testNewExtensionLine_rc
2018-04-12 09:41:16 +00:00
}
2019-12-18 15:45:20 +00:00
# Get the list of all supported PHP versions
2019-08-12 19:56:24 +00:00
#
# Arguments:
2019-12-18 15:45:20 +00:00
# $1: space-separated list with the names of the PHP extensions to be tested
#
# Outputs:
# the space-separated list of supported PHP versions
2019-12-20 15:52:00 +00:00
getAllPHPVersionsForExtensions() {
2019-12-18 15:45:20 +00:00
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
2019-08-12 19:56:24 +00:00
#
# Outputs:
# the space-separated list of supported PHP versions
2019-12-20 15:52:00 +00:00
getAllPHPVersionsForExtension() {
2019-12-18 15:45:20 +00:00
getAllPHPVersionsForExtension_result=''
while IFS= read -r getAllPHPVersionsForExtension_line; do
getAllPHPVersionsForExtension_ok=
2019-08-12 19:56:24 +00:00
IFS=' '
2019-12-18 15:45:20 +00:00
for getAllPHPVersionsForExtension_chunk in $getAllPHPVersionsForExtension_line; do
if test -z "$getAllPHPVersionsForExtension_ok"; then
if test "$getAllPHPVersionsForExtension_chunk" = "$1"; then
getAllPHPVersionsForExtension_ok=y
2019-08-12 19:56:24 +00:00
else
2019-12-18 15:45:20 +00:00
getAllPHPVersionsForExtension_ok=n
2019-08-12 19:56:24 +00:00
fi
else
2019-12-18 15:45:20 +00:00
if test $getAllPHPVersionsForExtension_ok = 'y'; then
if test -z "$getAllPHPVersionsForExtension_result"; then
getAllPHPVersionsForExtension_result="$getAllPHPVersionsForExtension_chunk"
2019-08-12 19:56:24 +00:00
else
2019-12-18 15:45:20 +00:00
if ! stringInList "$getAllPHPVersionsForExtension_chunk" "$getAllPHPVersionsForExtension_result"; then
getAllPHPVersionsForExtension_result="$getAllPHPVersionsForExtension_result $getAllPHPVersionsForExtension_chunk"
2019-08-12 19:56:24 +00:00
fi
fi
fi
fi
done
2019-12-20 15:52:00 +00:00
done <"$TRAVIS_BUILD_DIR/data/supported-extensions"
2019-12-20 10:51:20 +00:00
printf '%s' "$getAllPHPVersionsForExtension_result"
2019-08-12 19:56:24 +00:00
}
# Test extensions by reading a commit message
#
# Arguments:
# $1: the commit hash
#
2019-12-11 11:57:53 +00:00
# Set:
# STOP_NEXT_COMMITS to 1 if we should skip next commits
#
2019-08-12 19:56:24 +00:00
# Return:
# 0 (true): if test passes
# 1 (false): if test fails
2019-12-20 15:52:00 +00:00
testExtensionsFromMessage() {
2019-08-12 19:56:24 +00:00
testExtensionsFromMessage_result=0
TEST_EXTENSIONS=
FIRST_LINE=1
2019-12-20 10:51:20 +00:00
testExtensionsFromMessage_message="$(git -C "$TRAVIS_BUILD_DIR" log --pretty='format:%B' -n 1 "$1")"
2019-08-12 19:56:24 +00:00
IFS='
'
for COMMIT_LINE in $testExtensionsFromMessage_message; do
if test $FIRST_LINE -eq 1; then
FIRST_LINE=0
else
TESTLIST=
case "$COMMIT_LINE" in
2019-12-20 15:52:00 +00:00
Test:*)
2019-08-12 19:56:24 +00:00
TESTLIST=${COMMIT_LINE#Test:}
;;
2019-12-20 15:52:00 +00:00
TEST:*)
2019-08-12 19:56:24 +00:00
TESTLIST=${COMMIT_LINE#TEST:}
;;
2019-12-20 15:52:00 +00:00
test:*)
2019-08-12 19:56:24 +00:00
TESTLIST=${COMMIT_LINE#test:}
;;
esac
if test -n "$TESTLIST"; then
IFS=' ,;'
for COMMIT_LINE_EXT in $TESTLIST; do
2019-12-11 11:57:53 +00:00
if test $COMMIT_LINE_EXT = '-STOP-'; then
STOP_NEXT_COMMITS=1
elif test -z "$TEST_EXTENSIONS"; then
2019-12-20 15:52:00 +00:00
TEST_EXTENSIONS=$COMMIT_LINE_EXT
2019-08-12 19:56:24 +00:00
else
if ! stringInList "$COMMIT_LINE_EXT" "$TEST_EXTENSIONS"; then
TEST_EXTENSIONS="$TEST_EXTENSIONS $COMMIT_LINE_EXT"
fi
fi
done
fi
fi
IFS=' '
for TEST_EXTENSION in $TEST_EXTENSIONS; do
2019-12-17 08:48:49 +00:00
if ! stringInList "$TEST_EXTENSION" "$ALREADY_TESTED_EXTENSIONS"; then
ALREADY_TESTED_EXTENSIONS="$ALREADY_TESTED_EXTENSIONS $TEST_EXTENSION"
2019-12-18 15:45:20 +00:00
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
2019-12-17 08:48:49 +00:00
if ! testExtension "$TEST_EXTENSION" "$TEST_PHPVERSION"; then
testExtensionsFromMessage_result=1
fi
done
fi
2019-08-12 19:56:24 +00:00
done
done
resetIFS
return $testExtensionsFromMessage_result
}
2019-12-11 11:57:53 +00:00
STOP_NEXT_COMMITS=0
2018-04-12 09:41:16 +00:00
TESTS_RESULTS=0
ADDED_EXTENSION_LINE=
FOUND_ATAT=
2018-12-11 13:07:04 +00:00
IFS='
2018-04-12 09:41:16 +00:00
'
2019-12-20 10:51:20 +00:00
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 -z "$FOUND_ATAT"; then
2018-12-11 13:21:07 +00:00
if test -z "${DIFF_LINE##@@*}"; then
2018-04-12 09:41:16 +00:00
FOUND_ATAT=y
fi
2018-12-11 13:21:07 +00:00
elif test -z "${DIFF_LINE##+*}"; then
2018-04-12 09:41:16 +00:00
resetIFS
ADDED_EXTENSION_LINE="${DIFF_LINE##+}"
2019-12-20 10:51:20 +00:00
if ! testNewExtensionLine $ADDED_EXTENSION_LINE; then
2018-04-12 09:41:16 +00:00
TESTS_RESULTS=1
fi
fi
fi
done
2019-08-12 19:56:24 +00:00
IFS='
'
2019-12-20 10:51:20 +00:00
for COMMIT_HASH in $(git -C "$TRAVIS_BUILD_DIR" log --pretty='format:%H' "$TRAVIS_COMMIT_RANGE"); do
2019-08-12 19:56:24 +00:00
if ! testExtensionsFromMessage "$COMMIT_HASH"; then
TESTS_RESULTS=1
fi
2019-12-11 11:57:53 +00:00
if test $STOP_NEXT_COMMITS -eq 1; then
break
fi
2019-08-12 19:56:24 +00:00
done
2019-12-20 10:51:20 +00:00
if test $TESTS_RESULTS -ne 0; then
exit $TESTS_RESULTS
2018-04-12 09:41:16 +00:00
fi
2019-12-20 10:51:20 +00:00
if test -z "$ADDED_EXTENSION_LINE"; then
2018-04-12 09:41:16 +00:00
echo 'No new extensions detected.'
fi