async function uploadPayload(payload) {
    core.info('Uploading results');
    // If in test mode we don't want to upload the results
    const testMode = process.env['TEST_MODE'] === 'true' || false;
    if (testMode) {
        return true;
    }
    const [owner, repo] = util.getRequiredEnvParam("GITHUB_REPOSITORY").split("/");
    // Make up to 4 attempts to upload, and sleep for these
    // number of seconds between each attempt.
    // We don't want to backoff too much to avoid wasting action
    // minutes, but just waiting a little bit could maybe help.
    const backoffPeriods = [1, 5, 15];
    for (let attempt = 0; attempt <= backoffPeriods.length; attempt++) {
        const response = await api.client.request("PUT /repos/:owner/:repo/code-scanning/analysis", ({
            owner: owner,
            repo: repo,
            data: payload,
        }));
        core.debug('response status: ' + response.status);
        const statusCode = response.status;
        if (statusCode === 202) {
            core.info("Successfully uploaded results");
            return true;
        }
        const requestID = response.headers["x-github-request-id"];
        // On any other status code that's not 5xx mark the upload as failed
        if (!statusCode || statusCode < 500 || statusCode >= 600) {
            core.setFailed('Upload failed (' + requestID + '): (' + statusCode + ') ' + JSON.stringify(response.data));
            return false;
        }
        // On a 5xx status code we may retry the request
        if (attempt < backoffPeriods.length) {
            // Log the failure as a warning but don't mark the action as failed yet
            core.warning('Upload attempt (' + (attempt + 1) + ' of ' + (backoffPeriods.length + 1) +
                ') failed (' + requestID + '). Retrying in ' + backoffPeriods[attempt] +
                ' seconds: (' + statusCode + ') ' + JSON.stringify(response.data));
            // Sleep for the backoff period
            await new Promise(r => setTimeout(r, backoffPeriods[attempt] * 1000));
            continue;
        }
        else {
            // If the upload fails with 5xx then we assume it is a temporary problem
            // and not an error that the user has caused or can fix.
            // We avoid marking the job as failed to avoid breaking CI workflows.
            core.error('Upload failed (' + requestID + '): (' + statusCode + ') ' + JSON.stringify(response.data));
            return false;
        }
    }
    return false;
}
// If the request fails then this will retry a small number of times.
If the request fails then this will retry a small number of times.
If the request fails then this will retry a small number of times .
async function uploadPayload(payload) {
    core.info('Uploading results');
    const testMode = process.env['TEST_MODE'] === 'true' || false;
    if (testMode) {
        return true;
    }
    const [owner, repo] = util.getRequiredEnvParam("GITHUB_REPOSITORY").split("/");
    const backoffPeriods = [1, 5, 15];
    for (let attempt = 0; attempt <= backoffPeriods.length; attempt++) {
        const response = await api.client.request("PUT /repos/:owner/:repo/code-scanning/analysis", ({
            owner: owner,
            repo: repo,
            data: payload,
        }));
        core.debug('response status: ' + response.status);
        const statusCode = response.status;
        if (statusCode === 202) {
            core.info("Successfully uploaded results");
            return true;
        }
        const requestID = response.headers["x-github-request-id"];
        if (!statusCode || statusCode < 500 || statusCode >= 600) {
            core.setFailed('Upload failed (' + requestID + '): (' + statusCode + ') ' + JSON.stringify(response.data));
            return false;
        }
        if (attempt < backoffPeriods.length) {
            core.warning('Upload attempt (' + (attempt + 1) + ' of ' + (backoffPeriods.length + 1) +
                ') failed (' + requestID + '). Retrying in ' + backoffPeriods[attempt] +
                ' seconds: (' + statusCode + ') ' + JSON.stringify(response.data));
            await new Promise(r => setTimeout(r, backoffPeriods[attempt] * 1000));
            continue;
        }
        else {
            core.error('Upload failed (' + requestID + '): (' + statusCode + ') ' + JSON.stringify(response.data));
            return false;
        }
    }
    return false;
}
async function uploadPayload ( payload ) { core . info ( 'Uploading results' ) ; const testMode = process . env [ 'TEST_MODE' ] === 'true' || false ; if ( testMode ) { return true ; } const [ owner , repo ] = util . getRequiredEnvParam ( "GITHUB_REPOSITORY" ) . split ( "/" ) ; const backoffPeriods = [ 1 , 5 , 15 ] ; for ( let attempt = 0 ; attempt <= backoffPeriods . length ; attempt ++ ) { const response = await api . client . request ( "PUT /repos/:owner/:repo/code-scanning/analysis" , ( { owner : owner , repo : repo , data : payload , } ) ) ; core . debug ( 'response status: ' + response . status ) ; const statusCode = response . status ; if ( statusCode === 202 ) { core . info ( "Successfully uploaded results" ) ; return true ; } const requestID = response . headers [ "x-github-request-id" ] ; if ( ! statusCode || statusCode < 500 || statusCode >= 600 ) { core . setFailed ( 'Upload failed (' + requestID + '): (' + statusCode + ') ' + JSON . stringify ( response . data ) ) ; return false ; } if ( attempt < backoffPeriods . length ) { core . warning ( 'Upload attempt (' + ( attempt + 1 ) + ' of ' + ( backoffPeriods . length + 1 ) + ') failed (' + requestID + '). Retrying in ' + backoffPeriods [ attempt ] + ' seconds: (' + statusCode + ') ' + JSON . stringify ( response . data ) ) ; await new Promise ( r => setTimeout ( r , backoffPeriods [ attempt ] * 1000 ) ) ; continue ; } else { core . error ( 'Upload failed (' + requestID + '): (' + statusCode + ') ' + JSON . stringify ( response . data ) ) ; return false ; } } return false ; }
If the request fails then this will retry a small number of times.
If the request fails then this will retry a small number of times .
// If in test mode we don't want to upload the results // Make up to 4 attempts to upload, and sleep for these // number of seconds between each attempt. // We don't want to backoff too much to avoid wasting action // minutes, but just waiting a little bit could maybe help. // On any other status code that's not 5xx mark the upload as failed // On a 5xx status code we may retry the request // Log the failure as a warning but don't mark the action as failed yet // Sleep for the backoff period // If the upload fails with 5xx then we assume it is a temporary problem // and not an error that the user has caused or can fix. // We avoid marking the job as failed to avoid breaking CI workflows.