@@ -207,7 +207,8 @@ async function findRelease({name, apiBase, tag}) {
207
207
async function findLatestCommit ( { name, apiBase, branch = "master" } ) {
208
208
Core . info ( `Looking for latest ${ name } commit` ) ;
209
209
const commitsResp = await githubGet ( {
210
- url : apiBase + "/commits/" + branch ,
210
+ url : apiBase + "/commits/:branch" ,
211
+ "branch" : branch ,
211
212
} ) ;
212
213
const commit = commitsResp . data ;
213
214
Core . info ( `Found ${ name } commit ${ commit [ "html_url" ] } ` ) ;
@@ -220,8 +221,11 @@ async function downloadCrystalRelease(suffix, version = null, destination = null
220
221
221
222
const asset = release [ "assets" ] . find ( ( a ) => a [ "name" ] . endsWith ( [ `-${ suffix } .tar.gz` ] ) ) ;
222
223
223
- Core . info ( `Downloading Crystal build from ${ asset [ "browser_download_url" ] } ` ) ;
224
- const downloadedPath = await ToolCache . downloadTool ( asset [ "browser_download_url" ] ) ;
224
+ Core . info ( `Downloading Crystal build from ${ asset [ "url" ] } ` ) ;
225
+ const downloadedPath = await githubDownloadViaRedirect ( {
226
+ url : asset [ "url" ] ,
227
+ headers : { "accept" : "application/octet-stream" } ,
228
+ } ) ;
225
229
226
230
Core . info ( "Extracting Crystal build" ) ;
227
231
return onlySubdir ( await ToolCache . extractTar ( downloadedPath , destination ) ) ;
@@ -236,15 +240,11 @@ async function downloadSource({name, apiBase, version = null, destination = null
236
240
ref = release [ "tag_name" ] ;
237
241
}
238
242
239
- const zipballLinkResp = await githubGet ( {
243
+ Core . info ( `Downloading ${ name } source for ${ ref } ` ) ;
244
+ const downloadedPath = await githubDownloadViaRedirect ( {
240
245
url : apiBase + "/zipball/:ref" ,
241
246
"ref" : ref ,
242
- request : { redirect : "manual" } ,
243
247
} ) ;
244
- const downloadUrl = zipballLinkResp . headers [ "location" ] ;
245
-
246
- Core . info ( `Downloading ${ name } source from ${ downloadUrl } ` ) ;
247
- const downloadedPath = await ToolCache . downloadTool ( downloadUrl ) ;
248
248
Core . info ( `Extracting ${ name } source` ) ;
249
249
const path = await onlySubdir ( await ToolCache . extractZip ( downloadedPath , destination ) ) ;
250
250
@@ -361,15 +361,11 @@ async function downloadCrystalNightlyForWindows(destination = null) {
361
361
} ) ;
362
362
const artifact = artifactsResp . data [ "artifacts" ] . find ( ( x ) => x . name === "crystal" ) ;
363
363
364
- const artifactLinkResp = await githubGet ( {
364
+ Core . info ( "Downloading Crystal build" ) ;
365
+ return githubDownloadViaRedirect ( {
365
366
url : GitHubApiBase + "/actions/artifacts/:artifact_id/zip" ,
366
367
"artifact_id" : artifact . id ,
367
- request : { redirect : "manual" } ,
368
368
} ) ;
369
- const downloadUrl = artifactLinkResp . headers [ "location" ] ;
370
-
371
- Core . info ( "Downloading Crystal build" ) ;
372
- return ToolCache . downloadTool ( downloadUrl ) ;
373
369
} ;
374
370
375
371
const [ { path : srcPath } , exeDownloadedPath ] = await Promise . all ( [
@@ -388,6 +384,12 @@ function githubGet(request) {
388
384
} ) ( request ) ;
389
385
}
390
386
387
+ async function githubDownloadViaRedirect ( request ) {
388
+ request . request = { redirect : "manual" } ;
389
+ const resp = await githubGet ( request ) ;
390
+ return ToolCache . downloadTool ( resp . headers [ "location" ] ) ;
391
+ }
392
+
391
393
async function onlySubdir ( path ) {
392
394
const [ subDir ] = await FS . readdir ( path ) ;
393
395
return Path . join ( path , subDir ) ;
0 commit comments