@@ -21,6 +21,9 @@ struct TestCommand {
2121    /// Output to a tui instead 
2222#[ arg( short,  long) ]  
2323    tui :  bool , 
24+     /// Generate the allure report but just export it to the host. 
25+ #[ arg( long) ]  
26+     export :  bool , 
2427} 
2528
2629/// Run a dagger pipeline too generate test reports. 
@@ -75,7 +78,7 @@ mod prelude {
7578                    no_cache :  None , 
7679                } , 
7780            ) ; 
78-             self . with_directory ( "/app" ,  workspace) 
81+             self . with_mounted_directory ( "/app" ,  workspace) 
7982                . with_workdir ( "/app" ) 
8083                . with_mounted_cache ( "/app/target" ,  client. cache_volume ( "rust-target" ) ) 
8184        } 
@@ -109,7 +112,31 @@ async fn main() -> Result<()> {
109112    dagger_sdk:: connect ( async  move  |client| { 
110113        match  arguments { 
111114            Cli :: Tests ( arguments)  => { 
115+                 if  cfg ! ( feature = "ci" )  { 
116+                     base_images:: base ( & client) 
117+                         . with_workspace ( & client) 
118+                         . with_mounted_directory ( "/load_cache" ,  client. host ( ) . directory ( "./cache" ) ) 
119+                         . with_exec ( vec ! [ 
120+                             "sh" , 
121+                             "-c" , 
122+                             "mv /load_cache/target/* /app/target/* || true" , 
123+                         ] ) 
124+                         . sync ( ) 
125+                         . await ?; 
126+                 } 
127+ 
112128                let  reports = report:: run_all_tests ( & client,  & arguments) . await ?; 
129+ 
130+                 if  cfg ! ( feature = "ci" )  { 
131+                     base_images:: base ( & client) 
132+                         . with_workspace ( & client) 
133+                         . with_exec ( vec ! [ "mkdir" ,  "/store_cache" ] ) 
134+                         . with_exec ( vec ! [ "sh" ,  "-c" ,  "mv /app/target /store_cache" ] ) 
135+                         . directory ( "/store_cache" ) 
136+                         . export ( "./cache" ) 
137+                         . await ?; 
138+                 } 
139+ 
113140                if  arguments. tui  { 
114141                    let  total = reports. len ( ) ; 
115142                    let  mut  pass = 0u16 ; 
@@ -142,8 +169,19 @@ async fn main() -> Result<()> {
142169                        return  Err ( eyre ! ( "Tests failed" ) ) ; 
143170                    } 
144171                }  else  { 
145-                     let  report = report:: generate_allure_report ( & client,  reports) . await ?; 
146-                     report:: serve_dist ( & client,  report) . await ?; 
172+                     let  report = report:: generate_allure_report ( & client,  & reports) . await ?; 
173+ 
174+                     if  arguments. export  { 
175+                         report. export ( "./allure_report/" ) . await ?; 
176+                         let  tests_failed = reports
177+                             . into_iter ( ) 
178+                             . any ( |report| matches ! ( report. status,  TestStatus :: Failed ) ) ; 
179+                         if  tests_failed { 
180+                             return  Err ( eyre ! ( "Tests failed" ) ) ; 
181+                         } 
182+                     }  else  { 
183+                         report:: serve_dist ( & client,  report) . await ?; 
184+                     } 
147185                } 
148186            } 
149187            Cli :: Fix  => { 
0 commit comments