feat: implement waitTimeout

This commit is contained in:
Ivan Dlugos 2022-03-03 17:56:42 +01:00
parent 880511a8d8
commit 7825bea020
6 changed files with 135 additions and 18 deletions

29
dist/index.js vendored
View file

@ -6954,6 +6954,7 @@ var Inputs;
(function (Inputs) {
Inputs["Name"] = "name";
Inputs["Path"] = "path";
Inputs["WaitTimeout"] = "waitTimeout";
})(Inputs = exports.Inputs || (exports.Inputs = {}));
var Outputs;
(function (Outputs) {
@ -7009,6 +7010,28 @@ function run() {
try {
const name = core.getInput(constants_1.Inputs.Name, { required: false });
const path = core.getInput(constants_1.Inputs.Path, { required: false });
const waitTimeoutStr = core.getInput(constants_1.Inputs.WaitTimeout, { required: false });
let runDownload;
// no retry allowed
if (waitTimeoutStr == '') {
runDownload = (action) => action();
}
else {
const waitTimeoutSeconds = parseInt(waitTimeoutStr);
runDownload = (action) => {
const waitUntil = new Date().getSeconds() + waitTimeoutSeconds;
let lastError;
do {
try {
return action();
}
catch (e) {
lastError = e;
}
} while (new Date().getSeconds() < waitUntil);
throw Error('Timeout reached. Latest error: ' + lastError);
};
}
let resolvedPath;
// resolve tilde expansions, path.replace only replaces the first occurrence of a pattern
if (path.startsWith(`~`)) {
@ -7023,7 +7046,7 @@ function run() {
// download all artifacts
core.info('No artifact name specified, downloading all artifacts');
core.info('Creating an extra directory for each artifact that is being downloaded');
const downloadResponse = yield artifactClient.downloadAllArtifacts(resolvedPath);
const downloadResponse = yield runDownload(() => __awaiter(this, void 0, void 0, function* () { return yield artifactClient.downloadAllArtifacts(resolvedPath); }));
core.info(`There were ${downloadResponse.length} artifacts downloaded`);
for (const artifact of downloadResponse) {
core.info(`Artifact ${artifact.artifactName} was downloaded to ${artifact.downloadPath}`);
@ -7035,7 +7058,9 @@ function run() {
const downloadOptions = {
createArtifactFolder: false
};
const downloadResponse = yield artifactClient.downloadArtifact(name, resolvedPath, downloadOptions);
const downloadResponse = yield runDownload(() => __awaiter(this, void 0, void 0, function* () {
return yield artifactClient.downloadArtifact(name, resolvedPath, downloadOptions);
}));
core.info(`Artifact ${downloadResponse.artifactName} was downloaded to ${downloadResponse.downloadPath}`);
}
// output the directory that the artifact(s) was/were downloaded to