1
1
import * as core from "@actions/core"
2
2
import * as fs from "fs"
3
+ import * as path from "path"
3
4
import * as handlers from "typed-rest-client/Handlers"
4
5
import * as io from "@actions/io"
5
6
import * as thc from "typed-rest-client/HttpClient"
6
7
7
8
import { IReleaseDownloadSettings } from "../src/download-settings"
8
9
import { ReleaseDownloader } from "../src/release-downloader"
9
10
import nock from "nock"
11
+ import { extract } from "../src/unarchive"
10
12
11
13
let downloader : ReleaseDownloader
12
14
let httpClent : thc . HttpClient
@@ -61,6 +63,12 @@ beforeEach(() => {
61
63
. get ( "/repos/robinraju/probable-potato/releases/assets/66946550" )
62
64
. replyWithFile ( 200 , __dirname + "/resource/assets/lorem-ipsum.pdf" )
63
65
66
+ nock ( "https://api.github.com" , {
67
+ reqheaders : { accept : "application/octet-stream" }
68
+ } )
69
+ . get ( "/repos/robinraju/probable-potato/releases/assets/66946552" )
70
+ . replyWithFile ( 200 , __dirname + "/resource/assets/archive-example.zip" )
71
+
64
72
nock ( "https://api.github.com" , {
65
73
reqheaders : { accept : "application/octet-stream" }
66
74
} )
@@ -97,10 +105,11 @@ test("Download all files from public repo", async () => {
97
105
fileName : "*" ,
98
106
tarBall : false ,
99
107
zipBall : false ,
108
+ extractAssets : false ,
100
109
outFilePath : outputFilePath
101
110
}
102
111
const result = await downloader . download ( downloadSettings )
103
- expect ( result . length ) . toBe ( 6 )
112
+ expect ( result . length ) . toBe ( 7 )
104
113
} , 10000 )
105
114
106
115
test ( "Download single file from public repo" , async ( ) => {
@@ -112,6 +121,7 @@ test("Download single file from public repo", async () => {
112
121
fileName : "test-1.txt" ,
113
122
tarBall : false ,
114
123
zipBall : false ,
124
+ extractAssets : false ,
115
125
outFilePath : outputFilePath
116
126
}
117
127
const result = await downloader . download ( downloadSettings )
@@ -127,6 +137,7 @@ test("Fail loudly if given filename is not found in a release", async () => {
127
137
fileName : "missing-file.txt" ,
128
138
tarBall : false ,
129
139
zipBall : false ,
140
+ extractAssets : false ,
130
141
outFilePath : outputFilePath
131
142
}
132
143
const result = downloader . download ( downloadSettings )
@@ -144,6 +155,7 @@ test("Fail loudly if release is not identified", async () => {
144
155
fileName : "missing-file.txt" ,
145
156
tarBall : false ,
146
157
zipBall : false ,
158
+ extractAssets : false ,
147
159
outFilePath : outputFilePath
148
160
}
149
161
const result = downloader . download ( downloadSettings )
@@ -161,6 +173,7 @@ test("Download files with wildcard from public repo", async () => {
161
173
fileName : "test-*.txt" ,
162
174
tarBall : false ,
163
175
zipBall : false ,
176
+ extractAssets : false ,
164
177
outFilePath : outputFilePath
165
178
}
166
179
const result = await downloader . download ( downloadSettings )
@@ -176,6 +189,7 @@ test("Download single file with wildcard from public repo", async () => {
176
189
fileName : "3-*.txt" ,
177
190
tarBall : false ,
178
191
zipBall : false ,
192
+ extractAssets : false ,
179
193
outFilePath : outputFilePath
180
194
}
181
195
const result = await downloader . download ( downloadSettings )
@@ -191,6 +205,7 @@ test("Download multiple pdf files with wildcard filename", async () => {
191
205
fileName : "*.pdf" ,
192
206
tarBall : false ,
193
207
zipBall : false ,
208
+ extractAssets : false ,
194
209
outFilePath : outputFilePath
195
210
}
196
211
const result = await downloader . download ( downloadSettings )
@@ -206,6 +221,7 @@ test("Download a csv file with wildcard filename", async () => {
206
221
fileName : "*.csv" ,
207
222
tarBall : false ,
208
223
zipBall : false ,
224
+ extractAssets : false ,
209
225
outFilePath : outputFilePath
210
226
}
211
227
const result = await downloader . download ( downloadSettings )
@@ -223,6 +239,7 @@ test("Download file from Github Enterprise server", async () => {
223
239
fileName : "test-1.txt" ,
224
240
tarBall : false ,
225
241
zipBall : false ,
242
+ extractAssets : false ,
226
243
outFilePath : outputFilePath
227
244
}
228
245
const result = await downloader . download ( downloadSettings )
@@ -238,8 +255,34 @@ test("Download file from release identified by ID", async () => {
238
255
fileName : "test-2.txt" ,
239
256
tarBall : false ,
240
257
zipBall : false ,
258
+ extractAssets : false ,
241
259
outFilePath : outputFilePath
242
260
}
243
261
const result = await downloader . download ( downloadSettings )
244
262
expect ( result . length ) . toBe ( 1 )
245
263
} , 10000 )
264
+
265
+ test ( "Download all archive files from public repo" , async ( ) => {
266
+ const downloadSettings : IReleaseDownloadSettings = {
267
+ sourceRepoPath : "robinraju/probable-potato" ,
268
+ isLatest : true ,
269
+ tag : "" ,
270
+ id : "" ,
271
+ fileName : "*.zip" ,
272
+ tarBall : false ,
273
+ zipBall : false ,
274
+ extractAssets : true ,
275
+ outFilePath : outputFilePath
276
+ }
277
+ const result = await downloader . download ( downloadSettings )
278
+ if ( downloadSettings . extractAssets ) {
279
+ for ( const asset of result ) {
280
+ await extract ( asset , downloadSettings . outFilePath )
281
+ }
282
+ }
283
+
284
+ expect ( result . length ) . toBe ( 1 )
285
+ expect (
286
+ fs . existsSync ( path . join ( downloadSettings . outFilePath , "test-3.txt" ) )
287
+ ) . toBe ( true )
288
+ } , 10000 )
0 commit comments