From 9dea373bba6cf394ffc1a74b7129ffdd68034e5c Mon Sep 17 00:00:00 2001 From: bethanyj28 Date: Thu, 22 Feb 2024 20:29:42 -0500 Subject: [PATCH] wait for upload to finish --- .../src/internal/download/download-artifact.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/artifact/src/internal/download/download-artifact.ts b/packages/artifact/src/internal/download/download-artifact.ts index a06dcf28..9d337043 100644 --- a/packages/artifact/src/internal/download/download-artifact.ts +++ b/packages/artifact/src/internal/download/download-artifact.ts @@ -80,6 +80,7 @@ export async function streamExtractExternal( } const timer = setTimeout(timerFn, timeout) + const promises: Promise[] = [] response.message .on('data', () => { timer.refresh() @@ -95,11 +96,18 @@ export async function streamExtractExternal( .on('entry', (entry: unzip.Entry) => { const fullPath = path.normalize(path.join(directory, entry.path)) core.debug(`Extracting artifact entry: ${fullPath}`) - entry.pipe(createWriteStream(fullPath)) + const writeStream = createWriteStream(fullPath) + promises.push(new Promise((resolve, reject) => { + writeStream.on('finish', () => resolve()) + writeStream.on('error', reject) + })) + entry.pipe(writeStream) }) .on('end', () => { clearTimeout(timer) - resolve() + Promise.all(promises) + .then(() => resolve()) + .catch(error => reject(error)) }) .on('error', (error: Error) => { reject(error)