@@ -9,9 +9,10 @@ use std::fs::File;
99use std:: io:: BufWriter ;
1010use std:: time:: { Duration , Instant , SystemTime } ;
1111
12+ use build_helper:: ci:: CiEnv ;
1213use 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 ,
1516} ;
1617use sysinfo:: { CpuRefreshKind , RefreshKind , System } ;
1718
@@ -217,7 +218,12 @@ impl BuildMetrics {
217218 children : steps. into_iter ( ) . map ( |step| self . prepare_json_step ( step) ) . collect ( ) ,
218219 } ) ;
219220
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+ } ;
221227
222228 t ! ( std:: fs:: create_dir_all( dest. parent( ) . unwrap( ) ) ) ;
223229 let mut file = BufWriter :: new ( t ! ( File :: create( & dest) ) ) ;
@@ -245,6 +251,16 @@ impl BuildMetrics {
245251 }
246252}
247253
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+
248264struct MetricsState {
249265 finished_steps : Vec < StepMetrics > ,
250266 running_steps : Vec < StepMetrics > ,
0 commit comments