diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 510c13a..d2abd60 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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" } diff --git a/dist/index.js b/dist/index.js index b3764b2..9e629cb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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 diff --git a/src/download-artifact.ts b/src/download-artifact.ts index a7946cf..a815803 100644 --- a/src/download-artifact.ts +++ b/src/download-artifact.ts @@ -10,20 +10,22 @@ async function run(): Promise { const path = core.getInput(Inputs.Path, {required: false}) const waitTimeoutStr = core.getInput(Inputs.WaitTimeout, {required: false}) - let runDownload: (action: () => T) => T + let runDownload: (action: () => T) => Promise // no retry allowed if (waitTimeoutStr == '') { - runDownload = (action: () => T) => action() + runDownload = async (action: () => T) => action() } else { const waitTimeoutSeconds = parseInt(waitTimeoutStr) - runDownload = (action: () => T) => { + runDownload = async (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 { 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 { 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}`