Skip to content

Commit

Permalink
prep build 03/30
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Mar 30, 2023
2 parents 30587ed + 0e2b16a commit e860df9
Show file tree
Hide file tree
Showing 276 changed files with 3,271 additions and 1,878 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
name: Run performance tests
runs-on: ubuntu-latest
if: ${{ github.repository == 'WordPress/gutenberg' }}
env:
WP_ARTIFACTS_PATH: ${{ github.workspace }}/artifacts

steps:
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
Expand All @@ -39,13 +41,6 @@ jobs:
if: github.event_name == 'pull_request'
run: ./bin/plugin/cli.js perf $GITHUB_SHA trunk --tests-branch $GITHUB_SHA

- name: Store performance measurements
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb # v3.1.1
with:
name: perf-test-results
path: ./__test-results/*.json

- name: Compare performance with current WordPress Core and previous Gutenberg versions
if: github.event_name == 'release'
env:
Expand Down Expand Up @@ -80,6 +75,13 @@ jobs:
run: |
./bin/plugin/cli.js perf $(echo $BRANCHES | tr ',' ' ') --tests-branch $GITHUB_SHA --wp-version "$WP_VERSION"
- name: Archive performance results
if: success()
uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb # v3.1.1
with:
name: performance-results
path: ${{ env.WP_ARTIFACTS_PATH }}/*.performance-results.json

- name: Publish performance results
if: github.event_name == 'push'
env:
Expand All @@ -90,8 +92,8 @@ jobs:
- name: Archive debug artifacts (screenshots, HTML snapshots)
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
if: always()
if: failure()
with:
name: failures-artifacts
path: ./__test-results/artifacts
path: ${{ env.WP_ARTIFACTS_PATH }}
if-no-files-found: ignore
2 changes: 1 addition & 1 deletion .github/workflows/stale-issue-gardening.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

steps:
- name: Update issues
uses: actions/stale@6f05e4244c9a0b2ed3401882b05d701dd0a7289b # v7.0.0
uses: actions/stale@1160a2240286f5da8ec72b1c0816ce2481aabf84 # v8.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: ${{ matrix.message }}
Expand Down
11 changes: 7 additions & 4 deletions bin/log-performance-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ const [ token, branch, hash, baseHash, timestamp ] = process.argv.slice( 2 );

const resultsFiles = [
{
file: 'post-editor-performance-results.json',
file: 'post-editor.performance-results.json',
metricsPrefix: '',
},
{
file: 'front-end-block-theme-performance-results.json',
file: 'front-end-block-theme.performance-results.json',
metricsPrefix: 'block-theme-',
},
{
file: 'front-end-classic-theme-performance-results.json',
file: 'front-end-classic-theme.performance-results.json',
metricsPrefix: 'classic-theme-',
},
];

const performanceResults = resultsFiles.map( ( { file } ) =>
JSON.parse(
fs.readFileSync( path.join( __dirname, '../' + file ), 'utf8' )
fs.readFileSync(
path.join( process.env.WP_ARTIFACTS_PATH, file ),
'utf8'
)
)
);

Expand Down
113 changes: 66 additions & 47 deletions bin/plugin/commands/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const {
} = require( '../lib/utils' );
const config = require( '../config' );

const ARTIFACTS_PATH =
process.env.WP_ARTIFACTS_PATH || path.join( process.cwd(), 'artifacts' );

/**
* @typedef WPPerformanceCommandOptions
*
Expand Down Expand Up @@ -193,38 +196,22 @@ function curateResults( testSuite, results ) {
* @return {Promise<WPPerformanceResults>} Performance results for the branch.
*/
async function runTestSuite( testSuite, performanceTestDirectory, runKey ) {
try {
await runShellScript(
`npm run test:performance -- packages/e2e-tests/specs/performance/${ testSuite }.test.js`,
performanceTestDirectory
);
} catch ( error ) {
fs.mkdirSync( './__test-results/artifacts', { recursive: true } );
const artifactsFolder = path.join(
performanceTestDirectory,
'artifacts/'
);
await runShellScript(
'cp -Rv ' + artifactsFolder + ' ' + './__test-results/artifacts/'
);

throw error;
}
const resultsFilename = `${ runKey }.performance-results.json`;

const resultsFile = path.join(
await runShellScript(
`npm run test:performance -- ${ testSuite }`,
performanceTestDirectory,
`packages/e2e-tests/specs/performance/${ testSuite }.test.results.json`
);
fs.mkdirSync( './__test-results', { recursive: true } );
fs.copyFileSync( resultsFile, `./__test-results/${ runKey }.results.json` );
const rawResults = await readJSONFile(
path.join(
performanceTestDirectory,
`packages/e2e-tests/specs/performance/${ testSuite }.test.results.json`
)
{
...process.env,
WP_ARTIFACTS_PATH: ARTIFACTS_PATH,
RESULTS_FILENAME: resultsFilename,
}
);

return curateResults( testSuite, rawResults );
return curateResults(
testSuite,
await readJSONFile( path.join( ARTIFACTS_PATH, resultsFilename ) )
);
}

/**
Expand Down Expand Up @@ -339,15 +326,41 @@ async function runPerformanceTests( branches, options ) {
buildPath
);

await runShellScript(
'cp ' +
path.resolve(
performanceTestDirectory,
'bin/plugin/utils/.wp-env.performance.json'
) +
' ' +
environmentDirectory +
'/.wp-env.json'
// Create the config file for the current env.
fs.writeFileSync(
path.join( environmentDirectory, '.wp-env.json' ),
JSON.stringify(
{
core: 'WordPress/WordPress',
plugins: [ path.join( environmentDirectory, 'plugin' ) ],
themes: [
path.join(
performanceTestDirectory,
'test/emptytheme'
),
'https://downloads.wordpress.org/theme/twentytwentyone.1.7.zip',
'https://downloads.wordpress.org/theme/twentytwentythree.1.0.zip',
],
env: {
tests: {
mappings: {
'wp-content/mu-plugins': path.join(
performanceTestDirectory,
'packages/e2e-tests/mu-plugins'
),
'wp-content/plugins/gutenberg-test-plugins':
path.join(
performanceTestDirectory,
'packages/e2e-tests/plugins'
),
},
},
},
},
null,
2
),
'utf8'
);

if ( options.wpVersion ) {
Expand Down Expand Up @@ -404,33 +417,39 @@ async function runPerformanceTests( branches, options ) {

/** @type {Record<string,Record<string, WPPerformanceResults>>} */
const results = {};
const wpEnvPath = path.join(
performanceTestDirectory,
'node_modules/.bin/wp-env'
);

for ( const testSuite of testSuites ) {
results[ testSuite ] = {};
/** @type {Array<Record<string, WPPerformanceResults>>} */
const rawResults = [];
// Alternate three times between branches.
for ( let i = 0; i < TEST_ROUNDS; i++ ) {
const roundInfo = `round ${ i + 1 } of ${ TEST_ROUNDS }`;
log( ` >> Suite: ${ testSuite } (${ roundInfo })` );
rawResults[ i ] = {};
for ( const branch of branches ) {
const sanitizedBranch = sanitizeBranchName( branch );
const runKey = `${ sanitizedBranch }_${ testSuite }_run-${ i }`;
const runKey = `${ testSuite }_${ sanitizedBranch }_run-${ i }`;
// @ts-ignore
const environmentDirectory = branchDirectories[ branch ];
log( ` >> Branch: ${ branch }, Suite: ${ testSuite }` );
log( ' >> Starting the environment.' );
log( ` >> Branch: ${ branch }` );
log( ' >> Starting the environment.' );
await runShellScript(
'../../tests/node_modules/.bin/wp-env start',
`${ wpEnvPath } start`,
environmentDirectory
);
log( ' >> Running the test.' );
log( ' >> Running the test.' );
rawResults[ i ][ branch ] = await runTestSuite(
testSuite,
performanceTestDirectory,
runKey
);
log( ' >> Stopping the environment' );
log( ' >> Stopping the environment' );
await runShellScript(
'../../tests/node_modules/.bin/wp-env stop',
`${ wpEnvPath } stop`,
environmentDirectory
);
}
Expand Down Expand Up @@ -493,9 +512,9 @@ async function runPerformanceTests( branches, options ) {
);
console.table( invertedResult );

const resultsFilename = testSuite + '-performance-results.json';
const resultsFilename = testSuite + '.performance-results.json';
fs.writeFileSync(
path.resolve( __dirname, '../../../', resultsFilename ),
path.join( ARTIFACTS_PATH, resultsFilename ),
JSON.stringify( results[ testSuite ], null, 2 )
);
}
Expand Down
17 changes: 0 additions & 17 deletions bin/plugin/utils/.wp-env.performance.json

This file was deleted.

Loading

0 comments on commit e860df9

Please sign in to comment.