-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To make it easier to run tests locally with a specified version of PHP. This turns out to be a bit more complex than it sounds, as we need to be able to install the necessary version of PHP inside the container and we need to make sure the correct versions of Composer deps (particularly phpunit) are installed too. And then use those rather than whatever is in the monorepo install.
- Loading branch information
Showing
9 changed files
with
175 additions
and
35 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
projects/plugins/jetpack/changelog/try-docker-jetpack-phpunit-php-version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Significance: patch | ||
Type: other | ||
Comment: Update phpunit setup for `jetpack docker phpunit --php` | ||
|
||
|
5 changes: 5 additions & 0 deletions
5
projects/plugins/jetpack/changelog/try-docker-jetpack-phpunit-php-version#2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Significance: patch | ||
Type: other | ||
Comment: Remove unnecessary Patchwork include from test. Bootstrap should already have loaded it. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
|
||
set -eo pipefail | ||
|
||
source /etc/docker-args.sh | ||
|
||
VER=$1 | ||
if [[ "$1" == default ]]; then | ||
VER="$PHP_VERSION" | ||
elif [[ ! "$1" =~ ^[0-9]+\.[0-9]+$ ]]; then | ||
cat <<-EOF | ||
USAGE: $0 <version> | ||
<version> may be "default" or a two-part version number like "$PHP_VERSION". | ||
EOF | ||
exit 1 | ||
fi | ||
|
||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
# Determine packages to install. | ||
PKGS=( | ||
"libapache2-mod-php${VER}" | ||
"php${VER}" | ||
"php${VER}-bcmath" | ||
"php${VER}-cli" | ||
"php${VER}-curl" | ||
"php${VER}-intl" | ||
"php${VER}-ldap" | ||
"php${VER}-mbstring" | ||
"php${VER}-mysql" | ||
"php${VER}-opcache" | ||
"php${VER}-pgsql" | ||
"php${VER}-soap" | ||
"php${VER}-sqlite3" | ||
"php${VER}-xdebug" | ||
"php${VER}-xml" | ||
"php${VER}-xsl" | ||
"php${VER}-zip" | ||
) | ||
NO_RECOMMENDS_PKGS=( | ||
"php${VER}-apcu" | ||
"php${VER}-gd" | ||
"php${VER}-imagick" | ||
) | ||
|
||
# php-json is built in in 8.0+. | ||
if [[ "$VER" == [57].* ]]; then | ||
PKGS+=( "php${VER}-json" ) | ||
fi | ||
|
||
# Install selected packages. | ||
printf '\e[1m== Installing PHP %s ==\e[0m\n' "$VER" | ||
apt-get update -q | ||
apt-get install -qy "${PKGS[@]}" | ||
apt-get install -qy --no-install-recommends "${NO_RECOMMENDS_PKGS[@]}" | ||
|
||
# Enable our custom config for the new version. | ||
[[ -e "/etc/php/${VER}/mods-available/jetpack-wordpress.ini" ]] || ln -s /var/lib/jetpack-config/php.ini "/etc/php/${VER}/mods-available/jetpack-wordpress.ini" | ||
phpenmod -v "$VER" jetpack-wordpress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
set -eo pipefail | ||
|
||
VER="$1" | ||
DIR="/usr/local/src/phpunit-for-$VER/$( basename "$PWD" )" | ||
shift | ||
|
||
/var/scripts/ensure-php-version.sh "$VER" | ||
|
||
printf '\n\e[1m== Installing Composer deps for PHP %s externally ==\e[0m\n' "$VER" | ||
mkdir -p "$DIR" | ||
jq --arg PWD "$PWD" --arg VER "$( "php$VER" -r 'printf( "%d.%d.%d", PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION );' )" ' | ||
{ | ||
config: { | ||
platform: { | ||
php: $VER, | ||
}, | ||
}, | ||
repositories: [ | ||
{ | ||
type: "path", | ||
url: ( $PWD + "/../../packages/*" ), | ||
options: { | ||
monorepo: true, | ||
}, | ||
} | ||
], | ||
"require-dev": .["require-dev"], | ||
} | ||
' composer.json > "$DIR/composer.json" | ||
composer --working-dir="$DIR" update | ||
|
||
printf '\n\e[1m== Uninstalling Composer dev deps from monorepo ==\e[0m\n' | ||
composer install --no-dev | ||
# The above may have created files owned by the in-docker user ID, which probably doesn't match the user ID on the host system. | ||
# Avoid confusing users later by changing the ownership of such files. | ||
if [[ $(stat -c %u .) -ne $EUID ]]; then | ||
find -P vendor jetpack_vendor -xdev -user "$EUID" -exec chown --reference=. -h {} + &>/dev/null || true | ||
fi | ||
|
||
echo | ||
printf '\e[30;43m ** Note contents of vendor/ have been changed! ** \e[0m\n' | ||
printf '\e[30;43m ** You may want to run `jetpack install` when done testing to fix it. ** \e[0m\n' | ||
|
||
printf '\n\e[1m== Running phpunit ==\e[0m\n' | ||
export DOCKER_PHPUNIT_BASE_DIR="$DIR" | ||
exec "php$VER" "$DIR/vendor/bin/phpunit" "$@" |