Skip to content

Commit

Permalink
feat(github): display context
Browse files Browse the repository at this point in the history
  • Loading branch information
fargito committed Jan 27, 2025
1 parent c0a780f commit dfdd096
Showing 1 changed file with 47 additions and 5 deletions.
52 changes: 47 additions & 5 deletions src/run/ci_provider/github_actions/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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<RunPart> {
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::<HashMap<String, String>>(&v).ok());

let gh_github = get_env_variable("GH_GITHUB")
.ok()
.and_then(|v| serde_json::from_str::<HashMap<String, String>>(&v).ok());

let gh_matrix = get_env_variable("GH_MATRIX")
.ok()
.and_then(|v| serde_json::from_str::<HashMap<String, String>>(&v).ok());

let gh_strategy = get_env_variable("GH_STRATEGY")
.ok()
.and_then(|v| serde_json::from_str::<HashMap<String, String>>(&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,
})
}

Expand Down

0 comments on commit dfdd096

Please sign in to comment.