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 c190999
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions src/run/ci_provider/github_actions/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,60 @@ 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::<Value>(&v).ok());

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

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

let gh_strategy = get_env_variable("GH_STRATEGY")
.ok()
.and_then(|v| serde_json::from_str::<Value>(&v).ok());

let run_part_id = if let (Some(Value::Object(matrix)), Some(Value::Object(strategy))) =
(&gh_matrix, &gh_strategy)
{
let matrix = serde_json::to_string(matrix).expect("Unable to re-serialize matrix");
let strategy =
serde_json::to_string(strategy).expect("Unable to re-serialize 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 c190999

Please sign in to comment.