Fix coding style

This commit is contained in:
Michele Locati 2019-12-20 16:52:00 +01:00
parent 7748bb159a
commit 1ba29d90cf
No known key found for this signature in database
GPG Key ID: 98B7CE2E7234E28B
5 changed files with 148 additions and 181 deletions

View File

@ -13,7 +13,7 @@ set -o errexit
set -o nounset set -o nounset
# Reset the Internal Field Separator # Reset the Internal Field Separator
resetIFS () { resetIFS() {
IFS=' IFS='
' '
} }
@ -22,7 +22,7 @@ resetIFS () {
# #
# Output: # Output:
# alpine|debian # alpine|debian
getDistro () { getDistro() {
getDistro_os_id='' getDistro_os_id=''
if test -r /etc/os-release; then if test -r /etc/os-release; then
getDistro_os_id="$(cat /etc/os-release | grep -E ^ID= | cut -d = -f 2)" getDistro_os_id="$(cat /etc/os-release | grep -E ^ID= | cut -d = -f 2)"
@ -35,7 +35,7 @@ getDistro () {
# Example output: # Example output:
# alpine@3.10 # alpine@3.10
# debian@9 # debian@9
getDistroVersion () { getDistroVersion() {
getDistroVersion_distro="$(getDistro)" getDistroVersion_distro="$(getDistro)"
if test -z "$getDistroVersion_distro"; then if test -z "$getDistroVersion_distro"; then
return return
@ -54,7 +54,7 @@ getDistroVersion () {
# #
# Output: # Output:
# The PHP numeric Major-Minor version # The PHP numeric Major-Minor version
getPHPMajorMinor () { getPHPMajorMinor() {
php -r '$v = explode(".", PHP_VERSION); echo $v[0] * 100 + $v[1];' php -r '$v = explode(".", PHP_VERSION); echo $v[0] * 100 + $v[1];'
} }
@ -62,25 +62,24 @@ getPHPMajorMinor () {
# #
# Output: # Output:
# Space-separated list of module handles # Space-separated list of module handles
getPHPInstalledModules () { getPHPInstalledModules() {
getPHPInstalledModules_result='' getPHPInstalledModules_result=''
IFS=' IFS='
' '
for getPHPInstalledModules_module in $(php -m); do for getPHPInstalledModules_module in $(php -m); do
getPHPInstalledModules_moduleNormalized='' getPHPInstalledModules_moduleNormalized=''
case "$getPHPInstalledModules_module" in case "$getPHPInstalledModules_module" in
\[PHP\ Modules\]) \[PHP\ Modules\]) ;;
;;
\[Zend\ Modules\]) \[Zend\ Modules\])
break break
;; ;;
Core|PDO|PDO_*|Phar|Reflection|SimpleXML|SPL|SQLite|Xdebug) Core | PDO | PDO_* | Phar | Reflection | SimpleXML | SPL | SQLite | Xdebug)
getPHPInstalledModules_moduleNormalized=$(LC_CTYPE=C printf '%s' "$getPHPInstalledModules_module" | tr '[:upper:]' '[:lower:]') getPHPInstalledModules_moduleNormalized=$(LC_CTYPE=C printf '%s' "$getPHPInstalledModules_module" | tr '[:upper:]' '[:lower:]')
;; ;;
Zend\ OPcache) Zend\ OPcache)
getPHPInstalledModules_moduleNormalized='opcache' getPHPInstalledModules_moduleNormalized='opcache'
;; ;;
*\ *|*A*|*B*|*C*|*D*|*E*|*F*|*G*|*H*|*I*|*J*|*K*|*L*|*M*|*N*|*O*|*P*|*Q*|*R*|*S*|*T*|*U*|*V*|*W*|*X*|*Y*|*Z*) *\ * | *A* | *B* | *C* | *D* | *E* | *F* | *G* | *H* | *I* | *J* | *K* | *L* | *M* | *N* | *O* | *P* | *Q* | *R* | *S* | *T* | *U* | *V* | *W* | *X* | *Y* | *Z*)
printf '### WARNING Unrecognized module name: %s ###\n' "$getPHPInstalledModules_module" >&2 printf '### WARNING Unrecognized module name: %s ###\n' "$getPHPInstalledModules_module" >&2
;; ;;
*) *)
@ -107,7 +106,7 @@ getPHPInstalledModules () {
# #
# Output: # Output:
# Nothing # Nothing
processCommandArguments () { processCommandArguments() {
processCommandArguments_alreadyInstalled="$(getPHPInstalledModules)" processCommandArguments_alreadyInstalled="$(getPHPInstalledModules)"
processCommandArguments_endArgs=0 processCommandArguments_endArgs=0
PHP_MODULES_TO_INSTALL='' PHP_MODULES_TO_INSTALL=''
@ -153,7 +152,7 @@ processCommandArguments () {
# #
# Output: # Output:
# Nothing # Nothing
sortModulesToInstall () { sortModulesToInstall() {
if stringInList 'igbinary' "$PHP_MODULES_TO_INSTALL"; then if stringInList 'igbinary' "$PHP_MODULES_TO_INSTALL"; then
PHP_MODULES_TO_INSTALL="$(removeStringFromList 'igbinary' "$PHP_MODULES_TO_INSTALL")" PHP_MODULES_TO_INSTALL="$(removeStringFromList 'igbinary' "$PHP_MODULES_TO_INSTALL")"
if test -z "$PHP_MODULES_TO_INSTALL"; then if test -z "$PHP_MODULES_TO_INSTALL"; then
@ -185,7 +184,7 @@ sortModulesToInstall () {
# Return: # Return:
# 0 (true): if we to install some package # 0 (true): if we to install some package
# 1 (false): if no package is required # 1 (false): if no package is required
buildRequiredPackageLists () { buildRequiredPackageLists() {
buildRequiredPackageLists_persistent='' buildRequiredPackageLists_persistent=''
buildRequiredPackageLists_volatile='' buildRequiredPackageLists_volatile=''
buildRequiredPackageLists_distro="$(getDistro)" buildRequiredPackageLists_distro="$(getDistro)"
@ -580,7 +579,7 @@ buildRequiredPackageLists () {
# #
# Output: # Output:
# Space-separated list of every APT/APK packages that will be installed # Space-separated list of every APT/APK packages that will be installed
expandPackagesToBeInstalled () { expandPackagesToBeInstalled() {
expandPackagesToBeInstalled_result='' expandPackagesToBeInstalled_result=''
case "$(getDistro)" in case "$(getDistro)" in
alpine) alpine)
@ -637,7 +636,7 @@ expandPackagesToBeInstalled () {
# #
# Arguments: # Arguments:
# $@: the list of APT/APK packages to be installed # $@: the list of APT/APK packages to be installed
installRequiredPackages () { installRequiredPackages() {
printf '### INSTALLING REQUIRED PACKAGES ###\n' printf '### INSTALLING REQUIRED PACKAGES ###\n'
printf '# Packages to be kept after installation: %s\n' "$PACKAGES_PERSISTENT" printf '# Packages to be kept after installation: %s\n' "$PACKAGES_PERSISTENT"
printf '# Packages to be used only for installation: %s\n' "$PACKAGES_VOLATILE" printf '# Packages to be used only for installation: %s\n' "$PACKAGES_VOLATILE"
@ -667,7 +666,7 @@ installRequiredPackages () {
getInstalledPackageVersion() { getInstalledPackageVersion() {
case "$(getDistro)" in case "$(getDistro)" in
alpine) alpine)
apk info "$1" | head -n1 | cut -c $(( ${#1} + 2 ))- | grep -o -E '^[0-9]+(\.[0-9]+){0,2}' apk info "$1" | head -n1 | cut -c $((${#1} + 2))- | grep -o -E '^[0-9]+(\.[0-9]+){0,2}'
;; ;;
debian) debian)
dpkg-query --showformat='${Version}' --show "$1" 2>/dev/null | grep -o -E '^[0-9]+(\.[0-9]+){0,2}' dpkg-query --showformat='${Version}' --show "$1" 2>/dev/null | grep -o -E '^[0-9]+(\.[0-9]+){0,2}'
@ -688,7 +687,7 @@ getInstalledPackageVersion() {
compareVersions() { compareVersions() {
compareVersions_v1="$1.0.0" compareVersions_v1="$1.0.0"
compareVersions_v2="$2.0.0" compareVersions_v2="$2.0.0"
compareVersions_vMin="$(printf '%s\n%s' "${compareVersions_v1}" "${compareVersions_v2}" | sort -t '.' -n -k1,1 -k2,2 -k3,3 | head -n 1)" compareVersions_vMin="$(printf '%s\n%s' "$compareVersions_v1" "$compareVersions_v2" | sort -t '.' -n -k1,1 -k2,2 -k3,3 | head -n 1)"
if test "$compareVersions_vMin" != "$compareVersions_v1"; then if test "$compareVersions_vMin" != "$compareVersions_v1"; then
echo '1' echo '1'
elif test "$compareVersions_vMin" = "$compareVersions_v2"; then elif test "$compareVersions_vMin" = "$compareVersions_v2"; then
@ -709,7 +708,7 @@ compareVersions() {
# #
# Output: # Output:
# Nothing # Nothing
installBundledModule () { installBundledModule() {
printf '### INSTALLING BUNDLED MODULE %s ###\n' "$2" printf '### INSTALLING BUNDLED MODULE %s ###\n' "$2"
case "$2" in case "$2" in
gd) gd)
@ -736,7 +735,7 @@ installBundledModule () {
imap) imap)
PHP_OPENSSL=yes docker-php-ext-configure imap --with-kerberos --with-imap-ssl PHP_OPENSSL=yes docker-php-ext-configure imap --with-kerberos --with-imap-ssl
;; ;;
interbase|pdo_firebird) interbase | pdo_firebird)
case "$(getDistro)" in case "$(getDistro)" in
alpine) alpine)
if ! test -d /tmp/src/firebird; then if ! test -d /tmp/src/firebird; then
@ -758,9 +757,9 @@ installBundledModule () {
ldap) ldap)
docker-php-ext-configure ldap --with-libdir=lib/$(gcc -dumpmachine) docker-php-ext-configure ldap --with-libdir=lib/$(gcc -dumpmachine)
;; ;;
mssql|pdo_dblib) mssql | pdo_dblib)
case "$1" in case "$1" in
506|700|701|702|703|704) 506 | 700 | 701 | 702 | 703 | 704)
if ! test -f /usr/lib/libsybdb.so; then if ! test -f /usr/lib/libsybdb.so; then
ln -s /usr/lib/x86_64-linux-gnu/libsybdb.so /usr/lib/libsybdb.so ln -s /usr/lib/x86_64-linux-gnu/libsybdb.so /usr/lib/libsybdb.so
UNNEEDED_PACKAGE_LINKS="$UNNEEDED_PACKAGE_LINKS /usr/lib/libsybdb.so" UNNEEDED_PACKAGE_LINKS="$UNNEEDED_PACKAGE_LINKS /usr/lib/libsybdb.so"
@ -770,7 +769,7 @@ installBundledModule () {
;; ;;
odbc) odbc)
case "$1" in case "$1" in
506|700|701|702|703|704) 506 | 700 | 701 | 702 | 703 | 704)
docker-php-source extract docker-php-source extract
cd /usr/src/php/ext/odbc cd /usr/src/php/ext/odbc
phpize phpize
@ -821,7 +820,7 @@ installBundledModule () {
# #
# Output: # Output:
# The path of the extracted directory # The path of the extracted directory
getPackageSource () { getPackageSource() {
mkdir -p /tmp/src mkdir -p /tmp/src
getPackageSource_tempFile=$(mktemp -p /tmp/src) getPackageSource_tempFile=$(mktemp -p /tmp/src)
curl -L -s -S -o "$getPackageSource_tempFile" "$1" curl -L -s -S -o "$getPackageSource_tempFile" "$1"
@ -852,7 +851,7 @@ getPackageSource () {
# $2: the URL of the module source code # $2: the URL of the module source code
# $3: the options of the configure command # $3: the options of the configure command
# $4: the value of CFLAGS # $4: the value of CFLAGS
installModuleFromSource () { installModuleFromSource() {
printf '### INSTALLING MODULE %s FROM SOURCE CODE ###\n' "$1" printf '### INSTALLING MODULE %s FROM SOURCE CODE ###\n' "$1"
installModuleFromSource_dir="$(getPackageSource "$2")" installModuleFromSource_dir="$(getPackageSource "$2")"
cd "$installModuleFromSource_dir" cd "$installModuleFromSource_dir"
@ -868,7 +867,7 @@ installModuleFromSource () {
# Arguments: # Arguments:
# $1: the numeric PHP Major-Minor version # $1: the numeric PHP Major-Minor version
# $2: the handle of the PHP module # $2: the handle of the PHP module
installPECLModule () { installPECLModule() {
printf '### INSTALLING PECL MODULE %s ###\n' "$2" printf '### INSTALLING PECL MODULE %s ###\n' "$2"
installPECLModule_actual="$2" installPECLModule_actual="$2"
installPECLModule_stdin='\n' installPECLModule_stdin='\n'
@ -1054,7 +1053,7 @@ installPECLModule () {
# Return: # Return:
# 0 (true): if the string is in the list # 0 (true): if the string is in the list
# 1 (false): if the string is not in the list # 1 (false): if the string is not in the list
stringInList () { stringInList() {
for stringInList_listItem in $2; do for stringInList_listItem in $2; do
if test "$1" = "$stringInList_listItem"; then if test "$1" = "$stringInList_listItem"; then
return 0 return 0
@ -1071,7 +1070,7 @@ stringInList () {
# #
# Output: # Output:
# The list without the word # The list without the word
removeStringFromList () { removeStringFromList() {
removeStringFromList_result='' removeStringFromList_result=''
for removeStringFromList_listItem in $2; do for removeStringFromList_listItem in $2; do
if test "$1" != "$removeStringFromList_listItem"; then if test "$1" != "$removeStringFromList_listItem"; then
@ -1086,7 +1085,7 @@ removeStringFromList () {
} }
# Cleanup everything at the end of the execution # Cleanup everything at the end of the execution
cleanup () { cleanup() {
cleanup_distro="$(getDistro)" cleanup_distro="$(getDistro)"
if test -n "$UNNEEDED_PACKAGE_LINKS"; then if test -n "$UNNEEDED_PACKAGE_LINKS"; then
printf '### REMOVING UNNEEDED PACKAGE LINKS ###\n' printf '### REMOVING UNNEEDED PACKAGE LINKS ###\n'
@ -1123,10 +1122,10 @@ cleanup () {
resetIFS resetIFS
PHP_MAJMIN_VERSION=$(getPHPMajorMinor) PHP_MAJMIN_VERSION=$(getPHPMajorMinor)
case "$PHP_MAJMIN_VERSION" in case "$PHP_MAJMIN_VERSION" in
506|700|701|702|703|704) 506 | 700 | 701 | 702 | 703 | 704) ;;
;;
*) *)
printf "### ERROR: Unsupported PHP version: %s.%s ###\n" $(( PHP_MAJMIN_VERSION / 100 )) $(( PHP_MAJMIN_VERSION % 100 )) printf "### ERROR: Unsupported PHP version: %s.%s ###\n" $((PHP_MAJMIN_VERSION / 100)) $((PHP_MAJMIN_VERSION % 100))
;;
esac esac
UNNEEDED_PACKAGE_LINKS='' UNNEEDED_PACKAGE_LINKS=''
processCommandArguments "$@" processCommandArguments "$@"

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# Reset the Internal Field Separator # Reset the Internal Field Separator
resetIFS () { resetIFS() {
IFS=' IFS='
' '
} }
@ -15,12 +15,10 @@ resetIFS () {
# Return: # Return:
# 0 (true): if the string is in the list # 0 (true): if the string is in the list
# 1 (false): if the string is not in the list # 1 (false): if the string is not in the list
stringInList () { stringInList() {
resetIFS resetIFS
for stringInList_listItem in ${2} for stringInList_listItem in $2; do
do if test "$1" = "$stringInList_listItem"; then
if test "${1}" = "${stringInList_listItem}"
then
return 0 return 0
fi fi
done done
@ -35,20 +33,17 @@ stringInList () {
# #
# Output: # Output:
# The space-separated list of strings that are present in both lists # The space-separated list of strings that are present in both lists
commonElements () { commonElements() {
commonElements_result='' commonElements_result=''
resetIFS resetIFS
for commonElements_inA in ${1} for commonElements_inA in $1; do
do if stringInList "$commonElements_inA" "$2"; then
if stringInList "${commonElements_inA}" "${2}" if test -z "$commonElements_result"; then
then commonElements_result="$commonElements_inA"
if test -z "${commonElements_result}"
then
commonElements_result="${commonElements_inA}"
else else
commonElements_result="${commonElements_result} ${commonElements_inA}" commonElements_result="$commonElements_result $commonElements_inA"
fi fi
fi fi
done done
echo "${commonElements_result}" echo "$commonElements_result"
} }

View File

@ -22,7 +22,7 @@ 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"
@ -43,8 +43,7 @@ getDockerImageName () {
alpine3.4) alpine3.4)
# available for PHP from version 5.6 to version 7.1 # available for PHP from version 5.6 to version 7.1
case "$2" in case "$2" in
5.*|7.0|7.1) 5.* | 7.0 | 7.1) ;;
;;
*) *)
return return
;; ;;
@ -53,8 +52,7 @@ getDockerImageName () {
alpine3.6) alpine3.6)
# available for PHP 7.2 # available for PHP 7.2
case "$2" in case "$2" in
7.2) 7.2) ;;
;;
*) *)
return return
;; ;;
@ -67,8 +65,7 @@ getDockerImageName () {
7.0) 7.0)
#getDockerImageName_distro='-alpine' #getDockerImageName_distro='-alpine'
;; ;;
5.*|7.1|7.2) 5.* | 7.1 | 7.2) ;;
;;
*) *)
return return
;; ;;
@ -81,8 +78,7 @@ getDockerImageName () {
5.6) 5.6)
#getDockerImageName_distro='-alpine' #getDockerImageName_distro='-alpine'
;; ;;
5.*|7.1|7.2|7.3) 5.* | 7.1 | 7.2 | 7.3) ;;
;;
*) *)
return return
;; ;;
@ -91,8 +87,7 @@ getDockerImageName () {
alpine3.9) alpine3.9)
# available for PHP from version 7.1 to version 7.3 # available for PHP from version 7.1 to version 7.3
case "$2" in case "$2" in
7.1|7.2|7.3) 7.1 | 7.2 | 7.3) ;;
;;
*) *)
return return
;; ;;
@ -102,10 +97,10 @@ getDockerImageName () {
# available for PHP from version 7.1 # available for PHP from version 7.1
# default Alpine one for PHP 7.1 -> 7.4 # default Alpine one for PHP 7.1 -> 7.4
case "$2" in case "$2" in
7.1|7.2|7.3|7.4) 7.1 | 7.2 | 7.3 | 7.4)
#getDockerImageName_distro='-alpine' #getDockerImageName_distro='-alpine'
;; ;;
5.*|7.0) 5.* | 7.0)
return return
;; ;;
esac esac
@ -113,8 +108,7 @@ getDockerImageName () {
jessie) # Debian 8 jessie) # Debian 8
# available for PHP up to version 7.1 # available for PHP up to version 7.1
case "$2" in case "$2" in
5.*|7.0|7.1) 5.* | 7.0 | 7.1) ;;
;;
*) *)
return return
;; ;;
@ -124,11 +118,10 @@ getDockerImageName () {
# available for PHP up to version 7.3 # available for PHP up to version 7.3
# default one for PHP 5.6 -> 7.0 # default one for PHP 5.6 -> 7.0
case "$2" in case "$2" in
5.*|7.0) 5.* | 7.0)
#getDockerImageName_distro='' #getDockerImageName_distro=''
;; ;;
7.1|7.2|7.3) 7.1 | 7.2 | 7.3) ;;
;;
*) *)
return return
;; ;;
@ -138,10 +131,10 @@ getDockerImageName () {
# available for PHP from version 7.1 # available for PHP from version 7.1
# default one for PHP 7.1 -> 7.4 # default one for PHP 7.1 -> 7.4
case "$2" in case "$2" in
7.1|7.2|7.3|7.4) 7.1 | 7.2 | 7.3 | 7.4)
#getDockerImageName_distro='' #getDockerImageName_distro=''
;; ;;
5.*|7.0) 5.* | 7.0)
return return
;; ;;
esac esac
@ -154,7 +147,6 @@ getDockerImageName () {
printf 'php:%s%s%s' "$getDockerImageName_version" "$getDockerImageName_suffix" "$getDockerImageName_distro" printf 'php:%s%s%s' "$getDockerImageName_version" "$getDockerImageName_suffix" "$getDockerImageName_distro"
} }
# Test an extension # Test an extension
# #
# Arguments: # Arguments:
@ -164,7 +156,7 @@ getDockerImageName () {
# Return: # Return:
# 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
@ -176,7 +168,7 @@ testExtension () {
return 0 return 0
fi fi
printf ' - Docker image: %s\n' "$testExtension_Image" 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'
@ -188,7 +180,6 @@ testExtension () {
return 1 return 1
} }
# Test a new extension line # Test a new extension line
# #
# Arguments: # Arguments:
@ -198,7 +189,7 @@ testExtension () {
# Return: # Return:
# 0 (true): if test passes # 0 (true): if test passes
# 1 (false): if test fails # 1 (false): if test fails
testNewExtensionLine () { testNewExtensionLine() {
testNewExtensionLine_rc=0 testNewExtensionLine_rc=0
if test $# -lt 2; then if test $# -lt 2; then
printf 'Missing PHP version list for the new extension %s\n' "${1:-}" printf 'Missing PHP version list for the new extension %s\n' "${1:-}"
@ -223,7 +214,6 @@ testNewExtensionLine () {
return $testNewExtensionLine_rc return $testNewExtensionLine_rc
} }
# Get the list of all supported PHP versions # Get the list of all supported PHP versions
# #
# Arguments: # Arguments:
@ -231,7 +221,7 @@ testNewExtensionLine () {
# #
# Outputs: # Outputs:
# the space-separated list of supported PHP versions # the space-separated list of supported PHP versions
getAllPHPVersionsForExtensions () { getAllPHPVersionsForExtensions() {
getAllPHPVersionsForExtensions_result='' getAllPHPVersionsForExtensions_result=''
IFS=' ' IFS=' '
for getAllPHPVersionsForExtensions_extension in $1; do for getAllPHPVersionsForExtensions_extension in $1; do
@ -261,7 +251,7 @@ getAllPHPVersionsForExtensions () {
# #
# Outputs: # Outputs:
# the space-separated list of supported PHP versions # the space-separated list of supported PHP versions
getAllPHPVersionsForExtension () { getAllPHPVersionsForExtension() {
getAllPHPVersionsForExtension_result='' getAllPHPVersionsForExtension_result=''
while IFS= read -r getAllPHPVersionsForExtension_line; do while IFS= read -r getAllPHPVersionsForExtension_line; do
getAllPHPVersionsForExtension_ok= getAllPHPVersionsForExtension_ok=
@ -285,11 +275,10 @@ getAllPHPVersionsForExtension () {
fi fi
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"
} }
# Test extensions by reading a commit message # Test extensions by reading a commit message
# #
# Arguments: # Arguments:
@ -301,27 +290,26 @@ getAllPHPVersionsForExtension () {
# Return: # Return:
# 0 (true): if test passes # 0 (true): if test passes
# 1 (false): if test fails # 1 (false): if test fails
testExtensionsFromMessage () { 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='
' '
for COMMIT_LINE in $testExtensionsFromMessage_message; do for COMMIT_LINE in $testExtensionsFromMessage_message; do
if test $FIRST_LINE -eq 1; then if test $FIRST_LINE -eq 1; then
FIRST_LINE=0 FIRST_LINE=0
else else
TESTLIST= TESTLIST=
case "$COMMIT_LINE" in case "$COMMIT_LINE" in
Test:* ) Test:*)
TESTLIST=${COMMIT_LINE#Test:} TESTLIST=${COMMIT_LINE#Test:}
;; ;;
TEST:* ) TEST:*)
TESTLIST=${COMMIT_LINE#TEST:} TESTLIST=${COMMIT_LINE#TEST:}
;; ;;
test:* ) test:*)
TESTLIST=${COMMIT_LINE#test:} TESTLIST=${COMMIT_LINE#test:}
;; ;;
esac esac
@ -331,7 +319,7 @@ testExtensionsFromMessage () {
if test $COMMIT_LINE_EXT = '-STOP-'; then if test $COMMIT_LINE_EXT = '-STOP-'; then
STOP_NEXT_COMMITS=1 STOP_NEXT_COMMITS=1
elif test -z "$TEST_EXTENSIONS"; then elif test -z "$TEST_EXTENSIONS"; then
TEST_EXTENSIONS=$COMMIT_LINE_EXT; TEST_EXTENSIONS=$COMMIT_LINE_EXT
else else
if ! stringInList "$COMMIT_LINE_EXT" "$TEST_EXTENSIONS"; then if ! stringInList "$COMMIT_LINE_EXT" "$TEST_EXTENSIONS"; then
TEST_EXTENSIONS="$TEST_EXTENSIONS $COMMIT_LINE_EXT" TEST_EXTENSIONS="$TEST_EXTENSIONS $COMMIT_LINE_EXT"
@ -380,7 +368,6 @@ for DIFF_LINE in $(git -C "$TRAVIS_BUILD_DIR" diff --no-indent-heuristic --minim
fi fi
done 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

View File

@ -9,19 +9,15 @@ UPDATE_README_COMMIT_AUTHOR_EMAIL='michele@locati.it'
UPDATE_README_COMMIT_MESSAGE='[skip ci] Automatically update README.md' UPDATE_README_COMMIT_MESSAGE='[skip ci] Automatically update README.md'
WATCHED_FILES='data/special-requirements data/supported-extensions scripts/common scripts/update-readme scripts/travisci-update-readme' WATCHED_FILES='data/special-requirements data/supported-extensions scripts/common scripts/update-readme scripts/travisci-update-readme'
SCRIPTS_DIR="$(CDPATH= cd -- "$(dirname -- "${0}")" && pwd)" SCRIPTS_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
. "${SCRIPTS_DIR}/common" . "$SCRIPTS_DIR/common"
echo 'Checking environment' echo 'Checking environment'
if test -z "${TRAVIS_BUILD_DIR:-}" || test -z "${TRAVIS_BRANCH:-}" || test -z "${TRAVIS_EVENT_TYPE:-}" || test -z "${TRAVIS_REPO_SLUG:-}" if test -z "${TRAVIS_BUILD_DIR:-}" || test -z "${TRAVIS_BRANCH:-}" || test -z "${TRAVIS_EVENT_TYPE:-}" || test -z "${TRAVIS_REPO_SLUG:-}"; then
then
echo 'Not in a TravisCI environment' >&2 echo 'Not in a TravisCI environment' >&2
exit 1 exit 1
fi fi
if test -z "${GUTHUB_ACCESS_TOKEN:-}" if test -z "${GUTHUB_ACCESS_TOKEN:-}"; then
then
echo 'GitHub access token not set' >&2 echo 'GitHub access token not set' >&2
# To create it: # To create it:
# - go to https://github.com/settings/tokens/new?scopes=repo # - go to https://github.com/settings/tokens/new?scopes=repo
@ -35,47 +31,43 @@ then
# - secure: "encrypted string" # - secure: "encrypted string"
exit 1 exit 1
fi fi
if test "${TRAVIS_EVENT_TYPE}" != 'push' if test "$TRAVIS_EVENT_TYPE" != 'push'; then
then
echo 'This script should only be run in push builds' >&2 echo 'This script should only be run in push builds' >&2
exit 1 exit 1
fi fi
printf 'Checking-out branch %s\n' "${TRAVIS_BRANCH}" printf 'Checking-out branch %s\n' "$TRAVIS_BRANCH"
git checkout --force "${TRAVIS_BRANCH}" git checkout --force "$TRAVIS_BRANCH"
LAST_AUTO_UPDATED_IN="$(git -C "${TRAVIS_BUILD_DIR}" rev-list --max-count 1 --author "<${UPDATE_README_COMMIT_AUTHOR_EMAIL}>" --grep "${UPDATE_README_COMMIT_MESSAGE}" "${TRAVIS_BRANCH}")" LAST_AUTO_UPDATED_IN="$(git -C "$TRAVIS_BUILD_DIR" rev-list --max-count 1 --author "<$UPDATE_README_COMMIT_AUTHOR_EMAIL>" --grep "$UPDATE_README_COMMIT_MESSAGE" "$TRAVIS_BRANCH")"
if test -z "${LAST_AUTO_UPDATED_IN}" if test -z "$LAST_AUTO_UPDATED_IN"; then
then printf 'Rebuild of README.md enabled (no previous automatic refresh of it in branch %s)\n' "$TRAVIS_BRANCH"
printf 'Rebuild of README.md enabled (no previous automatic refresh of it in branch %s)\n' "${TRAVIS_BRANCH}"
else else
MODIFIED_FILES_SINCE="$(git -C "${TRAVIS_BUILD_DIR}" diff --name-only "${LAST_AUTO_UPDATED_IN}...${TRAVIS_BRANCH}")" MODIFIED_FILES_SINCE="$(git -C "$TRAVIS_BUILD_DIR" diff --name-only "$LAST_AUTO_UPDATED_IN...$TRAVIS_BRANCH")"
if test -z "$(commonElements "${WATCHED_FILES}" "${MODIFIED_FILES_SINCE}")" if test -z "$(commonElements "$WATCHED_FILES" "$MODIFIED_FILES_SINCE")"; then
then printf 'Rebuild of README.md not needed (no relevant files changed in branch %s since commit %s)\n' "$TRAVIS_BRANCH" "$LAST_AUTO_UPDATED_IN"
printf 'Rebuild of README.md not needed (no relevant files changed in branch %s since commit %s)\n' "${TRAVIS_BRANCH}" "${LAST_AUTO_UPDATED_IN}"
exit 0 exit 0
fi fi
printf 'Rebuild of README.md enabled (relevant files changed in branch %s since commit %s)\n' "${TRAVIS_BRANCH}" "${LAST_AUTO_UPDATED_IN}" printf 'Rebuild of README.md enabled (relevant files changed in branch %s since commit %s)\n' "$TRAVIS_BRANCH" "$LAST_AUTO_UPDATED_IN"
fi fi
echo 'Updating README.md' echo 'Updating README.md'
"${TRAVIS_BUILD_DIR}/scripts/update-readme" "$TRAVIS_BUILD_DIR/scripts/update-readme"
if test -z "$(git -C "${TRAVIS_BUILD_DIR}" ls-files -m | grep -E '^README\.md$')" if test -z "$(git -C "$TRAVIS_BUILD_DIR" ls-files -m | grep -E '^README\.md$')"; then
then
echo 'README.md has not been changed' echo 'README.md has not been changed'
exit 0 exit 0
fi fi
printf 'Adding %s remote\n' "${TRAVIS_REPO_SLUG}" printf 'Adding %s remote\n' "$TRAVIS_REPO_SLUG"
git remote add deploy "https://${GUTHUB_ACCESS_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git" git remote add deploy "https://$GUTHUB_ACCESS_TOKEN@github.com/$TRAVIS_REPO_SLUG.git"
echo 'Committing changes to README.md' echo 'Committing changes to README.md'
git -C "${TRAVIS_BUILD_DIR}" config user.name "${UPDATE_README_COMMIT_AUTHOR_NAME}" git -C "$TRAVIS_BUILD_DIR" config user.name "$UPDATE_README_COMMIT_AUTHOR_NAME"
git -C "${TRAVIS_BUILD_DIR}" config user.email "${UPDATE_README_COMMIT_AUTHOR_EMAIL}" git -C "$TRAVIS_BUILD_DIR" config user.email "$UPDATE_README_COMMIT_AUTHOR_EMAIL"
git -C "${TRAVIS_BUILD_DIR}" add README.md git -C "$TRAVIS_BUILD_DIR" add README.md
git -C "${TRAVIS_BUILD_DIR}" commit -m "${UPDATE_README_COMMIT_MESSAGE}" git -C "$TRAVIS_BUILD_DIR" commit -m "$UPDATE_README_COMMIT_MESSAGE"
printf 'Pushing to %s\n' "${TRAVIS_REPO_SLUG}" printf 'Pushing to %s\n' "$TRAVIS_REPO_SLUG"
git push deploy "${TRAVIS_BRANCH}" git push deploy "$TRAVIS_BRANCH"
echo 'Done.' echo 'Done.'

View File

@ -3,12 +3,11 @@
set -o errexit set -o errexit
set -o nounset set -o nounset
SCRIPTS_DIR="$(CDPATH= cd -- "$(dirname -- "${0}")" && pwd)" SCRIPTS_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
ROOT_DIR="$(dirname -- "${SCRIPTS_DIR}")" ROOT_DIR="$(dirname -- "$SCRIPTS_DIR")"
DATA_DIR="${ROOT_DIR}/data" DATA_DIR="$ROOT_DIR/data"
. "${SCRIPTS_DIR}/common"
. "$SCRIPTS_DIR/common"
# Get the list of PHP extensions from the data file # Get the list of PHP extensions from the data file
# #
@ -17,26 +16,25 @@ DATA_DIR="${ROOT_DIR}/data"
# #
# Output: # Output:
# the list of PHP extensions # the list of PHP extensions
getExtensionList () { getExtensionList() {
getExtensionList_extensions='' getExtensionList_extensions=''
IFS=' IFS='
' '
for getExtensionList_line in $(cat -- "${1}" | sort); do for getExtensionList_line in $(cat -- "$1" | sort); do
getExtensionList_extension='' getExtensionList_extension=''
IFS=' ' IFS=' '
for getExtensionList_chunk in ${getExtensionList_line}; do for getExtensionList_chunk in $getExtensionList_line; do
if test -z "${getExtensionList_extensions}"; then if test -z "$getExtensionList_extensions"; then
getExtensionList_extensions="${getExtensionList_chunk}" getExtensionList_extensions="$getExtensionList_chunk"
else else
getExtensionList_extensions="${getExtensionList_extensions} ${getExtensionList_chunk}" getExtensionList_extensions="$getExtensionList_extensions $getExtensionList_chunk"
fi fi
break break
done done
done done
printf '%s' "${getExtensionList_extensions}" printf '%s' "$getExtensionList_extensions"
} }
# Get the list of PHP versions from the data file # Get the list of PHP versions from the data file
# #
# Arguments: # Arguments:
@ -44,27 +42,26 @@ getExtensionList () {
# #
# Output: # Output:
# the list of PHP versions # the list of PHP versions
getVersionList () { getVersionList() {
getVersionList_versions='' getVersionList_versions=''
IFS=' IFS='
' '
for getVersionList_line in $(cat -- "${1}" | sort); do for getVersionList_line in $(cat -- "$1" | sort); do
getVersionList_extension='' getVersionList_extension=''
IFS=' ' IFS=' '
for getVersionList_chunk in ${getVersionList_line}; do for getVersionList_chunk in $getVersionList_line; do
if test -z "${getVersionList_extension}"; then if test -z "$getVersionList_extension"; then
getVersionList_extension="${getVersionList_chunk}" getVersionList_extension="$getVersionList_chunk"
elif test -z "${getVersionList_versions}"; then elif test -z "$getVersionList_versions"; then
getVersionList_versions="${getVersionList_chunk}" getVersionList_versions="$getVersionList_chunk"
elif ! stringInList "${getVersionList_chunk}" "${getVersionList_versions}"; then elif ! stringInList "$getVersionList_chunk" "$getVersionList_versions"; then
getVersionList_versions="${getVersionList_versions} ${getVersionList_chunk}" getVersionList_versions="$getVersionList_versions $getVersionList_chunk"
fi fi
done done
done done
sortVersionList "${getVersionList_versions}" sortVersionList "$getVersionList_versions"
} }
# Sort the list of PHP versions # Sort the list of PHP versions
# #
# Arguments: # Arguments:
@ -72,21 +69,20 @@ getVersionList () {
# #
# Output: # Output:
# the sorted list of PHP versions # the sorted list of PHP versions
sortVersionList () { sortVersionList() {
sortVersionList_list='' sortVersionList_list=''
IFS=' IFS='
' '
for sortVersionList_version in $(printf '%s' "${1}" | tr ' ' '\n' | sort -t '.' -k 1,1n -k 2,2n -k 3,3n); do for sortVersionList_version in $(printf '%s' "$1" | tr ' ' '\n' | sort -t '.' -k 1,1n -k 2,2n -k 3,3n); do
if test -z "${sortVersionList_list}"; then if test -z "$sortVersionList_list"; then
sortVersionList_list="${sortVersionList_version}" sortVersionList_list="$sortVersionList_version"
else else
sortVersionList_list="${sortVersionList_list} ${sortVersionList_version}" sortVersionList_list="$sortVersionList_list $sortVersionList_version"
fi fi
done done
printf '%s' "${sortVersionList_list}" printf '%s' "$sortVersionList_list"
} }
# Generate the markdown table with the supported PHP extensions # Generate the markdown table with the supported PHP extensions
# #
# Arguments: # Arguments:
@ -94,41 +90,41 @@ sortVersionList () {
# #
# Output: # Output:
# the markdown table # the markdown table
generateExtensionsTable () { generateExtensionsTable() {
generateExtensionsTable_data=$(cat "${1}") generateExtensionsTable_data=$(cat "$1")
generateExtensionsTable_extensions="$(getExtensionList "${1}")" generateExtensionsTable_extensions="$(getExtensionList "$1")"
generateExtensionsTable_versions="$(getVersionList "${1}")" generateExtensionsTable_versions="$(getVersionList "$1")"
generateExtensionsTable_count=0 generateExtensionsTable_count=0
printf '| Extension |' printf '| Extension |'
IFS=' ' IFS=' '
for generateExtensionsTable_version in ${generateExtensionsTable_versions}; do for generateExtensionsTable_version in $generateExtensionsTable_versions; do
printf ' PHP %s |' "${generateExtensionsTable_version}" printf ' PHP %s |' "$generateExtensionsTable_version"
done done
printf '\n' printf '\n'
printf '|:---:|' printf '|:---:|'
for generateExtensionsTable_version in ${generateExtensionsTable_versions}; do for generateExtensionsTable_version in $generateExtensionsTable_versions; do
printf -- ':---:|' printf -- ':---:|'
done done
printf '\n' printf '\n'
IFS=' ' IFS=' '
for generateExtensionsTable_extension in ${generateExtensionsTable_extensions}; do for generateExtensionsTable_extension in $generateExtensionsTable_extensions; do
generateExtensionsTable_count=$((generateExtensionsTable_count + 1)) generateExtensionsTable_count=$((generateExtensionsTable_count + 1))
printf '| %s |' "${generateExtensionsTable_extension}" printf '| %s |' "$generateExtensionsTable_extension"
IFS=' ' IFS=' '
for generateExtensionsTable_version in ${generateExtensionsTable_versions}; do for generateExtensionsTable_version in $generateExtensionsTable_versions; do
printf ' ' printf ' '
generateExtensionsTable_versionOk='' generateExtensionsTable_versionOk=''
IFS=' IFS='
' '
for generateExtensionsTable_dataLine in ${generateExtensionsTable_data}; do for generateExtensionsTable_dataLine in $generateExtensionsTable_data; do
if stringInList "${generateExtensionsTable_extension}" "${generateExtensionsTable_dataLine}"; then if stringInList "$generateExtensionsTable_extension" "$generateExtensionsTable_dataLine"; then
if stringInList "${generateExtensionsTable_version}" "${generateExtensionsTable_dataLine}"; then if stringInList "$generateExtensionsTable_version" "$generateExtensionsTable_dataLine"; then
generateExtensionsTable_versionOk='y' generateExtensionsTable_versionOk='y'
fi fi
break break
fi fi
done done
if test -n "${generateExtensionsTable_versionOk}"; then if test -n "$generateExtensionsTable_versionOk"; then
printf 'V' printf 'V'
fi fi
printf ' |' printf ' |'
@ -139,7 +135,6 @@ generateExtensionsTable () {
printf '*Number of supported extensions: %s*\n' $generateExtensionsTable_count printf '*Number of supported extensions: %s*\n' $generateExtensionsTable_count
} }
# Generate the markdown table with the special requirements for the PHP extensions # Generate the markdown table with the special requirements for the PHP extensions
# #
# Arguments: # Arguments:
@ -147,30 +142,29 @@ generateExtensionsTable () {
# #
# Output: # Output:
# the markdown table # the markdown table
generateSpecialRequirementsTable () { generateSpecialRequirementsTable() {
generateSpecialRequirementsTable_started='' generateSpecialRequirementsTable_started=''
IFS=' IFS='
' '
for generateSpecialRequirementsTable_line in $(cat -- "${1}" | sort); do for generateSpecialRequirementsTable_line in $(cat -- "$1" | sort); do
if test -z "${generateSpecialRequirementsTable_started}"; then if test -z "$generateSpecialRequirementsTable_started"; then
printf '| Extension | Requirements |\n' printf '| Extension | Requirements |\n'
printf '|:---:|:---:|\n' printf '|:---:|:---:|\n'
generateSpecialRequirementsTable_started='y' generateSpecialRequirementsTable_started='y'
fi fi
resetIFS resetIFS
generateSpecialRequirementsTable_requirement="$(echo "${generateSpecialRequirementsTable_line}" | sed -E 's/^\s*\w+\s+//')" generateSpecialRequirementsTable_requirement="$(echo "$generateSpecialRequirementsTable_line" | sed -E 's/^\s*\w+\s+//')"
case "${generateSpecialRequirementsTable_requirement}" in case "$generateSpecialRequirementsTable_requirement" in
zts) zts)
generateSpecialRequirementsTable_requirement='Requires images with PHP compiled with thread-safety enabled (`zts`).' generateSpecialRequirementsTable_requirement='Requires images with PHP compiled with thread-safety enabled (`zts`).'
;; ;;
esac esac
printf '| %s | %s |\n' \ printf '| %s | %s |\n' \
"$(echo "${generateSpecialRequirementsTable_line}" | awk '{print $1;}')" \ "$(echo "$generateSpecialRequirementsTable_line" | awk '{print $1;}')" \
"${generateSpecialRequirementsTable_requirement}" "$generateSpecialRequirementsTable_requirement"
done done
} }
# Generate the contents of README.md # Generate the contents of README.md
# #
# Arguments: # Arguments:
@ -180,20 +174,20 @@ generateSpecialRequirementsTable () {
# #
# Output: # Output:
# the markdown table # the markdown table
generateReadme () { generateReadme() {
generateReadme_ph_ExtensionsStart='<!-- START OF EXTENSIONS TABLE -->' generateReadme_ph_ExtensionsStart='<!-- START OF EXTENSIONS TABLE -->'
generateReadme_ph_ExtensionsEnd='<!-- END OF EXTENSIONS TABLE -->' generateReadme_ph_ExtensionsEnd='<!-- END OF EXTENSIONS TABLE -->'
generateReadme_ph_SpecialStart='<!-- START OF SPECIAL REQUIREMENTS -->' generateReadme_ph_SpecialStart='<!-- START OF SPECIAL REQUIREMENTS -->'
generateReadme_ph_SpecialEnd='<!-- END OF SPECIAL REQUIREMENTS -->' generateReadme_ph_SpecialEnd='<!-- END OF SPECIAL REQUIREMENTS -->'
generateReadme_skip='' generateReadme_skip=''
while IFS= read -r generateReadme_line; do while IFS= read -r generateReadme_line; do
if test "${generateReadme_line}" = "${generateReadme_ph_ExtensionsEnd}" || test "${generateReadme_line}" = "${generateReadme_ph_SpecialEnd}"; then if test "$generateReadme_line" = "$generateReadme_ph_ExtensionsEnd" || test "$generateReadme_line" = "$generateReadme_ph_SpecialEnd"; then
generateReadme_skip='' generateReadme_skip=''
fi fi
if test -z "${generateReadme_skip}"; then if test -z "$generateReadme_skip"; then
printf '%s\n' "${generateReadme_line}" printf '%s\n' "$generateReadme_line"
fi fi
if test "${generateReadme_line}" = "${generateReadme_ph_ExtensionsStart}"; then if test "$generateReadme_line" = "$generateReadme_ph_ExtensionsStart"; then
generateReadme_skip='y' generateReadme_skip='y'
printf '<!-- ########################################################### -->\n' printf '<!-- ########################################################### -->\n'
printf '<!-- # # -->\n' printf '<!-- # # -->\n'
@ -202,8 +196,8 @@ generateReadme () {
printf '<!-- # EDIT THE data/supported-extensions FILE INSTEAD # -->\n' printf '<!-- # EDIT THE data/supported-extensions FILE INSTEAD # -->\n'
printf '<!-- # # -->\n' printf '<!-- # # -->\n'
printf '<!-- ########################################################### -->\n' printf '<!-- ########################################################### -->\n'
generateExtensionsTable "${2}" generateExtensionsTable "$2"
elif test "${generateReadme_line}" = "${generateReadme_ph_SpecialStart}"; then elif test "$generateReadme_line" = "$generateReadme_ph_SpecialStart"; then
generateReadme_skip='y' generateReadme_skip='y'
printf '<!-- ########################################################### -->\n' printf '<!-- ########################################################### -->\n'
printf '<!-- # # -->\n' printf '<!-- # # -->\n'
@ -212,11 +206,11 @@ generateReadme () {
printf '<!-- # EDIT THE data/special-requirements FILE INSTEAD # -->\n' printf '<!-- # EDIT THE data/special-requirements FILE INSTEAD # -->\n'
printf '<!-- # # -->\n' printf '<!-- # # -->\n'
printf '<!-- ########################################################### -->\n' printf '<!-- ########################################################### -->\n'
generateSpecialRequirementsTable "${3}" generateSpecialRequirementsTable "$3"
fi fi
done < "${1}" done <"$1"
printf '%s' "${generateReadme_line}" printf '%s' "$generateReadme_line"
} }
NEW_README="$(generateReadme "${ROOT_DIR}/README.md" "${DATA_DIR}/supported-extensions" "${DATA_DIR}/special-requirements")" NEW_README="$(generateReadme "$ROOT_DIR/README.md" "$DATA_DIR/supported-extensions" "$DATA_DIR/special-requirements")"
printf '%s\n' "${NEW_README}" > "${ROOT_DIR}/README.md" printf '%s\n' "$NEW_README" >"$ROOT_DIR/README.md"