mirror of
git://develop.git.wordpress.org/
synced 2025-05-06 11:55:32 +02:00
This originally broke in [58165] and unfortunately went unnoticed for a while because the failing request to send the data did not cause the GitHub workflows to fail. This changeset resolves the underlying access problem, which was happening because reusable GitHub workflows do not automatically receive secrets from the calling workflow. More concretely, the relevant `CODEVITALS_PROJECT_TOKEN` was not being explicitly passed to the reusable workflow. The changeset also includes a change so that in the future a failing request would cause the workflow to fail, which ensures a similar problem further down the road wouldn't go unnoticed. Props joemcgill, flixos90, swissspidy, mukesh27, sergeybiryukov Fixes #62153. See #61213. git-svn-id: https://develop.svn.wordpress.org/trunk@59170 602fd350-edb4-49c9-b593-d223f7449a82
116 lines
2.7 KiB
JavaScript
116 lines
2.7 KiB
JavaScript
#!/usr/bin/env node
|
||
|
||
/*
|
||
* Get the test results and format them in the way required by the API.
|
||
*
|
||
* Contains some backward compatibility logic for the original test suite format,
|
||
* see #59900 for details.
|
||
*/
|
||
|
||
/**
|
||
* External dependencies.
|
||
*/
|
||
const https = require( 'https' );
|
||
const [ token, branch, hash, baseHash, timestamp, host ] =
|
||
process.argv.slice( 2 );
|
||
const { median, parseFile, accumulateValues } = require( './utils' );
|
||
|
||
const testSuiteMap = {
|
||
'Admin › Locale: en_US': 'admin',
|
||
'Admin › Locale: de_DE': 'admin-l10n',
|
||
'Front End › Theme: twentytwentyone, Locale: en_US': 'home-classic-theme',
|
||
'Front End › Theme: twentytwentyone, Locale: de_DE':
|
||
'home-classic-theme-l10n',
|
||
'Front End › Theme: twentytwentythree, Locale: en_US': 'home-block-theme',
|
||
'Front End › Theme: twentytwentythree, Locale: de_DE':
|
||
'home-block-theme-l10n',
|
||
};
|
||
|
||
/**
|
||
* @type {Array<{file: string, title: string, results: Record<string,number[]>[]}>}
|
||
*/
|
||
const afterStats = parseFile( 'performance-results.json' );
|
||
|
||
if ( ! afterStats.length ) {
|
||
console.error( 'No results file found' );
|
||
process.exit( 1 );
|
||
}
|
||
|
||
/**
|
||
* @type {Array<{file: string, title: string, results: Record<string,number[]>[]}>}
|
||
*/
|
||
const baseStats = parseFile( 'base-performance-results.json' );
|
||
|
||
if ( ! baseStats.length ) {
|
||
console.error( 'No base results file found' );
|
||
process.exit( 1 );
|
||
}
|
||
|
||
/**
|
||
* @type {Record<string, number>}
|
||
*/
|
||
const metrics = {};
|
||
|
||
/**
|
||
* @type {Record<string, number>}
|
||
*/
|
||
const baseMetrics = {};
|
||
|
||
for ( const { title, results } of afterStats ) {
|
||
const testSuiteName = testSuiteMap[ title ];
|
||
if ( ! testSuiteName ) {
|
||
continue;
|
||
}
|
||
|
||
const baseStat = baseStats.find( ( s ) => s.title === title );
|
||
|
||
const currResults = accumulateValues( results );
|
||
const baseResults = accumulateValues( baseStat.results );
|
||
|
||
for ( const [ metric, values ] of Object.entries( currResults ) ) {
|
||
metrics[ `${ testSuiteName }-${ metric }` ] = median( values );
|
||
}
|
||
|
||
for ( const [ metric, values ] of Object.entries( baseResults ) ) {
|
||
baseMetrics[ `${ testSuiteName }-${ metric }` ] = median( values );
|
||
}
|
||
}
|
||
|
||
const data = new TextEncoder().encode(
|
||
JSON.stringify( {
|
||
branch,
|
||
hash,
|
||
baseHash,
|
||
timestamp: parseInt( timestamp, 10 ),
|
||
metrics: metrics,
|
||
baseMetrics: baseMetrics,
|
||
} )
|
||
);
|
||
|
||
const options = {
|
||
hostname: host,
|
||
port: 443,
|
||
path: '/api/log?token=' + token,
|
||
method: 'POST',
|
||
headers: {
|
||
'Content-Type': 'application/json',
|
||
'Content-Length': data.length,
|
||
},
|
||
};
|
||
|
||
const req = https.request( options, ( res ) => {
|
||
console.log( `statusCode: ${ res.statusCode }` );
|
||
|
||
res.on( 'data', ( d ) => {
|
||
process.stdout.write( d );
|
||
} );
|
||
} );
|
||
|
||
req.on( 'error', ( error ) => {
|
||
console.error( error );
|
||
process.exit( 1 );
|
||
} );
|
||
|
||
req.write( data );
|
||
req.end();
|