@@ -9,9 +9,10 @@ use std::fs::File;
9
9
use std:: io:: BufWriter ;
10
10
use std:: time:: { Duration , Instant , SystemTime } ;
11
11
12
+ use build_helper:: ci:: CiEnv ;
12
13
use build_helper:: metrics:: {
13
- JsonInvocation , JsonInvocationSystemStats , JsonNode , JsonRoot , JsonStepSystemStats , Test ,
14
- TestOutcome , TestSuite , TestSuiteMetadata ,
14
+ CiMetadata , JsonInvocation , JsonInvocationSystemStats , JsonNode , JsonRoot , JsonStepSystemStats ,
15
+ Test , TestOutcome , TestSuite , TestSuiteMetadata ,
15
16
} ;
16
17
use sysinfo:: { CpuRefreshKind , RefreshKind , System } ;
17
18
@@ -217,7 +218,12 @@ impl BuildMetrics {
217
218
children : steps. into_iter ( ) . map ( |step| self . prepare_json_step ( step) ) . collect ( ) ,
218
219
} ) ;
219
220
220
- let json = JsonRoot { format_version : CURRENT_FORMAT_VERSION , system_stats, invocations } ;
221
+ let json = JsonRoot {
222
+ format_version : CURRENT_FORMAT_VERSION ,
223
+ system_stats,
224
+ invocations,
225
+ ci_metadata : get_ci_metadata ( CiEnv :: current ( ) ) ,
226
+ } ;
221
227
222
228
t ! ( std:: fs:: create_dir_all( dest. parent( ) . unwrap( ) ) ) ;
223
229
let mut file = BufWriter :: new ( t ! ( File :: create( & dest) ) ) ;
@@ -245,6 +251,16 @@ impl BuildMetrics {
245
251
}
246
252
}
247
253
254
+ fn get_ci_metadata ( ci_env : CiEnv ) -> Option < CiMetadata > {
255
+ if ci_env != CiEnv :: GitHubActions {
256
+ return None ;
257
+ }
258
+ let workflow_run_id =
259
+ std:: env:: var ( "GITHUB_WORKFLOW_RUN_ID" ) . ok ( ) . and_then ( |id| id. parse :: < u64 > ( ) . ok ( ) ) ?;
260
+ let repository = std:: env:: var ( "GITHUB_REPOSITORY" ) . ok ( ) ?;
261
+ Some ( CiMetadata { workflow_run_id, repository } )
262
+ }
263
+
248
264
struct MetricsState {
249
265
finished_steps : Vec < StepMetrics > ,
250
266
running_steps : Vec < StepMetrics > ,
0 commit comments