mirror of https://github.com/actions/toolkit
handle directories
parent
31c555afda
commit
a24b9c0184
|
@ -72,7 +72,7 @@ export async function streamExtractExternal(
|
||||||
|
|
||||||
const timeout = 30 * 1000 // 30 seconds
|
const timeout = 30 * 1000 // 30 seconds
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const timerFn = (): void => {
|
const timerFn = (): void => {
|
||||||
response.message.destroy(
|
response.message.destroy(
|
||||||
new Error(`Blob storage chunk did not respond in ${timeout}ms`)
|
new Error(`Blob storage chunk did not respond in ${timeout}ms`)
|
||||||
|
@ -93,23 +93,42 @@ export async function streamExtractExternal(
|
||||||
reject(error)
|
reject(error)
|
||||||
})
|
})
|
||||||
.pipe(unzip.Parse())
|
.pipe(unzip.Parse())
|
||||||
.on('entry', (entry: unzip.Entry) => {
|
.on('entry', async (entry: unzip.Entry) => {
|
||||||
const fullPath = path.normalize(path.join(directory, entry.path))
|
const fullPath = path.normalize(path.join(directory, entry.path))
|
||||||
core.debug(`Extracting artifact entry: ${fullPath}`)
|
core.debug(`Extracting artifact entry: ${fullPath}`)
|
||||||
|
if (entry.type === 'Directory') {
|
||||||
|
if (!(await exists(fullPath))) {
|
||||||
|
await fs.mkdir(fullPath, {recursive: true})
|
||||||
|
}
|
||||||
|
entry.autodrain()
|
||||||
|
} else {
|
||||||
|
if (!(await exists(path.dirname(fullPath)))) {
|
||||||
|
await fs.mkdir(path.dirname(fullPath), {recursive: true})
|
||||||
|
}
|
||||||
const writeStream = createWriteStream(fullPath)
|
const writeStream = createWriteStream(fullPath)
|
||||||
promises.push(
|
promises.push(
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
writeStream.on('finish', () => resolve())
|
writeStream.on('finish', () => {
|
||||||
|
console.log(`Finished writing ${fullPath}`)
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
writeStream.on('error', reject)
|
writeStream.on('error', reject)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
entry.pipe(writeStream)
|
entry.pipe(writeStream)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.on('end', () => {
|
.on('end', async () => {
|
||||||
|
console.log('All entries have been extracted')
|
||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
Promise.all(promises)
|
try {
|
||||||
.then(() => resolve())
|
console.log('Waiting for all write streams to finish')
|
||||||
.catch(error => reject(error))
|
await Promise.all(promises)
|
||||||
|
console.log('All write streams have finished')
|
||||||
|
resolve()
|
||||||
|
} catch (error) {
|
||||||
|
reject(error)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.on('error', (error: Error) => {
|
.on('error', (error: Error) => {
|
||||||
reject(error)
|
reject(error)
|
||||||
|
|
Loading…
Reference in New Issue