1
1
//! The run command
2
2
use std:: {
3
3
collections:: HashMap ,
4
+ env,
5
+ future:: Future ,
4
6
io:: Write ,
5
7
path:: { Path , PathBuf } ,
6
8
} ;
@@ -20,7 +22,10 @@ use omnix_common::config::OmConfig;
20
22
use omnix_health:: { traits:: Checkable , NixHealth } ;
21
23
use serde:: { Deserialize , Serialize } ;
22
24
23
- use crate :: { config:: subflakes:: SubflakesConfig , flake_ref:: FlakeRef , step:: core:: StepsResult } ;
25
+ use crate :: {
26
+ config:: subflakes:: SubflakesConfig , flake_ref:: FlakeRef , github:: actions:: in_github_log_group,
27
+ step:: core:: StepsResult ,
28
+ } ;
24
29
25
30
use super :: run_remote;
26
31
@@ -64,6 +69,10 @@ pub struct RunCommand {
64
69
#[ arg( default_value = "." ) ]
65
70
pub flake_ref : FlakeRef ,
66
71
72
+ /// Print Github Actions log groups (enabled by default when run in Github Actions)
73
+ #[ clap( long, default_value_t = env:: var( "GITHUB_ACTION" ) . is_ok( ) ) ]
74
+ pub github_output : bool ,
75
+
67
76
/// Arguments for all steps
68
77
#[ command( flatten) ]
69
78
pub steps_args : crate :: step:: core:: StepsArgs ,
@@ -114,15 +123,22 @@ impl RunCommand {
114
123
// TODO: We'll refactor this function to use steps
115
124
// https://github.com/juspay/omnix/issues/216
116
125
117
- tracing:: info!( "{}" , "\n 👟 Gathering NixInfo" . bold( ) ) ;
118
- let nix_info = NixInfo :: get ( )
119
- . await
120
- . as_ref ( )
121
- . with_context ( || "Unable to gather nix info" ) ?;
126
+ let nix_info = in_github_log_group ( "info" , self . github_output , || async {
127
+ tracing:: info!( "{}" , "\n 👟 Gathering NixInfo" . bold( ) ) ;
128
+ NixInfo :: get ( )
129
+ . await
130
+ . as_ref ( )
131
+ . with_context ( || "Unable to gather nix info" )
132
+ } )
133
+ . await ?;
122
134
123
135
// First, run the necessary health checks
124
- tracing:: info!( "{}" , "\n 🫀 Performing health check" . bold( ) ) ;
125
- check_nix_version ( & cfg, nix_info) . await ?;
136
+ in_github_log_group ( "health" , self . github_output , || async {
137
+ tracing:: info!( "{}" , "\n 🫀 Performing health check" . bold( ) ) ;
138
+ // check_nix_version(&cfg, nix_info).await?;
139
+ check_nix_version ( & cfg, nix_info) . await
140
+ } )
141
+ . await ?;
126
142
127
143
// Then, do the CI steps
128
144
tracing:: info!(
@@ -131,24 +147,36 @@ impl RunCommand {
131
147
) ;
132
148
let res = ci_run ( & self . nixcmd , verbose, self , & cfg, & nix_info. nix_config ) . await ?;
133
149
134
- let m_out_link = self . get_out_link ( ) ;
135
- let s = serde_json:: to_string ( & res) ?;
136
- let mut path = tempfile:: Builder :: new ( )
137
- . prefix ( "om-ci-results-" )
138
- . suffix ( ".json" )
139
- . tempfile ( ) ?;
140
- path. write_all ( s. as_bytes ( ) ) ?;
141
-
142
- let results_path =
143
- addstringcontext:: addstringcontext ( & self . nixcmd , path. path ( ) , m_out_link) . await ?;
144
- println ! ( "{}" , results_path. display( ) ) ;
145
- if let Some ( m_out_link) = m_out_link {
146
- tracing:: info!(
147
- "Result available at {:?} and symlinked at {:?}" ,
148
- results_path. as_path( ) ,
149
- m_out_link
150
- ) ;
151
- }
150
+ let msg = in_github_log_group :: < anyhow:: Result < String > , _ , _ > (
151
+ "outlink" ,
152
+ self . github_output ,
153
+ || async {
154
+ let m_out_link = self . get_out_link ( ) ;
155
+ let s = serde_json:: to_string ( & res) ?;
156
+ let mut path = tempfile:: Builder :: new ( )
157
+ . prefix ( "om-ci-results-" )
158
+ . suffix ( ".json" )
159
+ . tempfile ( ) ?;
160
+ path. write_all ( s. as_bytes ( ) ) ?;
161
+
162
+ let results_path =
163
+ addstringcontext:: addstringcontext ( & self . nixcmd , path. path ( ) , m_out_link)
164
+ . await ?;
165
+ println ! ( "{}" , results_path. display( ) ) ;
166
+
167
+ let msg = format ! (
168
+ "Result available at {:?}{}" ,
169
+ results_path. as_path( ) ,
170
+ m_out_link
171
+ . map( |p| format!( " and symlinked at {:?}" , p) )
172
+ . unwrap_or_default( )
173
+ ) ;
174
+ Ok ( msg)
175
+ } ,
176
+ )
177
+ . await ?;
178
+
179
+ tracing:: info!( "{}" , msg) ;
152
180
153
181
Ok ( ( ) )
154
182
}
@@ -213,7 +241,7 @@ pub async fn check_nix_version(cfg: &OmConfig, nix_info: &NixInfo) -> anyhow::Re
213
241
Ok ( ( ) )
214
242
}
215
243
216
- /// Run CI fo all subflakes
244
+ /// Run CI for all subflakes
217
245
pub async fn ci_run (
218
246
cmd : & NixCmd ,
219
247
verbose : bool ,
@@ -249,11 +277,18 @@ pub async fn ci_run(
249
277
continue ;
250
278
}
251
279
252
- tracing:: info!( "\n 🍎 {}" , name) ;
253
- let steps_res = subflake
254
- . steps
255
- . run ( cmd, verbose, run_cmd, & systems, & cfg. flake_url , subflake)
256
- . await ?;
280
+ let steps_res = in_github_log_group (
281
+ & format ! ( "subflake={}" , name) ,
282
+ run_cmd. github_output ,
283
+ || async {
284
+ tracing:: info!( "\n 🍎 {}" , name) ;
285
+ subflake
286
+ . steps
287
+ . run ( cmd, verbose, run_cmd, & systems, & cfg. flake_url , subflake)
288
+ . await
289
+ } ,
290
+ )
291
+ . await ?;
257
292
res. insert ( subflake_name. clone ( ) , steps_res) ;
258
293
}
259
294
0 commit comments