diff --git a/lib/upload-lib.js b/lib/upload-lib.js index d8f4639d9..a23f54c4b 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -70,11 +70,18 @@ async function uploadPayload(payload) { for (let attempt = 0; attempt <= backoffPeriods.length; attempt++) { const res = await client.put(url, payload); core.debug('response status: ' + res.message.statusCode); - if (res.message.statusCode === 202) { + const statusCode = res.message.statusCode; + if (statusCode === 202) { core.info("Successfully uploaded results"); return; } const requestID = res.message.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 + '): ' + await res.readBody()); + return; + } + // 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) + @@ -82,15 +89,14 @@ async function uploadPayload(payload) { await res.readBody()); // Sleep for the backoff period await new Promise(r => setTimeout(r, backoffPeriods[attempt] * 1000)); + continue; } - else if (res.message.statusCode === 500) { - // If the upload fails with 500 then we assume it is a temporary problem + else { + // If the upload fails with 5xx then we assume it is a temporary problem // with turbo-scan 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 + '): ' + await res.readBody()); - } - else { - core.setFailed('Upload failed (' + requestID + '): ' + await res.readBody()); + return; } } } diff --git a/src/upload-lib.ts b/src/upload-lib.ts index 1342ccfa8..d404b2685 100644 --- a/src/upload-lib.ts +++ b/src/upload-lib.ts @@ -68,13 +68,21 @@ async function uploadPayload(payload) { const res: http.HttpClientResponse = await client.put(url, payload); core.debug('response status: ' + res.message.statusCode); - if (res.message.statusCode === 202) { + const statusCode = res.message.statusCode; + if (statusCode === 202) { core.info("Successfully uploaded results"); return; } const requestID = res.message.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 + '): ' + await res.readBody()); + return; + } + + // 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) + @@ -82,15 +90,14 @@ async function uploadPayload(payload) { await res.readBody()); // Sleep for the backoff period await new Promise(r => setTimeout(r, backoffPeriods[attempt] * 1000)); + continue; - } else if (res.message.statusCode === 500) { - // If the upload fails with 500 then we assume it is a temporary problem + } else { + // If the upload fails with 5xx then we assume it is a temporary problem // with turbo-scan 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 + '): ' + await res.readBody()); - - } else { - core.setFailed('Upload failed (' + requestID + '): ' + await res.readBody()); + return; } } }