diff --git a/packages/artifact/package-lock.json b/packages/artifact/package-lock.json index 9710156d..0b29125e 100644 --- a/packages/artifact/package-lock.json +++ b/packages/artifact/package-lock.json @@ -19,6 +19,7 @@ "@octokit/request-error": "^5.0.0", "@protobuf-ts/plugin": "^2.2.3-alpha.1", "archiver": "^5.3.1", + "async": "^3.2.5", "crypto": "^1.0.1", "jwt-decode": "^3.1.2", "twirp-ts": "^2.5.0", diff --git a/packages/artifact/package.json b/packages/artifact/package.json index 166438f4..7796e926 100644 --- a/packages/artifact/package.json +++ b/packages/artifact/package.json @@ -50,6 +50,7 @@ "@octokit/request-error": "^5.0.0", "@protobuf-ts/plugin": "^2.2.3-alpha.1", "archiver": "^5.3.1", + "async": "^3.2.5", "crypto": "^1.0.1", "jwt-decode": "^3.1.2", "twirp-ts": "^2.5.0", @@ -64,4 +65,4 @@ "typedoc-plugin-markdown": "^3.17.1", "typescript": "^5.2.2" } -} \ No newline at end of file +} diff --git a/packages/artifact/src/internal/upload/zip.ts b/packages/artifact/src/internal/upload/zip.ts index 364f8f7d..7d6340e1 100644 --- a/packages/artifact/src/internal/upload/zip.ts +++ b/packages/artifact/src/internal/upload/zip.ts @@ -1,4 +1,5 @@ import * as stream from 'stream' +import * as async from 'async' import * as ZipStream from 'zip-stream' import * as core from '@actions/core' import {createReadStream} from 'fs' @@ -39,29 +40,22 @@ export async function createZipUploadStream( zip.on('finish', zipFinishCallback) zip.on('end', zipEndCallback) - - // for (const file of uploadSpecification) { - const fileUploadPromesses = uploadSpecification.map(async file => { - return new Promise((resolve, reject) => { - if (file.sourcePath !== null) { - // Add a normal file to the zip - zip.entry( - createReadStream(file.sourcePath), - {name: file.destinationPath}, - function (err, entry) { - core.debug(`Entry is: ${entry}`) - if (err) reject(err) - else resolve(entry) - } - ) - } else { - zip.entry(null, {name: file.destinationPath}, function (err, entry) { + async.forEachOf(uploadSpecification, async file => { + if (file.sourcePath !== null) { + zip.entry( + createReadStream(file.sourcePath), + {name: file.destinationPath}, + function (err, entry) { core.debug(`Entry is: ${entry}`) - if (err) reject(err) - resolve(entry) - }) - } - }) + if (err) throw err + } + ) + } else { + zip.entry(null, {name: file.destinationPath}, function (err, entry) { + core.debug(`Entry is: ${entry}`) + if (err) throw err + }) + } }) const bufferSize = getUploadChunkSize() @@ -72,9 +66,9 @@ export async function createZipUploadStream( core.debug( `Zip read high watermark value ${zipUploadStream.readableHighWaterMark}` ) - await Promise.all(fileUploadPromesses) - zip.finalize() + // zip.pipe(zipUploadStream) + zip.finalize() return zipUploadStream }