1
0
Fork 0

add resolve all promises again

pull/1700/head
Vallie Joseph 2024-03-28 17:43:17 +00:00
parent fd88cbe6df
commit 66343faec4
1 changed files with 10 additions and 18 deletions

View File

@ -7,7 +7,6 @@ import {UploadZipSpecification} from './upload-zip-specification'
import {getUploadChunkSize} from '../shared/config' import {getUploadChunkSize} from '../shared/config'
export const DEFAULT_COMPRESSION_LEVEL = 6 export const DEFAULT_COMPRESSION_LEVEL = 6
let isRunning = false
// Custom stream transformer so we can set the highWaterMark property // Custom stream transformer so we can set the highWaterMark property
// See https://github.com/nodejs/node/issues/8855 // See https://github.com/nodejs/node/issues/8855
@ -28,10 +27,6 @@ export async function createZipUploadStream(
uploadSpecification: UploadZipSpecification[], uploadSpecification: UploadZipSpecification[],
compressionLevel: number = DEFAULT_COMPRESSION_LEVEL compressionLevel: number = DEFAULT_COMPRESSION_LEVEL
): Promise<ZipUploadStream> { ): Promise<ZipUploadStream> {
if (isRunning) {
throw new Error('The function is already running')
}
isRunning = true
core.debug( core.debug(
`Creating Artifact archive with compressionLevel: ${compressionLevel}` `Creating Artifact archive with compressionLevel: ${compressionLevel}`
) )
@ -45,27 +40,25 @@ export async function createZipUploadStream(
zip.on('finish', zipFinishCallback) zip.on('finish', zipFinishCallback)
zip.on('end', zipEndCallback) zip.on('end', zipEndCallback)
try { const uploadFilePromises = uploadSpecification.map(async file => {
await async.forEachOf(uploadSpecification, async file => { return new Promise((resolve, reject) => {
if (file.sourcePath !== null) { if (file.sourcePath !== null) {
zip.entry( zip.entry(
createReadStream(file.sourcePath), createReadStream(file.sourcePath),
{name: file.destinationPath}, {name: file.destinationPath},
function (err, entry) { (err, entry) => {
core.debug(`Entry is: ${entry}`) if (err) reject(err)
if (err) throw err resolve(entry)
} }
) )
} else { } else {
zip.entry(null, {name: file.destinationPath}, function (err, entry) { zip.entry(null, {name: file.destinationPath}, (err, entry) => {
core.debug(`Entry is: ${entry}`) if (err) reject(err)
if (err) throw err resolve(entry)
}) })
} }
}) })
} finally { })
isRunning = false
}
const bufferSize = getUploadChunkSize() const bufferSize = getUploadChunkSize()
const zipUploadStream = new ZipUploadStream(bufferSize) const zipUploadStream = new ZipUploadStream(bufferSize)
@ -75,7 +68,7 @@ export async function createZipUploadStream(
core.debug( core.debug(
`Zip read high watermark value ${zipUploadStream.readableHighWaterMark}` `Zip read high watermark value ${zipUploadStream.readableHighWaterMark}`
) )
await Promise.all(uploadFilePromises)
// zip.pipe(zipUploadStream) // zip.pipe(zipUploadStream)
zip.finalize() zip.finalize()
return zipUploadStream return zipUploadStream
@ -88,7 +81,6 @@ const zipErrorCallback = (error: any): void => {
throw new Error('An error has occurred during zip creation for the artifact') throw new Error('An error has occurred during zip creation for the artifact')
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const zipWarningCallback = (err: any): void => { const zipWarningCallback = (err: any): void => {
if (err.code === 'ENOENT') { if (err.code === 'ENOENT') {
core.warning( core.warning(