docker-php-extension-installer/scripts/travisci-test-new-extensions

243 lines
6.0 KiB
Plaintext
Raw Normal View History

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'
2018-12-11 13:21:07 +00:00
if test -z "${TRAVIS_BUILD_DIR:-}"; then
2018-04-12 09:41:16 +00:00
echo 'Not in a TravisCI environment' >&2
exit 1
fi
2018-12-11 13:21:07 +00:00
if test -z "${TRAVIS_COMMIT_RANGE:-}"; then
2018-04-12 09:41:16 +00:00
echo 'The TravisCI commit range is empty' >&2
exit 0
fi
. "${TRAVIS_BUILD_DIR}/scripts/common"
# Get the docker image ID for a PHP extension and a PHP version
#
# Arguments:
# $1: the extension name
# $2: the PHP version
#
# Outputs:
# the full docker image ID
getExtensionImage () {
case "${2}" in
*)
getExtensionImage_version="${2}"
;;
esac
2019-10-10 15:52:10 +00:00
getExtensionImage_result="php:${getExtensionImage_version}-cli"
2018-04-12 09:41:16 +00:00
getExtensionImage_reqs="${TRAVIS_BUILD_DIR}/data/special-requirements"
2018-12-11 13:21:07 +00:00
if test -f "${getExtensionImage_reqs}"; then
if test -n "$(cat "${getExtensionImage_reqs}" | grep -E "^${1}[ \t]+zts[ \t]*$")"; then
2019-10-10 15:52:10 +00:00
getExtensionImage_result="php:${getExtensionImage_version}-zts"
2018-04-12 09:41:16 +00:00
fi
fi
printf '%s' "${getExtensionImage_result}"
}
# Test an extension
#
# Arguments:
# $1: the extension name
# $2: the PHP version
#
# Return:
# 0 (true): if test passes
# 1 (false): if test fails
testExtension () {
printf 'PHP version: %s\n' "${2}"
2018-12-11 13:21:07 +00:00
if test -n "$(printf '%s' "${2}" | sed -E 's/^[0-9]+\.[0-9]+$//')"; then
2018-04-12 09:41:16 +00:00
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
testExtension_Image="$(getExtensionImage "${1}" "${2}")"
printf ' - Docker image: %s\n' "${testExtension_Image}"
2018-12-11 13:33:31 +00:00
testExtension_out=`mktemp`
if $(docker run --rm --volume "${TRAVIS_BUILD_DIR}:/app" --workdir /app "${testExtension_Image}" bash -c "./install-php-extensions '${1}' && php ./scripts/check-installed-extension.php '${1}'" >"${testExtension_out}" 2>&1); then
2018-12-11 13:33:31 +00:00
rm -rf "${testExtension_out}"
printf ' - Passed\n'
return 0
fi
printf ' - FAILED!\n' >&2
cat "${testExtension_out}" >&2
rm -rf "${testExtension_out}"
return 1
2018-04-12 09:41:16 +00:00
}
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
testNewExtensionLine () {
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
else
printf '### TESTING NEW EXTENSION %s ###\n' "${1}"
2018-12-11 13:21:07 +00:00
if test -n "$(printf '%s' "${1}" | sed -E 's/^[a-z][a-z0-9\-\_\.]+$//')"; then
2018-04-12 09:41:16 +00:00
printf ' INVALID PHP EXTENSION NAME: %s\n' "${1}" >&2
testNewExtensionLine_rc=1
else
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
testNewExtensionLine_phpVersion="${1}"
2018-12-11 13:21:07 +00:00
if ! testExtension "${testNewExtensionLine_extension}" "${1}"; then
2018-04-12 09:41:16 +00:00
testNewExtensionLine_rc=1
fi
done
fi
fi
return ${testNewExtensionLine_rc}
}
#Get the list of all supported PHP versions
#
# Arguments:
# $1: the extension name
#
# Outputs:
# the space-separated list of supported PHP versions
getAllPHPVersionsFor () {
getAllPHPVersionsFor_result=''
while IFS= read -r getAllPHPVersionsFor_line; do
getAllPHPVersionsFor_ok=
IFS=' '
for getAllPHPVersionsFor_chunk in $getAllPHPVersionsFor_line; do
if test -z "$getAllPHPVersionsFor_ok"; then
if test "$getAllPHPVersionsFor_chunk" = "$1"; then
getAllPHPVersionsFor_ok=y
else
getAllPHPVersionsFor_ok=n
fi
else
if test $getAllPHPVersionsFor_ok = 'y'; then
if test -z "$getAllPHPVersionsFor_result"; then
getAllPHPVersionsFor_result="$getAllPHPVersionsFor_chunk"
else
if ! stringInList "$getAllPHPVersionsFor_chunk" "$getAllPHPVersionsFor_result"; then
getAllPHPVersionsFor_result="$getAllPHPVersionsFor_result $getAllPHPVersionsFor_chunk"
fi
fi
fi
fi
done
done < "$TRAVIS_BUILD_DIR/data/supported-extensions"
printf '%s' "${getAllPHPVersionsFor_result}"
}
# Test extensions by reading a commit message
#
# Arguments:
# $1: the commit hash
#
# Return:
# 0 (true): if test passes
# 1 (false): if test fails
testExtensionsFromMessage () {
testExtensionsFromMessage_result=0
TEST_EXTENSIONS=
FIRST_LINE=1
testExtensionsFromMessage_message="$(git -C "${TRAVIS_BUILD_DIR}" log --pretty='format:%B' -n 1 "$1")"
IFS='
'
for COMMIT_LINE in $testExtensionsFromMessage_message; do
if test $FIRST_LINE -eq 1; then
FIRST_LINE=0
else
TESTLIST=
case "$COMMIT_LINE" in
Test:* )
TESTLIST=${COMMIT_LINE#Test:}
;;
TEST:* )
TESTLIST=${COMMIT_LINE#TEST:}
;;
test:* )
TESTLIST=${COMMIT_LINE#test:}
;;
esac
if test -n "$TESTLIST"; then
IFS=' ,;'
for COMMIT_LINE_EXT in $TESTLIST; do
if test -z "$TEST_EXTENSIONS"; then
TEST_EXTENSIONS=$COMMIT_LINE_EXT;
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
printf '### TESTING EXTENSION %s ###\n' "$TEST_EXTENSION"
for TEST_PHPVERSION in $(getAllPHPVersionsFor $TEST_EXTENSION); do
if ! testExtension "$TEST_EXTENSION" "$TEST_PHPVERSION"; then
testExtensionsFromMessage_result=1
fi
done
done
done
resetIFS
return $testExtensionsFromMessage_result
}
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
'
2018-12-11 13:21:07 +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
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##+}"
2018-12-11 13:21:07 +00:00
if ! testNewExtensionLine ${ADDED_EXTENSION_LINE}; then
2018-04-12 09:41:16 +00:00
TESTS_RESULTS=1
fi
fi
fi
done
IFS='
'
for COMMIT_HASH in $(git -C "${TRAVIS_BUILD_DIR}" log --pretty='format:%H' "${TRAVIS_COMMIT_RANGE:-}"); do
if ! testExtensionsFromMessage "$COMMIT_HASH"; then
TESTS_RESULTS=1
fi
done
2018-12-11 13:21:07 +00:00
if test ${TESTS_RESULTS} -ne 0; then
2018-04-12 09:41:16 +00:00
exit ${TESTS_RESULTS}
fi
2018-12-11 13:21:07 +00:00
if test -z "${ADDED_EXTENSION_LINE}"; then
2018-04-12 09:41:16 +00:00
echo 'No new extensions detected.'
fi