Skip to content

Commit 8a5274e

Browse files
committed
Build: Fix redirect and error handling in performance results logging.
- Replace `https.request()` with native `fetch()` in `log-results.js`. - Drop www. from host name used to avoid redirects. Props mcsf. Fixes #64534. git-svn-id: https://develop.svn.wordpress.org/trunk@61507 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1943f9b commit 8a5274e

3 files changed

Lines changed: 37 additions & 38 deletions

File tree

.github/workflows/reusable-performance-report-v2.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ jobs:
104104
env:
105105
BASE_SHA: ${{ steps.base-sha.outputs.result }}
106106
CODEVITALS_PROJECT_TOKEN: ${{ secrets.CODEVITALS_PROJECT_TOKEN }}
107-
HOST_NAME: www.codevitals.run
107+
HOST_NAME: codevitals.run
108108
run: |
109109
if [ -z "$CODEVITALS_PROJECT_TOKEN" ]; then
110110
echo "Performance results could not be published. 'CODEVITALS_PROJECT_TOKEN' is not set"

.github/workflows/reusable-performance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ jobs:
347347
env:
348348
BASE_SHA: ${{ steps.base-sha.outputs.result }}
349349
CODEVITALS_PROJECT_TOKEN: ${{ secrets.CODEVITALS_PROJECT_TOKEN }}
350-
HOST_NAME: "www.codevitals.run"
350+
HOST_NAME: "codevitals.run"
351351
run: |
352352
if [ -z "$CODEVITALS_PROJECT_TOKEN" ]; then
353353
echo "Performance results could not be published. 'CODEVITALS_PROJECT_TOKEN' is not set"

tests/performance/log-results.js

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
/**
1111
* External dependencies.
1212
*/
13-
const https = require( 'https' );
1413
const [ token, branch, hash, baseHash, date, host ] =
1514
process.argv.slice( 2 );
1615
const { median, parseFile, accumulateValues } = require( './utils' );
@@ -82,40 +81,40 @@ for ( const { title, results } of afterStats ) {
8281
}
8382
}
8483

85-
const data = new TextEncoder().encode(
86-
JSON.stringify( {
87-
branch,
88-
hash,
89-
baseHash,
90-
timestamp: date,
91-
metrics: metrics,
92-
baseMetrics: baseMetrics,
93-
} )
94-
);
95-
96-
const options = {
97-
hostname: host,
98-
port: 443,
99-
path: '/api/log?token=' + token,
100-
method: 'POST',
101-
headers: {
102-
'Content-Type': 'application/json',
103-
'Content-Length': data.length,
104-
},
105-
};
106-
107-
const req = https.request( options, ( res ) => {
108-
console.log( `statusCode: ${ res.statusCode }` );
109-
110-
res.on( 'data', ( d ) => {
111-
process.stdout.write( d );
112-
} );
84+
const data = JSON.stringify( {
85+
branch,
86+
hash,
87+
baseHash,
88+
timestamp: date,
89+
metrics: metrics,
90+
baseMetrics: baseMetrics,
11391
} );
11492

115-
req.on( 'error', ( error ) => {
116-
console.error( error );
117-
process.exit( 1 );
118-
} );
119-
120-
req.write( data );
121-
req.end();
93+
( async () => {
94+
try {
95+
const response = await fetch(
96+
`https://${ host }/api/log?token=${ token }`,
97+
{
98+
method: 'POST',
99+
headers: {
100+
'Content-Type': 'application/json',
101+
},
102+
body: data,
103+
}
104+
);
105+
106+
console.log( `statusCode: ${ response.status }` );
107+
108+
const responseText = await response.text();
109+
if ( responseText ) {
110+
console.log( responseText );
111+
}
112+
113+
if ( ! response.ok ) {
114+
process.exit( 1 );
115+
}
116+
} catch ( error ) {
117+
console.error( error );
118+
process.exit( 1 );
119+
}
120+
} )();

0 commit comments

Comments
 (0)