From 4e8c2213adc2932d73234c230a0faea4b38c9b34 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Tue, 18 Jan 2022 18:12:23 +0000 Subject: [PATCH] chore: Update dist --- dist/index.js | 57 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/dist/index.js b/dist/index.js index a777d91..0a57dbf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -168,7 +168,7 @@ module.exports = AWS.MediaLive; /***/ }), /***/ 104: -/***/ (function(module, __unusedexports, __webpack_require__) { +/***/ (function(__unusedmodule, exports, __webpack_require__) { const core = __webpack_require__(6470); const aws = __webpack_require__(9350); @@ -408,6 +408,29 @@ function getStsClient(region) { }); } +let defaultSleep = function (ms) { + return new Promise((resolve) => setTimeout(resolve, ms)); +}; +let sleep = defaultSleep; + +// retryAndBackoff retries with exponential backoff the promise if the error isRetryable upto maxRetries time. +const retryAndBackoff = async (fn, isRetryable, retries = 0, maxRetries = 12, base = 50) => { + try { + return await fn(); + } catch (err) { + if (!isRetryable) { + throw err; + } + // It's retryable, so sleep and retry. + await sleep(Math.random() * (Math.pow(2, retries) * base) ); + retries += 1; + if (retries === maxRetries) { + throw err; + } + return await retryAndBackoff(fn, isRetryable, retries, maxRetries, base); + } +} + async function run() { try { // Get inputs @@ -475,17 +498,18 @@ async function run() { // Get role credentials if configured to do so if (roleToAssume) { - const roleCredentials = await assumeRole({ - sourceAccountId, - region, - roleToAssume, - roleExternalId, - roleDurationSeconds, - roleSessionName, - roleSkipSessionTagging, - webIdentityTokenFile, - webIdentityToken - }); + const roleCredentials = await retryAndBackoff( + async () => { return await assumeRole({ + sourceAccountId, + region, + roleToAssume, + roleExternalId, + roleDurationSeconds, + roleSessionName, + roleSkipSessionTagging, + webIdentityTokenFile, + webIdentityToken + }) }, true); exportCredentials(roleCredentials); // We need to validate the credentials in 2 of our use-cases // First: self-hosted runners. If the GITHUB_ACTIONS environment variable @@ -509,7 +533,14 @@ async function run() { } } -module.exports = run; +exports.withSleep = function (s) { + sleep = s; +}; +exports.reset = function () { + sleep = defaultSleep; +}; + +exports.run = run /* istanbul ignore next */ if (require.main === require.cache[eval('__filename')]) {