Skip to content

Commit

Permalink
feature: handle PDO driver extensions
Browse files Browse the repository at this point in the history
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<version>-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 <[email protected]>
  • Loading branch information
boesing committed Sep 26, 2024
1 parent 9fdebed commit 89eba26
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions scripts/extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 100 in scripts/extensions.sh

View workflow job for this annotation

GitHub Actions / ShellCheck

[shellcheck] reported by reviewdog 🐶 Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @). Raw Output: ./scripts/extensions.sh:100:13: error: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @). (ShellCheck.SC2199)

Check warning on line 100 in scripts/extensions.sh

View workflow job for this annotation

GitHub Actions / ShellCheck

[shellcheck] reported by reviewdog 🐶 Remove quotes from right-hand side of =~ to match as a regex rather than literally. Raw Output: ./scripts/extensions.sh:100:48: warning: Remove quotes from right-hand side of =~ to match as a regex rather than literally. (ShellCheck.SC2076)
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
Expand All @@ -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.
Expand Down

0 comments on commit 89eba26

Please sign in to comment.