11import fs from 'fs/promises'
2- import * as stream from 'stream'
3- import { createWriteStream } from 'fs'
4- import * as path from 'path'
52import * as github from '@actions/github'
63import * as core from '@actions/core'
74import * as httpClient from '@actions/http-client'
@@ -47,11 +44,6 @@ async function streamExtract(url: string, directory: string): Promise<void> {
4744 await streamExtractExternal ( url , directory )
4845 return
4946 } catch ( error ) {
50- if ( error . message . includes ( 'Malformed extraction path' ) ) {
51- throw new Error (
52- `Artifact download failed with unretryable error: ${ error . message } `
53- )
54- }
5547 retryCount ++
5648 core . debug (
5749 `Failed to download artifact after ${ retryCount } retries due to ${ error . message } . Retrying in 5 seconds...`
@@ -86,8 +78,6 @@ export async function streamExtractExternal(
8678 }
8779 const timer = setTimeout ( timerFn , timeout )
8880
89- const createdDirectories = new Set < string > ( )
90- createdDirectories . add ( directory )
9181 response . message
9282 . on ( 'data' , ( ) => {
9383 timer . refresh ( )
@@ -99,46 +89,8 @@ export async function streamExtractExternal(
9989 clearTimeout ( timer )
10090 reject ( error )
10191 } )
102- . pipe ( unzip . Parse ( ) )
103- . pipe (
104- new stream . Transform ( {
105- objectMode : true ,
106- transform : async ( entry , _ , callback ) => {
107- const fullPath = path . normalize ( path . join ( directory , entry . path ) )
108- if ( ! directory . endsWith ( path . sep ) ) {
109- directory += path . sep
110- }
111- if ( ! fullPath . startsWith ( directory ) ) {
112- reject ( new Error ( `Malformed extraction path: ${ fullPath } ` ) )
113- }
114-
115- if ( entry . type === 'Directory' ) {
116- if ( ! createdDirectories . has ( fullPath ) ) {
117- createdDirectories . add ( fullPath )
118- await resolveOrCreateDirectory ( fullPath ) . then ( ( ) => {
119- entry . autodrain ( )
120- callback ( )
121- } )
122- } else {
123- entry . autodrain ( )
124- callback ( )
125- }
126- } else {
127- core . info ( `Extracting artifact entry: ${ fullPath } ` )
128- if ( ! createdDirectories . has ( path . dirname ( fullPath ) ) ) {
129- createdDirectories . add ( path . dirname ( fullPath ) )
130- await resolveOrCreateDirectory ( path . dirname ( fullPath ) )
131- }
132-
133- const writeStream = createWriteStream ( fullPath )
134- writeStream . on ( 'finish' , callback )
135- writeStream . on ( 'error' , reject )
136- entry . pipe ( writeStream )
137- }
138- }
139- } )
140- )
141- . on ( 'finish' , async ( ) => {
92+ . pipe ( unzip . Extract ( { path : directory } ) )
93+ . on ( 'close' , ( ) => {
14294 clearTimeout ( timer )
14395 resolve ( )
14496 } )
0 commit comments