Php: Auto configure if a three part version is not provided (#406)
* Php: Auto configure if a three part version is not provided * fix test * update checks * Bump version
This commit is contained in:
parent
24b33c5f79
commit
7a3a9c5fca
5 changed files with 78 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"id": "php",
|
||||
"version": "1.0.11",
|
||||
"version": "1.1.0",
|
||||
"name": "PHP",
|
||||
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/php",
|
||||
"options": {
|
||||
|
@ -8,7 +8,9 @@
|
|||
"type": "string",
|
||||
"proposals": [
|
||||
"latest",
|
||||
"8.0.16"
|
||||
"8",
|
||||
"8.2",
|
||||
"8.2.0"
|
||||
],
|
||||
"default": "latest",
|
||||
"description": "Select or enter a PHP version"
|
||||
|
|
|
@ -84,15 +84,41 @@ check_packages() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Figure out correct version of PHP
|
||||
# Figure out correct version of a three part version number is not passed
|
||||
find_version_from_git_tags() {
|
||||
local repository="https://github.com/php/php-src"
|
||||
local separator="."
|
||||
local escaped_separator=${separator//./\\.}
|
||||
local last_part="${escaped_separator}[0-9]+"
|
||||
local regex="\\K[0-9]+${escaped_separator}[0-9]+${last_part}$"
|
||||
local version_list="$(git ls-remote --tags ${repository} | grep -oP "${regex}" | tr -d ' ' | tr "${separator}" "." | sort -rV)"
|
||||
PHP_VERSION="$(echo "${version_list}" | head -n 1)"
|
||||
local variable_name=$1
|
||||
local requested_version=${!variable_name}
|
||||
if [ "${requested_version}" = "none" ]; then return; fi
|
||||
local repository=$2
|
||||
local prefix=${3:-"tags/v"}
|
||||
local separator=${4:-"."}
|
||||
local last_part_optional=${5:-"false"}
|
||||
echo "${!variable_name}"
|
||||
echo "$(echo "${requested_version}" | grep -o "." | wc -l)"
|
||||
if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then
|
||||
local escaped_separator=${separator//./\\.}
|
||||
local last_part
|
||||
if [ "${last_part_optional}" = "true" ]; then
|
||||
last_part="(${escaped_separator}[0-9]+)?"
|
||||
else
|
||||
last_part="${escaped_separator}[0-9]+"
|
||||
fi
|
||||
local regex="${prefix}\\K[0-9]+${escaped_separator}[0-9]+${last_part}$"
|
||||
local version_list="$(git ls-remote --tags ${repository} | grep -oP "${regex}" | tr -d ' ' | tr "${separator}" "." | sort -rV)"
|
||||
if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "current" ] || [ "${requested_version}" = "lts" ]; then
|
||||
declare -g ${variable_name}="$(echo "${version_list}" | head -n 1)"
|
||||
else
|
||||
set +e
|
||||
declare -g ${variable_name}="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")"
|
||||
set -e
|
||||
fi
|
||||
fi
|
||||
echo "${!variable_name}"
|
||||
if [ -z "${!variable_name}" ] || ! echo "${version_list}" | grep "^${!variable_name//./\\.}$" > /dev/null 2>&1; then
|
||||
echo -e "Invalid ${variable_name} value: ${requested_version}\nValid values:\n${version_list}" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "${variable_name}=${!variable_name}"
|
||||
}
|
||||
|
||||
# Install PHP Composer
|
||||
|
@ -131,12 +157,6 @@ check_packages $RUNTIME_DEPS $PHP_DEPS $PHPIZE_DEPS
|
|||
|
||||
install_php() {
|
||||
PHP_VERSION="$1"
|
||||
|
||||
# Fetch latest version of PHP if needed
|
||||
if [ "${PHP_VERSION}" = "latest" ] || [ "${PHP_VERSION}" = "lts" ]; then
|
||||
find_version_from_git_tags
|
||||
fi
|
||||
|
||||
PHP_INSTALL_DIR="${PHP_DIR}/${PHP_VERSION}"
|
||||
if [ -d "${PHP_INSTALL_DIR}" ]; then
|
||||
echo "(!) PHP version ${PHP_VERSION} already exists."
|
||||
|
@ -218,6 +238,7 @@ install_php() {
|
|||
updaterc "if [[ \"\${PATH}\" != *\"${CURRENT_DIR}\"* ]]; then export PATH=\"${CURRENT_DIR}/bin:\${PATH}\"; fi"
|
||||
}
|
||||
|
||||
find_version_from_git_tags PHP_VERSION https://github.com/php/php-src "tags/php-"
|
||||
install_php "${PHP_VERSION}"
|
||||
|
||||
# Additional php versions to be installed but not be set as default.
|
||||
|
|
11
test/php/install_php_8.sh
Normal file
11
test/php/install_php_8.sh
Normal file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Optional: Import test library
|
||||
source dev-container-features-test-lib
|
||||
|
||||
check "php-version-8-is-installed" bash -c "php --version | grep '8.'"
|
||||
|
||||
# Report result
|
||||
reportResults
|
11
test/php/install_php_8_2.sh
Normal file
11
test/php/install_php_8_2.sh
Normal file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Optional: Import test library
|
||||
source dev-container-features-test-lib
|
||||
|
||||
check "php-version-8.2-is-installed" bash -c "php --version | grep '8.2'"
|
||||
|
||||
# Report result
|
||||
reportResults
|
|
@ -7,5 +7,21 @@
|
|||
"additionalVersions": "8.0.17,8.0.3"
|
||||
}
|
||||
}
|
||||
},
|
||||
"install_php_8": {
|
||||
"image": "ubuntu:focal",
|
||||
"features": {
|
||||
"php": {
|
||||
"version": "8"
|
||||
}
|
||||
}
|
||||
},
|
||||
"install_php_8_2": {
|
||||
"image": "ubuntu:focal",
|
||||
"features": {
|
||||
"php": {
|
||||
"version": "8.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue