@@ -33,7 +33,7 @@ async function run() {
33
33
params . shards = "nightly" ;
34
34
}
35
35
params . path = Core . getInput ( "destination" ) || Path . join (
36
- process . env [ "RUNNER_TEMP" ] , `crystal-${ params . crystal } -${ params . shards } -${ params . arch } ` ,
36
+ process . env [ "RUNNER_TEMP" ] , `crystal-${ params . crystal . replace ( "branch:" , "" ) } -${ params . shards } -${ params . arch } ` ,
37
37
) ;
38
38
Core . setOutput ( "path" , params . path ) ;
39
39
@@ -87,17 +87,22 @@ const Nightly = "nightly";
87
87
const Any = "true" ;
88
88
const None = "false" ;
89
89
const NumericVersion = / ^ \d ( [ . \d ] * \d ) ? $ / ;
90
+ const BranchVersion = / ^ b r a n c h : ( .+ ) $ / ;
90
91
91
92
function checkVersion ( version , allowed , earliestAllowed = null ) {
92
93
const numericVersion = NumericVersion . test ( version ) && version ;
93
94
if ( numericVersion && ( ! earliestAllowed || cmpTags ( numericVersion , earliestAllowed ) >= 0 ) ) {
94
95
allowed [ allowed . indexOf ( NumericVersion ) ] = numericVersion ;
95
96
}
97
+ const branchVersion = BranchVersion . test ( version ) && version ;
98
+ if ( branchVersion ) {
99
+ allowed [ allowed . indexOf ( BranchVersion ) ] = branchVersion ;
100
+ }
96
101
97
102
if ( allowed . includes ( version ) ) {
98
103
return version ;
99
104
}
100
- if ( [ Latest , Nightly , numericVersion ] . includes ( version ) ) {
105
+ if ( [ Latest , Nightly , numericVersion , branchVersion ] . includes ( version ) ) {
101
106
throw `Version "${ version } " is not supported on ${ getPlatform ( ) } ` ;
102
107
}
103
108
throw `Version "${ version } " is invalid` ;
@@ -116,7 +121,7 @@ async function subprocess(command, options) {
116
121
}
117
122
118
123
async function installCrystalForLinux ( { crystal, shards, arch = getArch ( ) , path} ) {
119
- checkVersion ( crystal , [ Latest , Nightly , NumericVersion ] ) ;
124
+ checkVersion ( crystal , [ Latest , Nightly , NumericVersion , BranchVersion ] ) ;
120
125
const filePatterns = { "x86_64" : / - l i n u x - x 8 6 _ 6 4 \. t a r \. g z $ / , "x86" : / - l i n u x - i 6 8 6 \. t a r \. g z $ / } ;
121
126
checkArch ( arch , Object . keys ( filePatterns ) ) ;
122
127
@@ -141,7 +146,7 @@ async function installCrystalForLinux({crystal, shards, arch = getArch(), path})
141
146
}
142
147
143
148
async function installCrystalForMac ( { crystal, shards, arch = "x86_64" , path} ) {
144
- checkVersion ( crystal , [ Latest , Nightly , NumericVersion ] ) ;
149
+ checkVersion ( crystal , [ Latest , Nightly , NumericVersion , BranchVersion ] ) ;
145
150
if ( crystal === Latest || crystal === Nightly || cmpTags ( crystal , "1.2" ) >= 0 ) {
146
151
checkArch ( arch , [ "universal" , "x86_64" , "aarch64" ] ) ;
147
152
} else {
@@ -186,12 +191,17 @@ async function installAptPackages(packages) {
186
191
187
192
async function installBinaryRelease ( { crystal, filePattern, path} ) {
188
193
if ( crystal === Nightly ) {
189
- await IO . mv ( await downloadCrystalNightly ( filePattern ) , path ) ;
194
+ await IO . mv ( await downloadCrystalNightly ( filePattern , "master" ) , path ) ;
190
195
} else {
191
- if ( crystal === Latest ) {
192
- crystal = null ;
196
+ const version = BranchVersion . exec ( crystal ) ;
197
+ if ( version ) {
198
+ await IO . mv ( await downloadCrystalNightly ( filePattern , version [ 1 ] ) , path ) ;
199
+ } else {
200
+ if ( crystal === Latest ) {
201
+ crystal = null ;
202
+ }
203
+ await IO . mv ( await downloadCrystalRelease ( filePattern , crystal ) , path ) ;
193
204
}
194
- await IO . mv ( await downloadCrystalRelease ( filePattern , crystal ) , path ) ;
195
205
}
196
206
}
197
207
@@ -373,21 +383,21 @@ async function downloadSource({name, repo, ref}) {
373
383
return onlySubdir ( await ToolCache . extractZip ( downloadedPath ) ) ;
374
384
}
375
385
376
- async function downloadCrystalNightly ( filePattern ) {
377
- Core . info ( " Looking for latest Crystal build" ) ;
386
+ async function downloadCrystalNightly ( filePattern , branch ) {
387
+ Core . info ( ` Looking for latest Crystal build of branch ' ${ branch } '` ) ;
378
388
379
389
let build ;
380
390
for ( let offset = 0 ; ; ) {
381
- const req = `/tree/master ?filter=successful&shallow=true&limit=100&offset=${ offset } ` ;
391
+ const req = `/tree/${ branch } ?filter=successful&shallow=true&limit=100&offset=${ offset } ` ;
382
392
const resp = await fetch ( CircleApiBase + req ) ;
383
393
const builds = await resp . json ( ) ;
384
394
build = builds . find ( ( b ) => b [ "workflows" ] [ "job_name" ] === "dist_artifacts" ) ;
385
395
if ( build ) {
386
396
break ;
387
397
}
388
398
offset += builds . length ;
389
- if ( offset >= 1000 ) {
390
- throw " Could not find a matching nightly build" ;
399
+ if ( offset >= 1000 || builds . length === 0 ) {
400
+ throw ` Could not find a matching build for branch ' ${ branch } '` ;
391
401
}
392
402
}
393
403
Core . info ( `Found Crystal build ${ build [ "build_url" ] } ` ) ;
@@ -397,6 +407,9 @@ async function downloadCrystalNightly(filePattern) {
397
407
const resp = await fetch ( CircleApiBase + req ) ;
398
408
const artifacts = await resp . json ( ) ;
399
409
const artifact = artifacts . find ( ( a ) => filePattern . test ( a [ "path" ] ) ) ;
410
+ if ( artifact === undefined ) {
411
+ throw `Could not find build artifacts for build ${ build [ "build_num" ] } ` ;
412
+ }
400
413
401
414
Core . info ( `Downloading Crystal build from ${ artifact [ "url" ] } ` ) ;
402
415
const downloadedPath = await ToolCache . downloadTool ( artifact [ "url" ] ) ;
@@ -406,14 +419,19 @@ async function downloadCrystalNightly(filePattern) {
406
419
}
407
420
408
421
async function installCrystalForWindows ( { crystal, shards, arch = "x86_64" , path} ) {
409
- checkVersion ( crystal , [ Latest , Nightly , NumericVersion ] , "1.3" ) ;
422
+ checkVersion ( crystal , [ Latest , Nightly , NumericVersion , BranchVersion ] , "1.3" ) ;
410
423
checkArch ( arch , [ "x86_64" ] ) ;
411
424
412
425
if ( crystal === Nightly ) {
413
- await IO . mv ( await downloadCrystalNightlyForWindows ( ) , path ) ;
426
+ await IO . mv ( await downloadCrystalNightlyForWindows ( "master" ) , path ) ;
414
427
} else {
415
- const filePattern = / - w i n d o w s - x 8 6 _ 6 4 - m s v c ( - u n s u p p o r t e d ) ? \. z i p $ / ;
416
- await installBinaryRelease ( { crystal, shards, filePattern, path} ) ;
428
+ const version = BranchVersion . exec ( crystal ) ;
429
+ if ( version ) {
430
+ await IO . mv ( await downloadCrystalNightlyForWindows ( version [ 1 ] ) , path ) ;
431
+ } else {
432
+ const filePattern = / - w i n d o w s - x 8 6 _ 6 4 - m s v c ( - u n s u p p o r t e d ) ? \. z i p $ / ;
433
+ await installBinaryRelease ( { crystal, shards, filePattern, path} ) ;
434
+ }
417
435
}
418
436
419
437
Core . info ( "Setting up environment for Crystal" ) ;
@@ -425,11 +443,11 @@ async function installCrystalForWindows({crystal, shards, arch = "x86_64", path}
425
443
}
426
444
}
427
445
428
- async function downloadCrystalNightlyForWindows ( ) {
429
- Core . info ( " Looking for latest Crystal build" ) ;
446
+ async function downloadCrystalNightlyForWindows ( branch ) {
447
+ Core . info ( ` Looking for latest Crystal build of branch ' ${ branch } '` ) ;
430
448
431
449
const runsResp = await github . rest . actions . listWorkflowRuns ( {
432
- ...RepoCrystal , "workflow_id" : "win.yml" , "branch" : "master" ,
450
+ ...RepoCrystal , "workflow_id" : "win.yml" , "branch" : branch ,
433
451
"event" : "push" , "status" : "success" , "per_page" : 1 ,
434
452
} ) ;
435
453
const [ workflowRun ] = runsResp . data [ "workflow_runs" ] ;
0 commit comments