@@ -21,11 +21,14 @@ pub struct Workflow {
2121
2222 /// Name of the workflow.
2323 pub name : String ,
24+
25+ /// When enabled, a benchmark job is added to the workflow.
26+ pub benchmarks : bool ,
2427}
2528
2629impl Default for Workflow {
2730 fn default ( ) -> Self {
28- Self { auto_release : false , name : "CI" . into ( ) }
31+ Self { auto_release : false , name : "CI" . into ( ) , benchmarks : false }
2932 }
3033}
3134
@@ -40,6 +43,47 @@ impl Workflow {
4043 pub fn to_github_workflow ( & self ) -> GHWorkflow {
4144 self . clone ( ) . into ( )
4245 }
46+
47+ /// Creates the "Build and Test" job for the workflow.
48+ pub fn build_and_test ( & self ) -> Job {
49+ let mut job = Job :: new ( "Build and Test" )
50+ . permissions ( Permissions :: default ( ) . contents ( Level :: Read ) )
51+ . add_step ( Step :: checkout ( ) )
52+ . add_step (
53+ Toolchain :: default ( )
54+ . add_stable ( )
55+ . add_nightly ( )
56+ . add_clippy ( )
57+ . add_fmt ( ) ,
58+ )
59+ . add_step (
60+ Cargo :: new ( "test" )
61+ . args ( "--all-features --workspace" )
62+ . name ( "Cargo Test" ) ,
63+ )
64+ . add_step (
65+ Cargo :: new ( "fmt" )
66+ . nightly ( )
67+ . args ( "--check" )
68+ . name ( "Cargo Fmt" ) ,
69+ )
70+ . add_step (
71+ Cargo :: new ( "clippy" )
72+ . nightly ( )
73+ . args ( "--all-features --workspace -- -D warnings" )
74+ . name ( "Cargo Clippy" ) ,
75+ ) ;
76+
77+ if self . benchmarks {
78+ job = job. add_step (
79+ Cargo :: new ( "bench" )
80+ . args ( "--workspace" )
81+ . name ( "Cargo Bench" ) ,
82+ ) ;
83+ }
84+
85+ job
86+ }
4387}
4488
4589impl From < Workflow > for GHWorkflow {
@@ -61,7 +105,7 @@ impl From<Workflow> for GHWorkflow {
61105 let cond = is_main. and ( is_push) ;
62106
63107 // Jobs
64- let build = build_and_test ( ) ;
108+ let build = value . build_and_test ( ) ;
65109 let mut workflow = GHWorkflow :: new ( value. name )
66110 . add_env ( flags)
67111 . on ( event)
@@ -114,33 +158,3 @@ fn release_job(cond: &Context<bool>, build: &Job, permissions: &Permissions) ->
114158 . add_step ( Step :: checkout ( ) )
115159 . add_step ( Release :: default ( ) . command ( Command :: Release ) )
116160}
117-
118- fn build_and_test ( ) -> Job {
119- Job :: new ( "Build and Test" )
120- . permissions ( Permissions :: default ( ) . contents ( Level :: Read ) )
121- . add_step ( Step :: checkout ( ) )
122- . add_step (
123- Toolchain :: default ( )
124- . add_stable ( )
125- . add_nightly ( )
126- . add_clippy ( )
127- . add_fmt ( ) ,
128- )
129- . add_step (
130- Cargo :: new ( "test" )
131- . args ( "--all-features --workspace" )
132- . name ( "Cargo Test" ) ,
133- )
134- . add_step (
135- Cargo :: new ( "fmt" )
136- . nightly ( )
137- . args ( "--check" )
138- . name ( "Cargo Fmt" ) ,
139- )
140- . add_step (
141- Cargo :: new ( "clippy" )
142- . nightly ( )
143- . args ( "--all-features --workspace -- -D warnings" )
144- . name ( "Cargo Clippy" ) ,
145- )
146- }
0 commit comments