@@ -327,6 +327,8 @@ struct Workflow {
327
327
name : String ,
328
328
on : WorkflowOn ,
329
329
jobs : BTreeMap < String , WorkflowJob > ,
330
+ concurrency : BTreeMap < String , String > ,
331
+ permissions : BTreeMap < String , String > ,
330
332
}
331
333
332
334
#[ derive( Serialize ) ]
@@ -358,6 +360,10 @@ struct WorkflowStep {
358
360
#[ serde( skip_serializing_if = "Option::is_none" ) ]
359
361
name : Option < String > ,
360
362
#[ serde( skip_serializing_if = "Option::is_none" ) ]
363
+ id : Option < String > ,
364
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
365
+ r#if : Option < String > ,
366
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
361
367
uses : Option < String > ,
362
368
#[ serde( skip_serializing_if = "BTreeMap::is_empty" ) ]
363
369
env : BTreeMap < String , String > ,
@@ -381,15 +387,44 @@ impl Flags {
381
387
pull_request : WorkflowEvents { branches : vec ! [ "main" . to_owned( ) ] } ,
382
388
schedule : vec ! [ WorkflowSchedule { cron: "38 11 * * 6" . to_owned( ) } ] ,
383
389
} ,
390
+ concurrency : BTreeMap :: new ( ) ,
391
+ permissions : BTreeMap :: new ( ) ,
384
392
jobs : BTreeMap :: new ( ) ,
385
393
} ;
394
+ ci. concurrency . insert ( "group" . to_string ( ) , "ci-${{ github.ref }}" . to_string ( ) ) ;
395
+ ci. concurrency . insert (
396
+ "cancel-in-progress" . to_string ( ) ,
397
+ "${{ github.event_name == 'pull_request' }}" . to_string ( ) ,
398
+ ) ;
386
399
for actions in actions. chunk_by ( |x, y| x. os == y. os ) {
387
400
let mut job =
388
401
WorkflowJob { runs_on : format ! ( "{}-latest" , actions[ 0 ] . os) , steps : vec ! [ ] } ;
389
402
job. steps . push ( WorkflowStep {
390
403
uses : Some ( "actions/checkout@v4" . to_owned ( ) ) ,
391
404
..Default :: default ( )
392
405
} ) ;
406
+ let use_cache = matches ! (
407
+ actions[ 0 ] ,
408
+ Action { os: Os :: Ubuntu , toolchain: Toolchain :: Nightly , .. }
409
+ ) ;
410
+ let with = [
411
+ ( "path" . to_string ( ) , "~/.cargo/bin\n ~/.cargo/.crates*\n " . to_string ( ) ) ,
412
+ ( "key" . to_string ( ) , "cargo-home-${{ runner.os }}" . to_string ( ) ) ,
413
+ ] ;
414
+ let snapshot =
415
+ "echo snapshot=\" $(cargo install --list | sha256sum)\" >> $GITHUB_OUTPUT" ;
416
+ if use_cache {
417
+ job. steps . push ( WorkflowStep {
418
+ uses : Some ( "actions/cache/restore@v4" . to_owned ( ) ) ,
419
+ with : with. iter ( ) . cloned ( ) . collect ( ) ,
420
+ ..Default :: default ( )
421
+ } ) ;
422
+ job. steps . push ( WorkflowStep {
423
+ id : Some ( "before" . to_string ( ) ) ,
424
+ run : Some ( snapshot. to_string ( ) ) ,
425
+ ..Default :: default ( )
426
+ } ) ;
427
+ }
393
428
for actions in actions. chunk_by ( |x, y| x. toolchain == y. toolchain ) {
394
429
job. steps . push ( WorkflowStep {
395
430
run : Some ( format ! ( "rustup install {}" , actions[ 0 ] . toolchain) ) ,
@@ -415,24 +450,6 @@ impl Flags {
415
450
}
416
451
job. steps . push ( WorkflowStep { run : Some ( run) , ..Default :: default ( ) } ) ;
417
452
}
418
- if matches ! (
419
- actions[ 0 ] ,
420
- Action { os: Os :: Ubuntu , toolchain: Toolchain :: Nightly , .. }
421
- ) {
422
- job. steps . push ( WorkflowStep {
423
- uses : Some ( "actions/cache@v4" . to_owned ( ) ) ,
424
- with : [
425
- (
426
- "path" . to_owned ( ) ,
427
- "~/.cargo/bin\n ~/.cargo/.crates*\n " . to_owned ( ) ,
428
- ) ,
429
- ( "key" . to_owned ( ) , "cargo-home-${{ runner.os }}" . to_owned ( ) ) ,
430
- ]
431
- . into_iter ( )
432
- . collect ( ) ,
433
- ..Default :: default ( )
434
- } ) ;
435
- }
436
453
for task in [ Task :: Audit , Task :: SemverChecks ] {
437
454
if actions. iter ( ) . any ( |x| x. task == task) {
438
455
job. steps . push ( WorkflowStep {
@@ -451,6 +468,23 @@ impl Flags {
451
468
}
452
469
}
453
470
}
471
+ if use_cache {
472
+ job. steps . push ( WorkflowStep {
473
+ id : Some ( "after" . to_string ( ) ) ,
474
+ run : Some ( snapshot. to_string ( ) ) ,
475
+ ..Default :: default ( )
476
+ } ) ;
477
+ job. steps . push ( WorkflowStep {
478
+ uses : Some ( "actions/cache/save@v4" . to_owned ( ) ) ,
479
+ with : with. iter ( ) . cloned ( ) . collect ( ) ,
480
+ r#if : Some (
481
+ "${{ steps.before.outputs.snapshot != \
482
+ steps.after.outputs.snapshot }}"
483
+ . to_string ( ) ,
484
+ ) ,
485
+ ..Default :: default ( )
486
+ } ) ;
487
+ }
454
488
ci. jobs . insert ( actions[ 0 ] . os . to_string ( ) , job) ;
455
489
}
456
490
let ci = serde_yaml:: to_string ( & ci) . unwrap ( ) ;
0 commit comments