@@ -2,7 +2,7 @@ use lazy_static::lazy_static;
22use regex:: Regex ;
33use serde_json:: Value ;
44use simplelog:: SharedLogger ;
5- use std:: collections:: BTreeMap ;
5+ use std:: collections:: { BTreeMap , HashMap } ;
66use std:: { env, fs} ;
77
88use crate :: prelude:: * ;
@@ -138,15 +138,59 @@ impl CIProvider for GitHubActionsProvider {
138138 PlatformSlug :: GithubActions
139139 }
140140
141+ /// For Github, the platform run part is the most complicated
142+ /// since we support matrix jobs.
143+ ///
144+ /// Computing the `run_part_id`:
145+ /// - not in a matrix:
146+ /// - simply take the job name
147+ /// - in a matrix:
148+ /// - take the job name
149+ /// - concatenate it with key-values from `matrix` and `strategy`
141150 fn get_platform_run_part ( & self ) -> Option < RunPart > {
142- info ! ( "Wowowowowowow, everybody calm down!" ) ;
151+ let job_name = self . gh_data . job . clone ( ) ;
152+ info ! ( "job_name {job_name}" ) ;
153+
154+ let metadata = BTreeMap :: new ( ) ;
155+
156+ let gh_env = get_env_variable ( "GH_ENV" )
157+ . ok ( )
158+ . and_then ( |v| serde_json:: from_str :: < Value > ( & v) . ok ( ) ) ;
159+
160+ let gh_github = get_env_variable ( "GH_GITHUB" )
161+ . ok ( )
162+ . and_then ( |v| serde_json:: from_str :: < Value > ( & v) . ok ( ) ) ;
163+
164+ let gh_matrix = get_env_variable ( "GH_MATRIX" )
165+ . ok ( )
166+ . and_then ( |v| serde_json:: from_str :: < Value > ( & v) . ok ( ) ) ;
167+
168+ let gh_strategy = get_env_variable ( "GH_STRATEGY" )
169+ . ok ( )
170+ . and_then ( |v| serde_json:: from_str :: < Value > ( & v) . ok ( ) ) ;
171+
172+ let run_part_id = if let ( Some ( Value :: Object ( matrix) ) , Some ( Value :: Object ( strategy) ) ) =
173+ ( & gh_matrix, & gh_strategy)
174+ {
175+ info ! ( "matrix: {matrix:?}" ) ;
176+ info ! ( "strategy: {strategy:?}" ) ;
177+
178+ format ! ( "{job_name}-{matrix:?}-{strategy:?}" )
179+ } else {
180+ job_name
181+ } ;
182+
183+ info ! ( "------- Job context -----------" ) ;
184+ info ! ( "run_part_id {run_part_id}" ) ;
185+ info ! ( "env {gh_env:?}" ) ;
186+ info ! ( "github {gh_github:?}" ) ;
187+ info ! ( "------- Job context -----------" ) ;
143188
144189 Some ( RunPart {
145190 run_id : self . gh_data . run_id . clone ( ) ,
146- // TODO(COD-447): handle matrix jobs here
147- run_part_id : self . gh_data . job . clone ( ) ,
191+ run_part_id,
148192 job_name : self . gh_data . job . clone ( ) ,
149- metadata : BTreeMap :: new ( ) ,
193+ metadata,
150194 } )
151195 }
152196
0 commit comments