Skip to content

Commit

Permalink
Workflows: Performance: Run suite atop latest stable major WordPress …
Browse files Browse the repository at this point in the history
…version (#32244)

* Workflows: Performance: Honour `--wp-version` option

... by patching the temporary test environment's `.wp-env.json` config.

* Workflows: Performance: Test all branches atop latest stable WP version

* Address feedback w.r.t. performance.yml (props ockham)

* runPerformanceTests: Remap wpVersion to match ZIP path

* runPerformanceTests: Use Node API to patch .wp-env.json
  • Loading branch information
mcsf authored May 31, 2021
1 parent 9d382e4 commit dcbd481
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ jobs:
PREVIOUS_RELEASE_BRANCH="release/$((PREVIOUS_VERSION_BASE_10 / 10)).$((PREVIOUS_VERSION_BASE_10 % 10))"
WP_VERSION=$(awk -F ': ' '/^Tested up to/{print $2}' readme.txt)
IFS=. read -ra WP_VERSION_ARRAY <<< "$WP_VERSION"
WP_BRANCH="wp/${WP_VERSION_ARRAY[0]}.${WP_VERSION_ARRAY[1]}"
./bin/plugin/cli.js perf --ci "$WP_BRANCH" "$PREVIOUS_RELEASE_BRANCH" "$CURRENT_RELEASE_BRANCH" --tests-branch "$WP_BRANCH"
WP_MAJOR="${WP_VERSION_ARRAY[0]}.${WP_VERSION_ARRAY[1]}"
./bin/plugin/cli.js perf --ci "wp/$WP_MAJOR" "$PREVIOUS_RELEASE_BRANCH" "$CURRENT_RELEASE_BRANCH" --wp-version "$WP_MAJOR"
4 changes: 4 additions & 0 deletions bin/plugin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ program
'--tests-branch <branch>',
"Use this branch's performance test files"
)
.option(
'--wp-version <version>',
'Specify a WordPress version on which to test all branches'
)
.description(
'Runs performance tests on two separate branches and outputs the result'
)
Expand Down
29 changes: 29 additions & 0 deletions bin/plugin/commands/performance.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
const fs = require( 'fs' );
const path = require( 'path' );
const { pickBy, mapValues } = require( 'lodash' );

Expand All @@ -22,6 +23,7 @@ const config = require( '../config' );
*
* @property {boolean=} ci Run on CI.
* @property {string=} testsBranch The branch whose performance test files will be used for testing.
* @property {string=} wpVersion The WordPress version to be used as the base install for testing.
*/

/**
Expand Down Expand Up @@ -260,6 +262,33 @@ async function runPerformanceTests( branches, options ) {
);

log( '>> Starting the WordPress environment' );
if ( options.wpVersion ) {
// In order to match the topology of ZIP files at wp.org, remap .0
// patch versions to major versions:
//
// 5.7 -> 5.7 (unchanged)
// 5.7.0 -> 5.7 (changed)
// 5.7.2 -> 5.7.2 (unchanged)
const zipVersion = options.wpVersion.replace( /^(\d+\.\d+).0/, '$1' );
const zipUrl = `https://wordpress.org/wordpress-${ zipVersion }.zip`;

log( `Using WordPress version ${ zipVersion }` );

// Patch the environment's .wp-env.json config to use the specified WP
// version:
//
// {
// "core": "https://wordpress.org/wordpress-$VERSION.zip",
// ...
// }
const confPath = `${ environmentDirectory }/.wp-env.json`;
const conf = { ...readJSONFile( confPath ), core: zipUrl };
await fs.writeFileSync(
confPath,
JSON.stringify( conf, null, 2 ),
'utf8'
);
}
await runShellScript( 'npm run wp-env start', environmentDirectory );

const testSuites = [ 'post-editor', 'site-editor' ];
Expand Down

0 comments on commit dcbd481

Please sign in to comment.