From 89eba266fd61b6b60f2ff82bd292d0c0315f776a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:49:23 +0200 Subject: [PATCH] feature: handle PDO driver extensions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Projects `composer.json` can require specific PDO drivers such as `ext-pdo_mysql`. These are passed to the CI container as `pdo_mysql` and are then passed as `php-pdo_mysql` package to `apt install`. These packages do not exist and thus there will be an error if the appropriate extension(s) was/were not already installed/enabled. This patch handles the most common drivers `mysql`, `pgsql` and `sqlite` and ensure that these are installed/enabled along with the `pdo` extension. Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com> --- scripts/extensions.sh | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/scripts/extensions.sh b/scripts/extensions.sh index 56c2dd8..342c501 100755 --- a/scripts/extensions.sh +++ b/scripts/extensions.sh @@ -93,10 +93,18 @@ declare -a EXTENSIONS=(${@:2}) ENABLED_EXTENSIONS=$(php -m | tr '[:upper:]' '[:lower:]' | egrep -v '^[\[]' | grep -v 'zend opcache') EXTENSIONS_TO_INSTALL=() +add_extension_to_install() { + local extension=$1 + + # Prevent duplicates + if [[ ! " ${EXTENSIONS_TO_INSTALL[@]} " =~ " ${extension} " ]]; then + EXTENSIONS_TO_INSTALL+=("${extension}") + fi +} + # Loop through known statically compiled/installed extensions, and enable them. # NOTE: when developing on MacOS, remove the quotes while implementing your changes and re-add the quotes afterwards. for EXTENSION in "${EXTENSIONS[@]}"; do - # Check if extension is already enabled REGULAR_EXPRESSION=\\b${EXTENSION}\\b if [[ "${ENABLED_EXTENSIONS}" =~ $REGULAR_EXPRESSION ]]; then @@ -112,7 +120,32 @@ for EXTENSION in "${EXTENSIONS[@]}"; do continue; fi - EXTENSIONS_TO_INSTALL+=("$EXTENSION") + if [[ "${EXTENSION}" =~ ^pdo_ ]]; then + case "${EXTENSION}" in + "pdo_mysql") + add_extension_to_install "mysql" + ;; + "pdo_sqlite") + add_extension_to_install "sqlite3" + ;; + "pdo_pgsql") + add_extension_to_install "pgsql" + ;; + *) + echo "Unsupported PDO driver extension \"${EXTENSION}\" cannot is not (yet) supported." + echo -n "In case the extension is not available already, please consider using .pre-install.sh to install" + echo " the appropriate extension." + echo -n "If you think its worth to have the PDO driver extension installed automatically, please create" + echo " a feature request on github: https://github.com/laminas/laminas-continuous-integration-action/issues" + continue; + ;; + esac + + add_extension_to_install "pdo" + continue; + fi + + add_extension_to_install "${EXTENSION}" done # If by now the extensions list is not empty, install missing extensions.