Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev: Only one WordPress #41057

Open
wants to merge 25 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4cd499e
Initial commit of a centralized test install of WordPress
kraftbj Jan 13, 2025
97e5a9a
Use new test package for various projects
kraftbj Jan 16, 2025
965e2f4
Update Image CDN tests
kraftbj Jan 21, 2025
ef8c04f
try: shouldn't we select wp on plugins?
kraftbj Jan 21, 2025
6db0ea3
Use dedicated WorDBless for image-cdn
kraftbj Jan 22, 2025
e4cc3c9
Restore cleanup of wordbless
kraftbj Jan 22, 2025
6586305
Update changelog to only impacted packages
kraftbj Jan 22, 2025
5263cee
Restore bootstrap file
kraftbj Jan 22, 2025
16fdf6f
Always determine WP version
kraftbj Jan 23, 2025
88b805e
lock files
kraftbj Jan 23, 2025
448bf99
Revise test runner
kraftbj Jan 23, 2025
85082fa
Do not phan the test env
kraftbj Jan 23, 2025
9700109
Only exclude the wordpress dir from the test env
kraftbj Jan 23, 2025
a9cad95
Merge remote-tracking branch 'origin/trunk' into try/one-wordpress-to…
kraftbj Jan 24, 2025
6b12c53
apt-get clean not needed on ubuntu docker builds
kraftbj Jan 24, 2025
c845cf9
Merge remote-tracking branch 'origin/trunk' into try/one-wordpress-to…
kraftbj Jan 27, 2025
24624b7
Exclude test env vendor dir
kraftbj Jan 27, 2025
8b0e6dc
Add WorDBless as an independent requirement for Publicize tests
kraftbj Jan 27, 2025
215b875
Update the .phan config base to selectively add wordbless
kraftbj Jan 27, 2025
1f45183
Override the directories for the test-env package so it'll check dire…
kraftbj Jan 27, 2025
80f4a88
only include wordbless src to avoid the wordbless test files from bei…
kraftbj Jan 27, 2025
f1be2d1
try: totally exclude to prevent phpcs declaration warnings
kraftbj Jan 27, 2025
7aa668e
Add pcov ext for the docker env
kraftbj Jan 27, 2025
f4ce5bc
Add VideoPress to the concurrent test problem set. DRY it later
kraftbj Jan 27, 2025
36dff46
Revert "Add pcov ext for the docker env"
kraftbj Jan 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions .github/files/setup-wordpress-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ git clone --depth=1 --branch "$WORDPRESS_TAG" git://develop.git.wordpress.org/ "
# We need a built version of WordPress to test against, so download that into the src directory instead of what's in wordpress-develop.
rm -rf "/tmp/wordpress-$WP_BRANCH/src"
git clone --depth=1 --branch "$WORDPRESS_TAG" git://core.git.wordpress.org/ "/tmp/wordpress-$WP_BRANCH/src"

echo "::group::Setting up WordPress uploads directory"
mkdir -p "/tmp/wordpress-$WP_BRANCH/src/wp-content/uploads"
chmod -R 777 "/tmp/wordpress-$WP_BRANCH/src/wp-content/uploads"
echo "::endgroup::"

echo "::endgroup::"

if [[ -n "$GITHUB_ENV" ]]; then
Expand Down Expand Up @@ -105,19 +111,6 @@ for PLUGIN in projects/plugins/*/composer.json; do
fi
cd "$BASE"

# Upgrade/downgrade WorDBless if necessary.
if [[ ( "$WP_BRANCH" == 'trunk' || "$WP_BRANCH" == 'previous' ) && "$TEST_SCRIPT" == "test-php" ]]; then
VER=$(composer --format=json --working-dir="$DIR" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version')
if [[ -n "$VER" ]]; then
INSVER=$WORDPRESS_TAG
[[ "$WORDPRESS_TAG" == 'trunk' ]] && INSVER="dev-main as $VER"
echo "Supposed to run tests against WordPress $WORDPRESS_TAG, so setting roots/wordpress and roots/wordpress-no-content to \"$INSVER\""
# Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first.
rm -rf "$DIR/wordpress"
composer --working-dir="$DIR" require --dev roots/wordpress="$INSVER" roots/wordpress-no-content="$INSVER"
fi
fi

cp -r "$DIR" "/tmp/wordpress-$WP_BRANCH/src/wp-content/plugins/$NAME"
# Plugin dir for tests in WP >= 5.6-beta1
ln -s "/tmp/wordpress-$WP_BRANCH/src/wp-content/plugins/$NAME" "/tmp/wordpress-$WP_BRANCH/tests/phpunit/data/plugins/$NAME"
Expand Down
66 changes: 45 additions & 21 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@ jobs:
pnpm install
echo "::endgroup::"

# If we're going to be making WorDBless use WP "nightlies", remove the relevant package from Composer's cache to get the latest version.
if [[ "$WP_BRANCH" == 'trunk' && ( "$TEST_SCRIPT" == "test-php" || "$TEST_SCRIPT" == "test-coverage" ) ]]; then
echo "::group::Clear composer cache for roots/wordpress"
DIR=$(composer config cache-files-dir)
rm -rf "$DIR/roots/wordpress" "$DIR/roots/wordpress-no-content"
echo "::endgroup::"
fi

- name: Detect changed projects
id: changed
run: |
Expand All @@ -109,9 +101,53 @@ jobs:
echo "any-plugins=${ANY_PLUGINS}" >> "$GITHUB_OUTPUT"

- name: Select WordPress version
if: steps.changed.outputs.any-plugins != 'true' && matrix.wp != 'none'
if: matrix.wp != 'none'
run: .github/files/select-wordpress-tag.sh

- name: Composer Install
run: |
# If we're going to be making WorDBless use WP "nightlies", remove the relevant package from Composer's cache to get the latest version.
if [[ "$WP_BRANCH" == 'trunk' && ( "$TEST_SCRIPT" == "test-php" || "$TEST_SCRIPT" == "test-coverage" ) ]]; then
echo "::group::Clear composer cache for roots/wordpress"
DIR=$(composer config cache-files-dir)
rm -rf "$DIR/roots/wordpress" "$DIR/roots/wordpress-no-content"
echo "::endgroup::"
fi

echo "::group::Composer"
composer install --working-dir=tools/php-test-env

# Add WorDBless for image-cdn package tests since concurrency can nuke uploads that are in use.
if [[ "$TEST_SCRIPT" =~ ^test-(php|coverage)$ ]] && jq -e '.name == "automattic/jetpack-image-cdn"' projects/packages/image-cdn/composer.json >/dev/null; then
echo "Adding WordBless for image-cdn tests"
composer require --working-dir=projects/packages/image-cdn automattic/wordbless:^0.4.2 --dev
fi

# Add WorDBles for publicize package tests since concurrency can nuke uploads that are in use.
if [[ "$TEST_SCRIPT" =~ ^test-(php|coverage)$ ]] && jq -e '.name == "automattic/jetpack-publicize"' projects/packages/publicize/composer.json >/dev/null; then
echo "Adding WorDBless for publicize tests"
composer require --working-dir=projects/packages/publicize automattic/wordbless:^0.4.2 --dev
fi

# Add WorDBles for videopress package tests since concurrency can nuke uploads that are in use.
if [[ "$TEST_SCRIPT" =~ ^test-(php|coverage)$ ]] && jq -e '.name == "automattic/jetpack-videopress"' projects/packages/videopress/composer.json >/dev/null; then
echo "Adding WorDBless for videopress tests"
composer require --working-dir=projects/packages/videopress automattic/wordbless:^0.4.2 --dev
fi

if [[ ( "$TEST_SCRIPT" == "test-php" || "$TEST_SCRIPT" == "test-coverage" ) && ( "$WP_BRANCH" == 'trunk' || "$WP_BRANCH" == 'previous' ) ]]; then
VER=$(composer --format=json --working-dir="tools/php-test-env" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version')
if [[ -n "$VER" ]]; then
INSVER=$WORDPRESS_TAG
[[ "$WORDPRESS_TAG" == 'trunk' ]] && INSVER="dev-main as $VER"
echo "Supposed to run tests against WordPress $WORDPRESS_TAG, so setting roots/wordpress and roots/wordpress-no-content to \"$INSVER\""
# Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first.
rm -rf "tools/php-test-env/wordpress"
composer --working-dir="tools/php-test-env" require --dev "roots/wordpress:$INSVER" "roots/wordpress-no-content:$INSVER"
fi
fi
echo "::endgroup::"

- name: Setup WordPress environment for plugin tests
env:
API_TOKEN_GITHUB: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -195,18 +231,6 @@ jobs:
echo 'Platform reqs failed, running `composer update`'
composer --working-dir="$DIR" update
fi

if [[ "$WP_BRANCH" == 'trunk' || "$WP_BRANCH" == 'previous' ]]; then
VER=$(composer --format=json --working-dir="$DIR" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version')
if [[ -n "$VER" ]]; then
INSVER=$WORDPRESS_TAG
[[ "$WORDPRESS_TAG" == 'trunk' ]] && INSVER="dev-main as $VER"
echo "Supposed to run tests against WordPress $WORDPRESS_TAG, so setting roots/wordpress and roots/wordpress-no-content to \"$INSVER\""
# Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first.
rm -rf "$DIR/wordpress"
composer --working-dir="$DIR" require --dev roots/wordpress="$INSVER" roots/wordpress-no-content="$INSVER"
fi
fi
fi
fi

Expand Down
19 changes: 19 additions & 0 deletions .phan/config.base.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,25 @@ function make_phan_config( $dir, $options = array() ) {
$internal_stubs[ $stub ] = $stub_file_path;
}

// Check if test-environment is a dependency and add WorDBless if it is
$composer_json = $dir . '/composer.json';
if ( file_exists( $composer_json ) ) {
$composer_data = json_decode( file_get_contents( $composer_json ), true );
foreach ( array( 'require', 'require-dev' ) as $require_type ) {
if ( isset( $composer_data[ $require_type ]['automattic/jetpack-test-environment'] ) ) {
// Use absolute path to ensure WorDBless is found
$wordbless_path = dirname( __DIR__ ) . '/tools/php-test-env/vendor/automattic/wordbless';
if ( is_dir( $wordbless_path ) ) {
// Only include the src directory
$options['directory_list'][] = $wordbless_path . '/src';
// Exclude from analysis
$options['exclude_analysis_directory_list'][] = $wordbless_path;
}
break;
}
}
}

$config = array(
// Apparently this is only useful when upgrading from php 5, not for 7-to-8.
'backward_compatibility_checks' => false,
Expand Down
2 changes: 2 additions & 0 deletions .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
// Ignore stuff in various subdirs too.
'.*/node_modules/',
'tools/docker/',
'tools/php-test-env/wordpress/',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides this, you'll also need to exclude the tools/php-test-env/vendor from being analyzed by adding something like this into the $options array here.

		'exclude_analysis_directory_list' => array(
			'tools/php-test-env/vendor',
		),

(can't make it a suggestion because it has to go outside of where GH will allow comments, e.g. just after line 36 below).

'tools/php-test-env/vendor/',
// Don't load the stubs. (if we need to start loading _a_ stub for the "monorepo", do like `(?!filename\.php)` to exclude it from the exclusion.)
'.phan/stubs/',
),
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
],
"test-js": [
"cd tools/cli && pnpm test"
],
"post-install-cmd": [
"cd tools/php-test-env && composer install"
],
"post-update-cmd": [
"cd tools/php-test-env && composer update"
]
},
"scripts-descriptions": {
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: Update development platform only


6 changes: 2 additions & 4 deletions projects/packages/admin-ui/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "@dev",
"automattic/jetpack-logo": "@dev",
"automattic/wordbless": "^0.4.2"
"automattic/jetpack-test-environment": "@dev"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
Expand All @@ -29,9 +29,7 @@
],
"test-php": [
"@composer phpunit"
],
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy"
]
},
"repositories": [
{
Expand Down
3 changes: 2 additions & 1 deletion projects/packages/admin-ui/tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@

define( 'WP_DEBUG', true );

\WorDBless\Load::load();
// Initialize WordPress test environment
\Automattic\Jetpack\Test_Environment::init();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: Update development platform only


6 changes: 2 additions & 4 deletions projects/packages/backup-helper-script-manager/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"require-dev": {
"yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "@dev",
"automattic/wordbless": "^0.4.2"
"automattic/jetpack-test-environment": "@dev"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
Expand All @@ -28,9 +28,7 @@
],
"test-php": [
"@composer phpunit"
],
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy"
]
},
"repositories": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@

define( 'WP_DEBUG', true );

\WorDBless\Load::load();
// Initialize WordPress test environment
\Automattic\Jetpack\Test_Environment::init();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: Update development platform only


4 changes: 1 addition & 3 deletions projects/packages/backup/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"require-dev": {
"automattic/jetpack-changelogger": "@dev",
"yoast/phpunit-polyfills": "^1.1.1",
"automattic/wordbless": "^0.4.2"
"automattic/jetpack-test-environment": "@dev"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
Expand All @@ -43,8 +43,6 @@
"test-php": [
"@composer phpunit"
],
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"build-development": [
"pnpm run build"
],
Expand Down
3 changes: 2 additions & 1 deletion projects/packages/backup/tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@

define( 'WP_DEBUG', true );

\WorDBless\Load::load();
// Initialize WordPress test environment
\Automattic\Jetpack\Test_Environment::init();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: Update development platform only


6 changes: 2 additions & 4 deletions projects/packages/blaze/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"require-dev": {
"yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "@dev",
"automattic/wordbless": "^0.4.2"
"automattic/jetpack-test-environment": "@dev"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
Expand Down Expand Up @@ -45,9 +45,7 @@
"watch": [
"Composer\\Config::disableProcessTimeout",
"pnpm run watch"
],
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy"
]
},
"repositories": [
{
Expand Down
6 changes: 2 additions & 4 deletions projects/packages/blaze/tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@
*/
require_once __DIR__ . '/../../vendor/autoload.php';

/**
* Load WorDBless
*/
\WorDBless\Load::load();
// Initialize WordPress test environment
\Automattic\Jetpack\Test_Environment::init();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: Update development platform only


4 changes: 1 addition & 3 deletions projects/packages/blocks/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"automattic/jetpack-constants": "@dev"
},
"require-dev": {
"automattic/wordbless": "^0.4.2",
"automattic/jetpack-test-environment": "@dev",
"brain/monkey": "^2.6.2",
"yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "@dev"
Expand All @@ -25,8 +25,6 @@
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-php \"$COVERAGE_DIR/php.cov\""
],
Expand Down
6 changes: 2 additions & 4 deletions projects/packages/blocks/tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@
*/
require_once __DIR__ . '/../../vendor/autoload.php';

/**
* Load WorDBless
*/
\WorDBless\Load::load();
// Initialize WordPress test environment
\Automattic\Jetpack\Test_Environment::init();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: Update development platform only


Loading
Loading