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!
This commit is contained in:
21
.github/actions/github-release/main.js
vendored
21
.github/actions/github-release/main.js
vendored
@@ -4,6 +4,10 @@ const fs = require("fs");
|
|||||||
const github = require('@actions/github');
|
const github = require('@actions/github');
|
||||||
const glob = require('glob');
|
const glob = require('glob');
|
||||||
|
|
||||||
|
function sleep(milliseconds) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, milliseconds))
|
||||||
|
}
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
// Load all our inputs and env vars. Note that `getInput` reads from `INPUT_*`
|
// Load all our inputs and env vars. Note that `getInput` reads from `INPUT_*`
|
||||||
const files = core.getInput('files');
|
const files = core.getInput('files');
|
||||||
@@ -72,15 +76,28 @@ async function run() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Upload all the relevant assets for this release as just general blobs.
|
// Upload all the relevant assets for this release as just general blobs.
|
||||||
|
const retries = 10;
|
||||||
for (const file of glob.sync(files)) {
|
for (const file of glob.sync(files)) {
|
||||||
const size = fs.statSync(file).size;
|
const size = fs.statSync(file).size;
|
||||||
core.info(`upload ${file}`);
|
core.info(`upload ${file}`);
|
||||||
|
for (let i = 0; i < retries; i++) {
|
||||||
|
try {
|
||||||
await octokit.repos.uploadReleaseAsset({
|
await octokit.repos.uploadReleaseAsset({
|
||||||
file: fs.createReadStream(file),
|
data: fs.createReadStream(file),
|
||||||
headers: { 'content-length': size, 'content-type': 'application/octet-stream' },
|
headers: { 'content-length': size, 'content-type': 'application/octet-stream' },
|
||||||
name: path.basename(file),
|
name: path.basename(file),
|
||||||
url: release.data.upload_url,
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user