From 3a4c7cf43252a7af8f7c68f0cb68790601901527 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 21 Jan 2026 11:38:11 +0100 Subject: [PATCH] Build: Fix redirect and error handling in performance results logging. Replace `https.request()` with native `fetch()` in `log-results.js` to properly handle HTTP redirects and non-2xx responses. Also removes `www.` from the CodeVitals host to avoid unnecessary redirects. Previously, the script would silently succeed even when the API returned a redirect (301/302) or error response, causing performance results to be lost without any indication in CI. Props youknowriad. Fixes #XXXXX. Co-Authored-By: Claude Opus 4.5 --- .../reusable-performance-report-v2.yml | 2 +- .github/workflows/reusable-performance.yml | 2 +- tests/performance/log-results.js | 71 +++++++++---------- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/.github/workflows/reusable-performance-report-v2.yml b/.github/workflows/reusable-performance-report-v2.yml index 988e60310d950..bc0174d083aa0 100644 --- a/.github/workflows/reusable-performance-report-v2.yml +++ b/.github/workflows/reusable-performance-report-v2.yml @@ -104,7 +104,7 @@ jobs: env: BASE_SHA: ${{ steps.base-sha.outputs.result }} CODEVITALS_PROJECT_TOKEN: ${{ secrets.CODEVITALS_PROJECT_TOKEN }} - HOST_NAME: www.codevitals.run + HOST_NAME: codevitals.run run: | if [ -z "$CODEVITALS_PROJECT_TOKEN" ]; then echo "Performance results could not be published. 'CODEVITALS_PROJECT_TOKEN' is not set" diff --git a/.github/workflows/reusable-performance.yml b/.github/workflows/reusable-performance.yml index f211b58890fc3..37941678978ab 100644 --- a/.github/workflows/reusable-performance.yml +++ b/.github/workflows/reusable-performance.yml @@ -347,7 +347,7 @@ jobs: env: BASE_SHA: ${{ steps.base-sha.outputs.result }} CODEVITALS_PROJECT_TOKEN: ${{ secrets.CODEVITALS_PROJECT_TOKEN }} - HOST_NAME: "www.codevitals.run" + HOST_NAME: "codevitals.run" run: | if [ -z "$CODEVITALS_PROJECT_TOKEN" ]; then echo "Performance results could not be published. 'CODEVITALS_PROJECT_TOKEN' is not set" diff --git a/tests/performance/log-results.js b/tests/performance/log-results.js index f8214b68d4eb3..a3ef4003fab6c 100644 --- a/tests/performance/log-results.js +++ b/tests/performance/log-results.js @@ -10,7 +10,6 @@ /** * External dependencies. */ -const https = require( 'https' ); const [ token, branch, hash, baseHash, date, host ] = process.argv.slice( 2 ); const { median, parseFile, accumulateValues } = require( './utils' ); @@ -82,40 +81,40 @@ for ( const { title, results } of afterStats ) { } } -const data = new TextEncoder().encode( - JSON.stringify( { - branch, - hash, - baseHash, - timestamp: date, - 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 ); - } ); +const data = JSON.stringify( { + branch, + hash, + baseHash, + timestamp: date, + metrics: metrics, + baseMetrics: baseMetrics, } ); -req.on( 'error', ( error ) => { - console.error( error ); - process.exit( 1 ); -} ); - -req.write( data ); -req.end(); +( async () => { + try { + const response = await fetch( + `https://${ host }/api/log?token=${ token }`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: data, + } + ); + + console.log( `statusCode: ${ response.status }` ); + + const responseText = await response.text(); + if ( responseText ) { + console.log( responseText ); + } + + if ( ! response.ok ) { + process.exit( 1 ); + } + } catch ( error ) { + console.error( error ); + process.exit( 1 ); + } +} )();