1
0
Fork 0

updating event handlers

pull/1700/head
Vallie Joseph 2024-03-28 15:10:34 +00:00
parent e71ddb9e5a
commit 14eee6f54a
2 changed files with 63 additions and 37 deletions

View File

@ -109,10 +109,10 @@ export async function uploadArtifact(
`Artifact ${name}.zip successfully finalized. Artifact ID ${artifactId}` `Artifact ${name}.zip successfully finalized. Artifact ID ${artifactId}`
) )
// if (core.isDebug()) { // if (core.isDebug()) {
setTimeout(function () { // setTimeout(function () {
core.debug('Processes keeping upload stream running:') // core.debug('Processes keeping upload stream running:')
whyIsNodeRunning() // whyIsNodeRunning()
}, 500) // }, 500)
// } // }
// //

View File

@ -48,10 +48,37 @@ export async function createZipUploadStream(
// }) // })
// }) // })
// register callbacks for various events during the zip lifecycle // register callbacks for various events during the zip lifecycle
zip.on('error', zipErrorCallback) zip.on('error', err => {
zip.on('warning', zipWarningCallback) core.error('An error has occurred while creating the zip file for upload')
zip.on('finish', zipFinishCallback) core.info(err)
zip.on('end', zipEndCallback)
throw new Error(
'An error has occurred during zip creation for the artifact'
)
})
zip.on('warning', err => {
if (err.code === 'ENOENT') {
core.warning(
'ENOENT warning during artifact zip creation. No such file or directory'
)
core.info(err)
} else {
core.warning(
`A non-blocking warning has occurred during artifact zip creation: ${err.code}`
)
core.info(err)
}
})
// zip.on('error', zipErrorCallback)
// zip.on('warning', zipWarningCallback)
zip.on('finish', () => {
core.debug('Zip stream for upload has finished.')
})
zip.on('end', () => {
core.debug('Zip stream for upload has ended.')
})
// zip.on('end', zipEndCallback)
for (const file of uploadSpecification) { for (const file of uploadSpecification) {
if (file.sourcePath !== null) { if (file.sourcePath !== null) {
@ -65,18 +92,18 @@ export async function createZipUploadStream(
function (err, entry) { function (err, entry) {
core.debug(`Entry is: ${entry}`) core.debug(`Entry is: ${entry}`)
if (err) throw err if (err) throw err
// zip.finish()
} }
) )
} else { } else {
zip.entry(null, {name: file.destinationPath}, function (err, entry) { zip.entry(null, {name: file.destinationPath}, function (err, entry) {
core.debug(`Entry is: ${entry}`) core.debug(`Entry is: ${entry}`)
if (err) throw err if (err) throw err
// zip.finish()
}) })
// Add a directory to the zip // Add a directory to the zip
// zip.append('', {name: file.destinationPath}) // zip.append('', {name: file.destinationPath})
} }
zip.finish()
} }
const bufferSize = getUploadChunkSize() const bufferSize = getUploadChunkSize()
@ -90,38 +117,37 @@ export async function createZipUploadStream(
) )
zip.pipe(zipUploadStream) zip.pipe(zipUploadStream)
// zip.finalize()
zip.finalize() zip.finalize()
return zipUploadStream return zipUploadStream
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any // const zipErrorCallback = (error: any): void => {
const zipErrorCallback = (error: any): void => { // core.error('An error has occurred while creating the zip file for upload')
core.error('An error has occurred while creating the zip file for upload') // core.info(error)
core.info(error)
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 // // eslint-disable-next-line @typescript-eslint/no-explicit-any
const zipWarningCallback = (error: any): void => { // const zipWarningCallback = (error: any): void => {
if (error.code === 'ENOENT') { // if (error.code === 'ENOENT') {
core.warning( // core.warning(
'ENOENT warning during artifact zip creation. No such file or directory' // 'ENOENT warning during artifact zip creation. No such file or directory'
) // )
core.info(error) // core.info(error)
} else { // } else {
core.warning( // core.warning(
`A non-blocking warning has occurred during artifact zip creation: ${error.code}` // `A non-blocking warning has occurred during artifact zip creation: ${error.code}`
) // )
core.info(error) // core.info(error)
} // }
} // }
const zipFinishCallback = (): void => { // const zipFinishCallback = (): void => {
core.debug('Zip stream for upload has finished.') // core.debug('Zip stream for upload has finished.')
} // }
const zipEndCallback = (): void => { // const zipEndCallback = (): void => {
core.debug('Zip stream for upload has ended.') // core.debug('Zip stream for upload has ended.')
} // }