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 39 commits into
base: trunk
Choose a base branch
from
Open

Conversation

kraftbj
Copy link
Contributor

@kraftbj kraftbj commented Jan 14, 2025

For unit testing, we often use WorDBless, a variant of WordPress that does not require database setup. Except, we include it a lot so there are a lot of copies of WordPress within the repo when fully installed.

Before and after the changes proposed below (conducted in clean directories on my M1 with composer's cache cleared)

Before:
1st run of jetpack install --all: Between 2m 57s and 3m 17s
2nd run: 56s
Size: (du of monorepo with du of .git subtracted): 5.1 GB

After:
1st run: Between 1m 20s and 1m 52s
2nd run: 55s
Size: 2.7 GB

Proposed changes:

  • Remove inclusion of the WorDBless package in packages that did not use it for testing.
  • Add a new test-environment package to serve as the WorDBless loader for monorepo projects.
  • Replaced all inclusion of WorDBless package in individual packages with the new test-environment, updated bootstraps.
  • Added a new tools/php-test-env package that will install WorDBless once in that directory.
  • Updated monorepo root to install/update tools/php-test-env when itself is installed/updated (so jetpack install --all, -r will cover it.

In short, this changes the packages consumed by individual projects to use the internal test-environment. This ensure it is easy to modify all in the future and required little change to each individual package.

The test-environment loads a class that loads the test-php-env autoloader and loads WorDBless.

The test-php-env quasi-package does a singular install of WorDBless.

Other solution investigated was having the test-environment package directly require WorDBless, but that meant it would be re-installed every time test-environment was installed. No gain (at least) to install time, but it would have ended up with only one copy of WP.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

None yet.

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

  • jetpack install -r (at least) and jetpack install a package that uses worDBLess, like packages/admin-ui
  • jetpack test phh packages/admin-ui

Does it still run the test successfully?

@github-actions github-actions bot added [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] Social Issues about the Jetpack Social plugin [Plugin] Starter Plugin [Plugin] Super Cache A fast caching plugin for WordPress. [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. [Plugin] Wpcomsh [Tests] Includes Tests labels Jan 28, 2025
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

I gave it a try, it seems to test well. Let's give it a try!

I have a few remarks below:


I think you'll need to update packages/account-protection as well.


What do you think about updating the docs in docs/automated-testing.md and docs/monorepo.md to explain that setup?


You should be able to remove this now?

/vendor/automattic/wordbless/** production-exclude


I think you may have to update the generate command so folks do not set up WorDBless again in new packages:

if ( answers.wordbless ) {
composerJson.scripts[ 'post-install-cmd' ] = 'WorDBless\\Composer\\InstallDropin::copy';
composerJson.scripts[ 'post-update-cmd' ] = 'WorDBless\\Composer\\InstallDropin::copy';
composerJson[ 'require-dev' ][ 'automattic/wordbless' ] = 'dev-master';
composerJson.config = composerJson.config || {};
composerJson.config[ 'allow-plugins' ] = composerJson.config[ 'allow-plugins' ] || {};
composerJson.config[ 'allow-plugins' ][ 'roots/wordpress-core-installer' ] = true;
}

projects/packages/test-environment/README.md Outdated Show resolved Hide resolved
@kraftbj kraftbj requested a review from jeherve January 29, 2025 19:51
@kraftbj
Copy link
Contributor Author

kraftbj commented Jan 29, 2025

@jeherve I believe I resolved or explained all of the items in your feedback.

Copy link
Contributor

github-actions bot commented Jan 29, 2025

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/plugins/jetpack/extensions/store/membership-products/resolvers.js 56/106 (52.83%) 0.94% -1 💚
projects/packages/sync/src/modules/class-callables.php 45/177 (25.42%) 8.47% -15 💚

1 file are newly covered.

File Coverage
projects/packages/test-environment/src/class-test-environment.php 0/20 (0.00%) 💔

Full summary · PHP report · JS report

Comment on lines +146 to +149
// Only include the src directory
$options['directory_list'][] = $wordbless_path . '/src';
// Exclude from analysis
$options['exclude_analysis_directory_list'][] = $wordbless_path;
Copy link
Contributor

Choose a reason for hiding this comment

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

While this works, IMO it would be a little cleaner to have an array that works like $extra_stubs, which gets array_merged into the two config entries below, instead of changing the $options directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm down for fixing this in a follow-up. I'm itchy to get it in and iterate on it vs holding up the PR too much longer.

tools/docker/Dockerfile.monorepo Outdated Show resolved Hide resolved
.github/workflows/tests.yml Outdated Show resolved Hide resolved
kraftbj and others added 3 commits January 29, 2025 17:01
Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
…attic/jetpack into try/one-wordpress-to-rule-them-all
@kraftbj kraftbj requested a review from anomiex January 30, 2025 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Actions GitHub actions used to automate some of the work around releases and repository management Docker Docs [Feature] Contact Form [Feature] Google Analytics [Feature] Masterbar WordPress.com Toolbar and Dashboard customizations [Feature] Photon aka "Image CDN". Feature developed in the Image CDN package and shipped in multiple plugins [Feature] Publicize Now Jetpack Social, auto-sharing [Feature] Theme Tools [Package] Account Protection [Package] Admin Ui [Package] Backup Helper Script Manager [Package] Backup [Package] Blaze [Package] Blocks [Package] Connection [Package] Forms [Package] Google Analytics [Package] Image CDN [Package] Jetpack mu wpcom WordPress.com Features [Package] Licensing [Package] Masterbar [Package] My Jetpack [Package] Password Checker [Package] Plans [Package] Post List [Package] Protect Models [Package] Protect Status [Package] Publicize [Package] Scheduled Updates [Package] Schema [Package] Search Contains core Search functionality for Jetpack and Search plugins [Package] Stats Admin [Package] Stats Data [Package] Sync [Package] Test Environment [Package] Transport Helper [Package] VideoPress [Package] WAF [Plugin] Automattic For Agencies Client [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Beta For serving live branches and the beta versions. https://github.com/automattic/jetpack-beta [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Classic Theme Helper Plugin [Plugin] CRM Issues about the Jetpack CRM plugin [Plugin] Debug Helper Debug Tools plugin [Plugin] Inspect [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] Social Issues about the Jetpack Social plugin [Plugin] Starter Plugin [Plugin] Super Cache A fast caching plugin for WordPress. [Plugin] VaultPress [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. [Plugin] Wpcomsh RNA [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Tests] Includes Tests [Tools] Development CLI The tools/cli to assist during JP development. [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants