Skip to content

Commit

Permalink
Docker: Make WP unit test versions match installed WP version (#41934)
Browse files Browse the repository at this point in the history
* Add script to update core

* Replace update-core-unit-tests subcommand with update-core

* Update initial unit test checkout version

* Patch core update file

* Allow downgrade as well

* Add plugin to .gitignore

* Comment tweaks
  • Loading branch information
tbradsha authored Feb 21, 2025
1 parent 8d083c8 commit 6389b56
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 12 deletions.
20 changes: 10 additions & 10 deletions tools/cli/commands/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,8 @@ const buildExecCmd = argv => {
opts.push( '/var/scripts/uninstall.sh' );
} else if ( cmd === 'multisite-convert' ) {
opts.push( '/var/scripts/multisite-convert.sh' );
} else if ( cmd === 'update-core-unit-tests' ) {
opts.push(
'svn',
'up',
'/tmp/wordpress-develop/tests/phpunit/data/',
'/tmp/wordpress-develop/tests/phpunit/includes'
);
} else if ( cmd === 'update-core' ) {
opts.push( '/var/scripts/update-core.sh', argv.version );
} else if ( cmd === 'run-extras' ) {
opts.push( '/var/scripts/run-extras.sh' );
} else if ( cmd === 'link-plugin' ) {
Expand Down Expand Up @@ -767,9 +762,14 @@ export function dockerDefine( yargs ) {
handler: argv => execDockerCmdHandler( argv ),
} )
.command( {
command: 'update-core-unit-tests',
description: 'Pulls latest Core unit tests files from SVN',
builder: yargExec => defaultOpts( yargExec ),
command: 'update-core [version]',
description: 'Installs core files',
builder: yargExec =>
defaultOpts( yargExec ).positional( 'version', {
type: 'string',
description: 'Specify the version to install',
default: 'latest',
} ),
handler: argv => execDockerCmdHandler( argv ),
} )
.command( {
Expand Down
5 changes: 3 additions & 2 deletions tools/docker/bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ fi
if [ "$COMPOSE_PROJECT_NAME" == "jetpack_dev" ] ; then
# If we don't have the wordpress test helpers, download them
if [ ! -d /tmp/wordpress-develop/tests ]; then
CUR_WP_VERSION=$(wp --allow-root core version);
# Get latest WordPress unit-test helper files
svn co \
https://develop.svn.wordpress.org/trunk/tests/phpunit/data \
"https://develop.svn.wordpress.org/tags/$CUR_WP_VERSION/tests/phpunit/data" \
/tmp/wordpress-develop/tests/phpunit/data \
--trust-server-cert \
--non-interactive
svn co \
https://develop.svn.wordpress.org/trunk/tests/phpunit/includes \
"https://develop.svn.wordpress.org/tags/$CUR_WP_VERSION/tests/phpunit/includes" \
/tmp/wordpress-develop/tests/phpunit/includes \
--trust-server-cert \
--non-interactive
Expand Down
54 changes: 54 additions & 0 deletions tools/docker/bin/update-core.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
if [[ -z "$1" ]]; then
echo 'Usage: update-core.sh [<version>]'
exit 1
fi

TARGET_VERSION="$1"
INIT_CORE_VERSION=$(wp --allow-root core version)

if [[ "$TARGET_VERSION" == 'latest' ]]; then
TARGET_VERSION=$(wp --allow-root core check-update --field=version|tail -n1)
# We're already on the latest version.
if [[ "$TARGET_VERSION" == Success:* ]]; then
TARGET_VERSION=$INIT_CORE_VERSION
fi
fi

# WordPress versioning has no minor 0 version.
if [[ "$TARGET_VERSION" =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
TARGET_VERSION="${TARGET_VERSION%.0}"
fi

echo "Current version: $INIT_CORE_VERSION"
echo "Target version: $TARGET_VERSION"

# We could force-install, but for now just abort if we're already at our target.
if [[ "$TARGET_VERSION" != "$INIT_CORE_VERSION" ]]; then
echo "Updating WordPress core to $TARGET_VERSION..."
echo "Please be patient; this may take some time."

# Clean up old option if a previous update didn't complete. Otherwise one would get this:
# "Error: Another update is currently in progress."
wp --allow-root option get core_updater.lock &>/dev/null && wp --allow-root option delete core_updater.lock

wp --allow-root core update --version="$TARGET_VERSION" --force

# If these don't match now, it means something went wrong with the update.
if [[ "$TARGET_VERSION" != "$(wp --allow-root core version)" ]]; then
echo "WordPress update to $TARGET_VERSION failed!"
exit 1
fi

# Update database.
echo 'Updating core database.'
wp --allow-root core update-db
fi

# Update core unit tests.
echo 'Updating core unit tests...'
svn -q switch "https://develop.svn.wordpress.org/tags/$TARGET_VERSION/tests/phpunit/data" /tmp/wordpress-develop/tests/phpunit/data && svn -q switch "https://develop.svn.wordpress.org/tags/$TARGET_VERSION/tests/phpunit/includes" /tmp/wordpress-develop/tests/phpunit/includes || {
echo 'Failed to update WordPress unit tests!'
}

echo "Successfully updated WordPress from $INIT_CORE_VERSION to $TARGET_VERSION."
1 change: 1 addition & 0 deletions tools/docker/mu-plugins/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
!.gitignore
!debug.php
!avoid-plugin-deletion.php
!bypass_circular_refs_during_core_update.php
!fix-monorepo-plugin_url.php
!jetpack-debug-helper-loader.php
!/jetpack-debug-helper
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Plugin Name: Bypass Circular Refs During Core Update
* Description: Some of our packages have circular refs for testing purposes, which makes the core upgrader choke. This removes the problematic call to `_upgrade_422_remove_genericons()`.
* Version: 1.0
* Author: Automattic
* Author URI: https://automattic.com/
* Text Domain: jetpack
*
* @package automattic/jetpack
*/

/**
* Remove problematic call to `_upgrade_422_remove_genericons()` from `wp-admin/includes/update-core.php`. That call
* recursively searches all directories for genericons files, which results in a circular reference loop for some
* of our projects.
*
* Unfortunately there's no direct filter in the upgrade routine, but it happens to call `wp_opcache_invalidate()` just
* before requiring the file, which has a filter we're able to hijack.
*
* @param boolean $will_invalidate Whether to invalidate the file.
* @param string $filepath Path to file to invalidate.
*
* @return true
*/
function jetpack_bypass_circular_refs_during_core_update( $will_invalidate, $filepath ) {
if ( $filepath === ABSPATH . 'wp-admin/includes/update-core.php' ) {
$file_contents = file_get_contents( $filepath );
$file_contents = str_replace( '_upgrade_422_remove_genericons();', '// _upgrade_422_remove_genericons();', $file_contents );
file_put_contents( $filepath, $file_contents );
}
return true;
}
add_filter( 'wp_opcache_invalidate_file', 'jetpack_bypass_circular_refs_during_core_update', 10, 2 );

0 comments on commit 6389b56

Please sign in to comment.