-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docker: Make WP unit test versions match installed WP version (#41934)
* 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
Showing
5 changed files
with
102 additions
and
12 deletions.
There are no files selected for viewing
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,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." |
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
34 changes: 34 additions & 0 deletions
34
tools/docker/mu-plugins/bypass_circular_refs_during_core_update.php
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,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 ); |