From dfdd0967b15ef7896e74c84b2c600645dbe93231 Mon Sep 17 00:00:00 2001 From: fargito Date: Thu, 16 Jan 2025 11:52:49 +0100 Subject: [PATCH] feat(github): display context --- .../ci_provider/github_actions/provider.rs | 52 +++++++++++++++++-- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/src/run/ci_provider/github_actions/provider.rs b/src/run/ci_provider/github_actions/provider.rs index d578217..442e29a 100644 --- a/src/run/ci_provider/github_actions/provider.rs +++ b/src/run/ci_provider/github_actions/provider.rs @@ -2,7 +2,7 @@ use lazy_static::lazy_static; use regex::Regex; use serde_json::Value; use simplelog::SharedLogger; -use std::collections::BTreeMap; +use std::collections::{BTreeMap, HashMap}; use std::{env, fs}; use crate::prelude::*; @@ -138,15 +138,57 @@ impl CIProvider for GitHubActionsProvider { PlatformSlug::GithubActions } + /// For Github, the platform run part is the most complicated + /// since we support matrix jobs. + /// + /// Computing the `run_part_id`: + /// - not in a matrix: + /// - simply take the job name + /// - in a matrix: + /// - take the job name + /// - concatenate it with key-values from `matrix` and `strategy` fn get_platform_run_part(&self) -> Option { - info!("Wowowowowowow, everybody calm down!"); + let job_name = self.gh_data.job.clone(); + info!("job_name {job_name}"); + + let metadata = BTreeMap::new(); + + let gh_env = get_env_variable("GH_ENV") + .ok() + .and_then(|v| serde_json::from_str::>(&v).ok()); + + let gh_github = get_env_variable("GH_GITHUB") + .ok() + .and_then(|v| serde_json::from_str::>(&v).ok()); + + let gh_matrix = get_env_variable("GH_MATRIX") + .ok() + .and_then(|v| serde_json::from_str::>(&v).ok()); + + let gh_strategy = get_env_variable("GH_STRATEGY") + .ok() + .and_then(|v| serde_json::from_str::>(&v).ok()); + + let run_part_id = if let (Some(matrix), Some(strategy)) = (&gh_matrix, &gh_strategy) { + info!("matrix: {matrix:?}"); + info!("strategy: {strategy:?}"); + + format!("{job_name}-{matrix:?}-{strategy:?}") + } else { + job_name + }; + + info!("------- Job context -----------"); + info!("run_part_id {run_part_id}"); + info!("env {gh_env:?}"); + info!("github {gh_github:?}"); + info!("------- Job context -----------"); Some(RunPart { run_id: self.gh_data.run_id.clone(), - // TODO(COD-447): handle matrix jobs here - run_part_id: self.gh_data.job.clone(), + run_part_id, job_name: self.gh_data.job.clone(), - metadata: BTreeMap::new(), + metadata, }) }