Performance: Log the performance metrics to codevitals
This commit is contained in:
parent
81c19c0e39
commit
743b26d498
|
@ -51,3 +51,11 @@ jobs:
|
||||||
with:
|
with:
|
||||||
name: performance-results
|
name: performance-results
|
||||||
path: ${{ env.WP_ARTIFACTS_PATH }}/*.performance-results*.json
|
path: ${{ env.WP_ARTIFACTS_PATH }}/*.performance-results*.json
|
||||||
|
|
||||||
|
- name: Publish performance results
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
env:
|
||||||
|
CODEVITALS_PROJECT_TOKEN: ${{ secrets.CODEVITALS_PROJECT_TOKEN }}
|
||||||
|
run: |
|
||||||
|
COMMITTED_AT=$(git show -s $GITHUB_SHA --format="%cI")
|
||||||
|
cd tools/compare-perf && pnpm run log $CODEVITALS_PROJECT_TOKEN trunk $GITHUB_SHA 2f6ca66e00b3666b2567877ae67cbfb5b6ce171a $COMMITTED_AT
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
const fs = require( 'fs' );
|
||||||
|
const path = require( 'path' );
|
||||||
|
const https = require( 'https' );
|
||||||
|
const [ token, branch, hash, baseHash, timestamp ] = process.argv.slice( 2 );
|
||||||
|
|
||||||
|
const resultsFiles = [
|
||||||
|
{
|
||||||
|
file: 'editor.performance-results.json',
|
||||||
|
metricsPrefix: 'editor',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const performanceResults = resultsFiles.map( ( { file } ) =>
|
||||||
|
JSON.parse(
|
||||||
|
fs.readFileSync(
|
||||||
|
path.join( process.env.WP_ARTIFACTS_PATH, file ),
|
||||||
|
'utf8'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
const data = new TextEncoder().encode(
|
||||||
|
JSON.stringify( {
|
||||||
|
branch,
|
||||||
|
hash,
|
||||||
|
baseHash,
|
||||||
|
timestamp,
|
||||||
|
metrics: resultsFiles.reduce( ( result, { metricsPrefix }, index ) => {
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
...Object.fromEntries(
|
||||||
|
Object.entries(
|
||||||
|
performanceResults[ index ][ hash ] ?? {}
|
||||||
|
).map( ( [ key, value ] ) => [
|
||||||
|
metricsPrefix + key,
|
||||||
|
value,
|
||||||
|
] )
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}, {} ),
|
||||||
|
baseMetrics: resultsFiles.reduce(
|
||||||
|
( result, { metricsPrefix }, index ) => {
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
...Object.fromEntries(
|
||||||
|
Object.entries(
|
||||||
|
performanceResults[ index ][ baseHash ] ?? {}
|
||||||
|
).map( ( [ key, value ] ) => [
|
||||||
|
metricsPrefix + key,
|
||||||
|
value,
|
||||||
|
] )
|
||||||
|
),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
),
|
||||||
|
} )
|
||||||
|
);
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
hostname: 'codevitals.run',
|
||||||
|
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 );
|
||||||
|
} );
|
||||||
|
|
||||||
|
req.write( data );
|
||||||
|
req.end();
|
|
@ -7,7 +7,8 @@
|
||||||
"license": "GPLv2",
|
"license": "GPLv2",
|
||||||
"repository": "woocommerce/woocommerce",
|
"repository": "woocommerce/woocommerce",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compare": "node index.js"
|
"compare": "node index.js",
|
||||||
|
"log": "node log-to-codevitals.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@wordpress/env": "^8.13.0",
|
"@wordpress/env": "^8.13.0",
|
||||||
|
|
Loading…
Reference in New Issue