From 5bed47631a29342e2966ca07a7dbef5618bc2e6c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 25 Feb 2020 17:14:36 -0600 Subject: [PATCH] Retry uploading release assets if they fail (#982) This is an attempt to mitigate #978. I'm not really sure if it'll work, but seems like it's worth trying! --- .github/actions/github-release/main.js | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/.github/actions/github-release/main.js b/.github/actions/github-release/main.js index 6d2f80f946..cb59cf2840 100644 --- a/.github/actions/github-release/main.js +++ b/.github/actions/github-release/main.js @@ -4,6 +4,10 @@ const fs = require("fs"); const github = require('@actions/github'); const glob = require('glob'); +function sleep(milliseconds) { + return new Promise(resolve => setTimeout(resolve, milliseconds)) +} + async function run() { // Load all our inputs and env vars. Note that `getInput` reads from `INPUT_*` const files = core.getInput('files'); @@ -72,15 +76,28 @@ async function run() { }); // Upload all the relevant assets for this release as just general blobs. + const retries = 10; for (const file of glob.sync(files)) { const size = fs.statSync(file).size; core.info(`upload ${file}`); - await octokit.repos.uploadReleaseAsset({ - file: fs.createReadStream(file), - headers: { 'content-length': size, 'content-type': 'application/octet-stream' }, - name: path.basename(file), - url: release.data.upload_url, - }) + for (let i = 0; i < retries; i++) { + try { + await octokit.repos.uploadReleaseAsset({ + data: fs.createReadStream(file), + headers: { 'content-length': size, 'content-type': 'application/octet-stream' }, + name: path.basename(file), + url: release.data.upload_url, + }); + break; + } catch (e) { + if (i === retries - 1) + throw e; + console.log("ERROR: ", JSON.stringify(e, null, 2)); + console.log("ERROR: ", e.message); + console.log(e.stack); + console.log("RETRYING after 10s"); + await sleep(10000) + } } }