mirror of
https://github.com/actions/download-artifact.git
synced 2025-07-27 00:48:28 +02:00
fix: wait timeout implementation
This commit is contained in:
parent
7825bea020
commit
6e62761105
3 changed files with 19 additions and 22 deletions
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
|
@ -223,7 +223,7 @@ jobs:
|
|||
{
|
||||
Write-Error "Expected files do not exist"
|
||||
}
|
||||
if(!(Get-Content $fileA) -ceq "Lorem ipsum dolor sit amet"))
|
||||
if(!(Get-Content $fileA) -ceq "Lorem ipsum dolor sit amet")
|
||||
{
|
||||
Write-Error "File contents of downloaded artifacts are incorrect"
|
||||
}
|
||||
|
|
16
dist/index.js
vendored
16
dist/index.js
vendored
|
@ -7014,23 +7014,25 @@ function run() {
|
|||
let runDownload;
|
||||
// no retry allowed
|
||||
if (waitTimeoutStr == '') {
|
||||
runDownload = (action) => action();
|
||||
runDownload = (action) => __awaiter(this, void 0, void 0, function* () { return action(); });
|
||||
}
|
||||
else {
|
||||
const waitTimeoutSeconds = parseInt(waitTimeoutStr);
|
||||
runDownload = (action) => {
|
||||
runDownload = (action) => __awaiter(this, void 0, void 0, function* () {
|
||||
const waitUntil = new Date().getSeconds() + waitTimeoutSeconds;
|
||||
let lastError;
|
||||
do {
|
||||
try {
|
||||
return action();
|
||||
return yield action();
|
||||
}
|
||||
catch (e) {
|
||||
lastError = e;
|
||||
core.info('Waiting for the artifact to become available...');
|
||||
yield new Promise(f => setTimeout(f, 10000));
|
||||
}
|
||||
} 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
|
||||
|
@ -7046,7 +7048,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 runDownload(() => __awaiter(this, void 0, void 0, function* () { return yield artifactClient.downloadAllArtifacts(resolvedPath); }));
|
||||
const downloadResponse = yield runDownload(() => 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}`);
|
||||
|
@ -7058,9 +7060,7 @@ function run() {
|
|||
const downloadOptions = {
|
||||
createArtifactFolder: false
|
||||
};
|
||||
const downloadResponse = yield runDownload(() => __awaiter(this, void 0, void 0, function* () {
|
||||
return yield artifactClient.downloadArtifact(name, resolvedPath, downloadOptions);
|
||||
}));
|
||||
const downloadResponse = yield runDownload(() => 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
|
||||
|
|
|
@ -10,20 +10,22 @@ async function run(): Promise<void> {
|
|||
const path = core.getInput(Inputs.Path, {required: false})
|
||||
const waitTimeoutStr = core.getInput(Inputs.WaitTimeout, {required: false})
|
||||
|
||||
let runDownload: <T extends unknown>(action: () => T) => T
|
||||
let runDownload: <T extends unknown>(action: () => T) => Promise<T>
|
||||
// no retry allowed
|
||||
if (waitTimeoutStr == '') {
|
||||
runDownload = <T extends unknown>(action: () => T) => action()
|
||||
runDownload = async <T extends unknown>(action: () => T) => action()
|
||||
} else {
|
||||
const waitTimeoutSeconds = parseInt(waitTimeoutStr)
|
||||
runDownload = <T extends unknown>(action: () => T) => {
|
||||
runDownload = async <T extends unknown>(action: () => T) => {
|
||||
const waitUntil = new Date().getSeconds() + waitTimeoutSeconds
|
||||
let lastError
|
||||
do {
|
||||
try {
|
||||
return action()
|
||||
return await action()
|
||||
} catch (e) {
|
||||
lastError = e
|
||||
core.info('Waiting for the artifact to become available...')
|
||||
await new Promise(f => setTimeout(f, 10000))
|
||||
}
|
||||
} while (new Date().getSeconds() < waitUntil)
|
||||
throw Error('Timeout reached. Latest error: ' + lastError)
|
||||
|
@ -46,8 +48,8 @@ async function run(): Promise<void> {
|
|||
core.info(
|
||||
'Creating an extra directory for each artifact that is being downloaded'
|
||||
)
|
||||
const downloadResponse = await runDownload(
|
||||
async () => await artifactClient.downloadAllArtifacts(resolvedPath)
|
||||
const downloadResponse = await runDownload(() =>
|
||||
artifactClient.downloadAllArtifacts(resolvedPath)
|
||||
)
|
||||
core.info(`There were ${downloadResponse.length} artifacts downloaded`)
|
||||
for (const artifact of downloadResponse) {
|
||||
|
@ -61,13 +63,8 @@ async function run(): Promise<void> {
|
|||
const downloadOptions = {
|
||||
createArtifactFolder: false
|
||||
}
|
||||
const downloadResponse = await runDownload(
|
||||
async () =>
|
||||
await artifactClient.downloadArtifact(
|
||||
name,
|
||||
resolvedPath,
|
||||
downloadOptions
|
||||
)
|
||||
const downloadResponse = await runDownload(() =>
|
||||
artifactClient.downloadArtifact(name, resolvedPath, downloadOptions)
|
||||
)
|
||||
core.info(
|
||||
`Artifact ${downloadResponse.artifactName} was downloaded to ${downloadResponse.downloadPath}`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue