Fix CI Metrics job (#50214)

This commit is contained in:
Bart Kalisz 2024-08-06 11:23:04 +02:00 committed by GitHub
parent 328d944288
commit 52119dfcc9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 65 additions and 47 deletions

View File

@ -195,15 +195,6 @@ jobs:
path: ${{ env.ARTIFACTS_PATH }}/flaky-tests path: ${{ env.ARTIFACTS_PATH }}/flaky-tests
if-no-files-found: ignore if-no-files-found: ignore
- name: 'Archive metrics results'
if: ${{ success() && startsWith(matrix.name, 'Metrics') }} # this seems too fragile, we should update the reporting path and use the generic upload step above
uses: actions/upload-artifact@v4
env:
WP_ARTIFACTS_PATH: ${{ github.workspace }}/artifacts
with:
name: metrics-results
path: ${{ env.WP_ARTIFACTS_PATH }}/*.performance-results*.json
evaluate-project-jobs: evaluate-project-jobs:
# In order to add a required status check we need a consistent job that we can grab onto. # In order to add a required status check we need a consistent job that we can grab onto.
# Since we are dynamically generating a matrix for the project jobs, however, we can't # Since we are dynamically generating a matrix for the project jobs, however, we can't

View File

@ -7,25 +7,34 @@ if [[ -z "$GITHUB_EVENT_NAME" ]]; then
exit 1 exit 1
fi fi
echo "Installing dependencies"
pnpm install --filter="compare-perf"
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
echo "Comparing performance with trunk" echo "Comparing performance with trunk"
pnpm --filter="compare-perf" run compare perf $GITHUB_SHA trunk --tests-branch $GITHUB_SHA pnpm --filter="compare-perf" run compare perf $GITHUB_SHA trunk --tests-branch $GITHUB_SHA
elif [[ "$GITHUB_EVENT_NAME" == "push" ]]; then elif [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
echo "Comparing performance with base branch" echo "Comparing performance with base branch"
# The base hash used here need to be a commit that is compatible with the current WP version
# The current one is 19f3d0884617d7ecdcf37664f648a51e2987cada
# it needs to be updated every time it becomes unsupported by the current wp-env (WP version).
# It is used as a base comparison point to avoid fluctuation in the performance metrics.
WP_VERSION=$(awk -F ': ' '/^Tested up to/{print $2}' readme.txt) WP_VERSION=$(awk -F ': ' '/^Tested up to/{print $2}' readme.txt)
# Updating the WP version used for performance jobs means theres a high
# chance that the reference commit used for performance test stability
# becomes incompatible with the WP version. So, every time the "Tested up
# to" flag is updated in the readme.txt, we also have to update the
# reference commit below (BASE_SHA). The new reference needs to meet the
# following requirements:
# - Be compatible with the new WP version used in the “Tested up to” flag.
# - Be tracked on https://www.codevitals.run/project/woo for all existing
# metrics.
BASE_SHA=3d7d7f02017383937f1a4158d433d0e5d44b3dc9
echo "WP_VERSION: $WP_VERSION" echo "WP_VERSION: $WP_VERSION"
IFS=. read -ra WP_VERSION_ARRAY <<< "$WP_VERSION" IFS=. read -ra WP_VERSION_ARRAY <<< "$WP_VERSION"
WP_MAJOR="${WP_VERSION_ARRAY[0]}.${WP_VERSION_ARRAY[1]}" WP_MAJOR="${WP_VERSION_ARRAY[0]}.${WP_VERSION_ARRAY[1]}"
pnpm --filter="compare-perf" run compare perf $GITHUB_SHA 19f3d0884617d7ecdcf37664f648a51e2987cada --tests-branch $GITHUB_SHA --wp-version "$WP_MAJOR" pnpm --filter="compare-perf" run compare perf $GITHUB_SHA $BASE_SHA --tests-branch $GITHUB_SHA --wp-version "$WP_MAJOR"
echo "Publish results to CodeVitals" echo "Publish results to CodeVitals"
COMMITTED_AT=$(git show -s $GITHUB_SHA --format="%cI") COMMITTED_AT=$(git show -s $GITHUB_SHA --format="%cI")
pnpm --filter="compare-perf" run log $CODEVITALS_PROJECT_TOKEN trunk $GITHUB_SHA 19f3d0884617d7ecdcf37664f648a51e2987cada $COMMITTED_AT pnpm --filter="compare-perf" run log $CODEVITALS_PROJECT_TOKEN trunk $GITHUB_SHA $BASE_SHA $COMMITTED_AT
else else
echo "Unsupported event: $GITHUB_EVENT_NAME" echo "Unsupported event: $GITHUB_EVENT_NAME"
fi fi

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Fix Metrics CI job

View File

@ -529,8 +529,12 @@
".wp-env.json" ".wp-env.json"
], ],
"events": [ "events": [
"disabled" "push"
] ],
"report": {
"resultsBlobName": "core-metrics-report",
"resultsPath": "../../tools/compare-perf/artifacts/"
}
}, },
{ {
"name": "Blocks e2e tests", "name": "Blocks e2e tests",

View File

@ -27,17 +27,27 @@ async function isBlockProductEditorEnabled( page ) {
*/ */
async function toggleBlockProductEditor( action = 'enable', page ) { async function toggleBlockProductEditor( action = 'enable', page ) {
await page.goto( SETTINGS_URL ); await page.goto( SETTINGS_URL );
if ( action === 'disable' ) {
await page const enableProductEditor = page.locator(
.locator( '#woocommerce_feature_product_block_editor_enabled' ) '#woocommerce_feature_product_block_editor_enabled'
.uncheck(); );
} else { const isEnabled = await enableProductEditor.isChecked();
await page
.locator( '#woocommerce_feature_product_block_editor_enabled' ) if (
.check(); ( action === 'enable' && isEnabled ) ||
( action === 'disable' && ! isEnabled )
) {
// No need to toggle the setting.
return;
} }
if ( action === 'enable' ) {
await enableProductEditor.check();
} else if ( action === 'disable' ) {
await enableProductEditor.uncheck();
}
await page await page
.locator( '.submit' )
.getByRole( 'button', { .getByRole( 'button', {
name: 'Save changes', name: 'Save changes',
} ) } )

View File

@ -1,3 +1,6 @@
/**
* External dependencies
*/
import path from 'path'; import path from 'path';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import { defineConfig, devices } from '@playwright/test'; import { defineConfig, devices } from '@playwright/test';
@ -11,9 +14,7 @@ process.env.STORAGE_STATE_PATH ??= path.join(
process.env.WP_BASE_URL ??= 'http://localhost:8086'; process.env.WP_BASE_URL ??= 'http://localhost:8086';
const config = defineConfig( { const config = defineConfig( {
reporter: process.env.CI reporter: [ [ 'list' ], [ './config/performance-reporter.ts' ] ],
? './config/performance-reporter.ts'
: [ [ 'list' ], [ './config/performance-reporter.ts' ] ],
forbidOnly: !! process.env.CI, forbidOnly: !! process.env.CI,
fullyParallel: false, fullyParallel: false,
workers: 1, workers: 1,

View File

@ -146,7 +146,6 @@ test.describe( 'Editor Performance', () => {
await perfUtils.loadBlocksForLargePost(); await perfUtils.loadBlocksForLargePost();
await editor.insertBlock( { name: 'core/paragraph' } ); await editor.insertBlock( { name: 'core/paragraph' } );
draftId = await perfUtils.saveDraft(); draftId = await perfUtils.saveDraft();
console.log( draftId );
} ); } );
test( 'Run the test', async ( { admin, page, perfUtils, metrics } ) => { test( 'Run the test', async ( { admin, page, perfUtils, metrics } ) => {

View File

@ -30,10 +30,6 @@ test.describe( 'Product editor performance', () => {
}, },
} ); } );
test.beforeEach( async ( { page } ) => {
await toggleBlockProductEditor( 'enable', page );
} );
test.afterAll( async ( {}, testInfo ) => { test.afterAll( async ( {}, testInfo ) => {
const medians = {}; const medians = {};
Object.keys( results ).forEach( ( metric ) => { Object.keys( results ).forEach( ( metric ) => {
@ -45,6 +41,10 @@ test.describe( 'Product editor performance', () => {
} ); } );
} ); } );
test( 'Enable Product Editor', async ( { page } ) => {
await toggleBlockProductEditor( 'enable', page );
} );
test.describe( 'Loading', () => { test.describe( 'Loading', () => {
const samples = 2; const samples = 2;
const throwaway = 1; const throwaway = 1;

View File

@ -2,13 +2,13 @@ const path = require( 'path' );
const getPnpmPackage = ( sourceDir ) => { const getPnpmPackage = ( sourceDir ) => {
const packageJson = require( path.join( sourceDir, 'package.json' ) ); const packageJson = require( path.join( sourceDir, 'package.json' ) );
let pnpm_package = 'pnpm'; let pnpmPackage = 'pnpm';
if ( packageJson.engines.pnpm ) { if ( packageJson.engines.pnpm ) {
pnpm_package = `pnpm@${ packageJson.engines.pnpm }`; pnpmPackage = `pnpm@${ packageJson.engines.pnpm }`;
} }
return pnpm_package; return pnpmPackage;
}; };
const config = { const config = {
@ -16,18 +16,18 @@ const config = {
pluginPath: '/plugins/woocommerce', pluginPath: '/plugins/woocommerce',
testsPath: '/plugins/woocommerce/tests/metrics/specs', testsPath: '/plugins/woocommerce/tests/metrics/specs',
getSetupTestRunner: ( sourceDir ) => { getSetupTestRunner: ( sourceDir ) => {
const pnpm_package = getPnpmPackage( sourceDir ); const pnpmPackage = getPnpmPackage( sourceDir );
return `npm install -g ${ pnpm_package } && pnpm install --filter="@woocommerce/plugin-woocommerce" &> /dev/null && cd plugins/woocommerce && pnpm exec playwright install chromium`; return `npm install -g ${ pnpmPackage } && pnpm install --frozen-lockfile --filter="@woocommerce/plugin-woocommerce" &> /dev/null && cd plugins/woocommerce && pnpm exec playwright install chromium`;
}, },
getSetupCommand: ( sourceDir ) => { getSetupCommand: ( sourceDir ) => {
const pnpm_package = getPnpmPackage( sourceDir ); const pnpmPackage = getPnpmPackage( sourceDir );
return `npm install -g ${ pnpm_package } && pnpm install &> /dev/null && pnpm build &> /dev/null`; return `npm install -g ${ pnpmPackage } && pnpm install --frozen-lockfile &> /dev/null && pnpm build &> /dev/null`;
}, },
getTestCommand: ( sourceDir ) => { getTestCommand: ( sourceDir ) => {
const pnpm_package = getPnpmPackage( sourceDir ); const pnpmPackage = getPnpmPackage( sourceDir );
return `npm install -g ${ pnpm_package } && cd plugins/woocommerce && pnpm test:metrics`; return `npm install -g ${ pnpmPackage } && cd plugins/woocommerce && pnpm test:metrics`;
}, },
}; };