Make WordPress Core

Changeset 61507


Ignore:
Timestamp:
01/21/2026 05:23:44 PM (8 months ago)
Author:
youknowriad
Message:

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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/reusable-performance-report-v2.yml

    r61209 r61507  
    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
  • trunk/.github/workflows/reusable-performance.yml

    r61209 r61507  
    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
  • trunk/tests/performance/log-results.js

    r59582 r61507  
    1111 * External dependencies.
    1212 */
    13 const https = require( 'https' );
    1413const [ token, branch, hash, baseHash, date, host ] =
    1514        process.argv.slice( 2 );
     
    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         } );
     84const 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 } );
     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                );
    119105
    120 req.write( data );
    121 req.end();
     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} )();
Note: See TracChangeset for help on using the changeset viewer.