Skip to content

Commit

Permalink
Retry uploading release assets if they fail (#982)
Browse files Browse the repository at this point in the history
This is an attempt to mitigate #978. I'm not really sure if it'll work,
but seems like it's worth trying!
  • Loading branch information
alexcrichton committed Feb 25, 2020
1 parent 7341e2f commit 5bed476
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions .github/actions/github-release/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit 5bed476

Please sign in to comment.