Merge pull request #225 from mlocati/composer

Add support for installing composer
pull/226/head 1.1.15
Michele Locati 2020-12-16 12:05:21 +01:00 committed by GitHub
commit 83b3a13d20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 107 additions and 3 deletions

View File

@ -109,3 +109,22 @@ jobs:
with: with:
fetch-depth: 1 fetch-depth: 1
- run: docker run --rm --volume "$(pwd):/app" --workdir /app php:7.4-alpine ./scripts/test-installversion "${{ matrix.xdebug_version }}" - run: docker run --rm --volume "$(pwd):/app" --workdir /app php:7.4-alpine ./scripts/test-installversion "${{ matrix.xdebug_version }}"
test_composer:
name: Test installing composer
needs:
- check_syntax_data
- check_syntax_shell
- check_syntax_php
runs-on: ubuntu-latest
strategy:
matrix:
composer_version:
- ''
- '1'
- '2.0.1'
steps:
- name: Checkout
uses: actions/checkout@v2
- run: |
docker run --rm --volume "$(pwd):/app" --workdir /app php:7.4-alpine ./scripts/test-installcomposer "${{ matrix.composer_version }}"

View File

@ -46,6 +46,21 @@ For example:
install-php-extensions xdebug-2.9.7 install-php-extensions xdebug-2.9.7
``` ```
### Installing composer
You can also install [composer](https://getcomposer.org/), and you also can specify a major version of it, or a full version.
Examples:
```sh
# Install the latest version
install-php-extensions @composer
# Install the latest 1.x version
install-php-extensions @composer-1
# Install a specific version
install-php-extensions @composer-2.0.2
```
## Supported PHP extensions ## Supported PHP extensions
<!-- START OF EXTENSIONS TABLE --> <!-- START OF EXTENSIONS TABLE -->

View File

@ -107,6 +107,8 @@ processPHPMuduleArgument() {
if test -n "$processPHPMuduleArgument_version"; then if test -n "$processPHPMuduleArgument_version"; then
if printf '%s' "$PROCESSED_PHP_MODULE_ARGUMENT" | grep -Eq '^[a-zA-Z0-9_]+$'; then if printf '%s' "$PROCESSED_PHP_MODULE_ARGUMENT" | grep -Eq '^[a-zA-Z0-9_]+$'; then
eval PHP_WANTEDMODULEVERSION_$PROCESSED_PHP_MODULE_ARGUMENT="$processPHPMuduleArgument_version" eval PHP_WANTEDMODULEVERSION_$PROCESSED_PHP_MODULE_ARGUMENT="$processPHPMuduleArgument_version"
elif printf '%s' "$PROCESSED_PHP_MODULE_ARGUMENT" | grep -Eq '^@[a-zA-Z0-9_]+$'; then
eval PHP_WANTEDMODULEVERSION__${PROCESSED_PHP_MODULE_ARGUMENT#@}="$processPHPMuduleArgument_version"
else else
printf 'Unable to parse the following module name:\n%s\n' "$PROCESSED_PHP_MODULE_ARGUMENT" >&2 printf 'Unable to parse the following module name:\n%s\n' "$PROCESSED_PHP_MODULE_ARGUMENT" >&2
fi fi
@ -123,6 +125,8 @@ processPHPMuduleArgument() {
getWantedPHPModuleVersion() { getWantedPHPModuleVersion() {
if printf '%s' "$1" | grep -Eq '^[a-zA-Z0-9_]+$'; then if printf '%s' "$1" | grep -Eq '^[a-zA-Z0-9_]+$'; then
eval printf '%s' "\${PHP_WANTEDMODULEVERSION_$1:-}" eval printf '%s' "\${PHP_WANTEDMODULEVERSION_$1:-}"
elif printf '%s' "$1" | grep -Eq '^@[a-zA-Z0-9_]+$'; then
eval printf '%s' "\${PHP_WANTEDMODULEVERSION__${1#@}:-}"
fi fi
} }
@ -147,6 +151,9 @@ setPHPPreinstalledModules() {
;; ;;
esac esac
done done
if command -v composer >/dev/null; then
PHP_PREINSTALLED_MODULES="$PHP_PREINSTALLED_MODULES @composer"
fi
resetIFS resetIFS
PHP_PREINSTALLED_MODULES="${PHP_PREINSTALLED_MODULES# }" PHP_PREINSTALLED_MODULES="${PHP_PREINSTALLED_MODULES# }"
} }
@ -252,6 +259,12 @@ sortModulesToInstall() {
PHP_MODULES_TO_INSTALL="msgpack $PHP_MODULES_TO_INSTALL" PHP_MODULES_TO_INSTALL="msgpack $PHP_MODULES_TO_INSTALL"
PHP_MODULES_TO_INSTALL="${PHP_MODULES_TO_INSTALL% }" PHP_MODULES_TO_INSTALL="${PHP_MODULES_TO_INSTALL% }"
fi fi
# In any case, first of all, we need to install composer
if stringInList '@composer' "$PHP_MODULES_TO_INSTALL"; then
PHP_MODULES_TO_INSTALL="$(removeStringFromList '@composer' "$PHP_MODULES_TO_INSTALL")"
PHP_MODULES_TO_INSTALL="@composer $PHP_MODULES_TO_INSTALL"
PHP_MODULES_TO_INSTALL="${PHP_MODULES_TO_INSTALL% }"
fi
} }
# Get the required APT/APK packages for a specific PHP version and for the list of module handles # Get the required APT/APK packages for a specific PHP version and for the list of module handles
@ -273,7 +286,9 @@ buildRequiredPackageLists() {
esac esac
case "$DISTRO_VERSION" in case "$DISTRO_VERSION" in
alpine@*) alpine@*)
buildRequiredPackageLists_volatile="$PHPIZE_DEPS" if test $# -gt 1 || test "${1:-}" != '@composer'; then
buildRequiredPackageLists_volatile="$PHPIZE_DEPS"
fi
if test -z "$(apk info 2>/dev/null | grep -E ^libssl)"; then if test -z "$(apk info 2>/dev/null | grep -E ^libssl)"; then
buildRequiredPackageLists_libssl='libssl1.0' buildRequiredPackageLists_libssl='libssl1.0'
elif test -z "$(apk info 2>/dev/null | grep -E '^libressl.*-libtls')"; then elif test -z "$(apk info 2>/dev/null | grep -E '^libressl.*-libtls')"; then
@ -1045,6 +1060,24 @@ installOracleInstantClient() {
esac esac
} }
# Install Composer
installComposer() {
installComposer_version="$(getWantedPHPModuleVersion @composer)"
if test -z "$installComposer_version"; then
installComposer_fullname=composer
installComposer_flags=''
else
installComposer_fullname="$(printf 'composer v%s' "$installComposer_version")"
if printf '%s' "$installComposer_version" | grep -Eq '^[0-9]+$'; then
installComposer_flags="--$installComposer_version"
else
installComposer_flags="--version=$installComposer_version"
fi
fi
printf '### INSTALLING %s ###\n' "$installComposer_fullname"
curl -sSLf https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer $installComposer_flags
}
# Install a bundled PHP module given its handle # Install a bundled PHP module given its handle
# #
# Arguments: # Arguments:
@ -1736,6 +1769,9 @@ installPECLModule() {
configureInstaller() { configureInstaller() {
USE_PICKLE=0 USE_PICKLE=0
for PHP_MODULE_TO_INSTALL in $PHP_MODULES_TO_INSTALL; do for PHP_MODULE_TO_INSTALL in $PHP_MODULES_TO_INSTALL; do
if test "${PHP_MODULE_TO_INSTALL#@}" != "$PHP_MODULE_TO_INSTALL"; then
continue
fi
if ! stringInList "$PHP_MODULE_TO_INSTALL" "$BUNDLED_MODULES"; then if ! stringInList "$PHP_MODULE_TO_INSTALL" "$BUNDLED_MODULES"; then
if test $PHP_MAJMIN_VERSION -lt 800; then if test $PHP_MAJMIN_VERSION -lt 800; then
pecl channel-update pecl.php.net || true pecl channel-update pecl.php.net || true
@ -1902,9 +1938,13 @@ buildRequiredPackageLists $PHP_MODULES_TO_INSTALL
if test -n "$PACKAGES_PERSISTENT$PACKAGES_VOLATILE"; then if test -n "$PACKAGES_PERSISTENT$PACKAGES_VOLATILE"; then
installRequiredPackages installRequiredPackages
fi fi
setTargetTriplet if test "$PHP_MODULES_TO_INSTALL" != '@composer'; then
setTargetTriplet
fi
for PHP_MODULE_TO_INSTALL in $PHP_MODULES_TO_INSTALL; do for PHP_MODULE_TO_INSTALL in $PHP_MODULES_TO_INSTALL; do
if stringInList "$PHP_MODULE_TO_INSTALL" "$BUNDLED_MODULES"; then if test "$PHP_MODULE_TO_INSTALL" = '@composer'; then
installComposer
elif stringInList "$PHP_MODULE_TO_INSTALL" "$BUNDLED_MODULES"; then
installBundledModule "$PHP_MODULE_TO_INSTALL" installBundledModule "$PHP_MODULE_TO_INSTALL"
else else
MODULE_SOURCE='' MODULE_SOURCE=''

30
scripts/test-installcomposer Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh
# Let's set a sane environment
set -o errexit
set -o nounset
WANTED_VERSION="${1:-}"
INSTALLME=@composer
if test -n "$WANTED_VERSION"; then
INSTALLME="$INSTALLME-$1"
fi
./install-php-extensions "$INSTALLME"
INSTALLED_VERSION="$(composer --version | sed -E 's/^.*[Vv]ersion\s*(\S+).*$/\1/')"
if test -z "$WANTED_VERSION"; then
echo 'Installing the latest version worked'
elif printf '%s' "$WANTED_VERSION" | grep -Eq '^[0-9]+$'; then
if test "${INSTALLED_VERSION#$WANTED_VERSION.}" = "$INSTALLED_VERSION"; then
printf 'Installing major version %s DID NOT worked (we installed version %s)\n' "$WANTED_VERSION" "$INSTALLED_VERSION"
exit 1
fi
printf 'Installing major version %s worked (we installed version %s)\n' "$WANTED_VERSION" "$INSTALLED_VERSION"
else
if test "$INSTALLED_VERSION" != "$WANTED_VERSION"; then
printf 'Installing specific version %s DID NOT worked (we installed version %s)\n' "$WANTED_VERSION" "$INSTALLED_VERSION"
exit 1
fi
printf 'Installing specific version %s worked\n' "$INSTALLED_VERSION"
fi