Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/executor/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ impl Orchestrator {
let last_upload_result = self.upload_all(&mut completed_runs, api_client).await?;
end_group!();

if let Err(e) = self.provider.export_run_id(&last_upload_result.run_id) {
warn!("Failed to expose the run id as a step output: {e}");
}

if self.is_local() {
poll_results(
api_client,
Expand Down
45 changes: 45 additions & 0 deletions src/run_environment/github_actions/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use serde::Deserialize;
use serde_json::Value;
use simplelog::SharedLogger;
use std::collections::BTreeMap;
use std::io::Write;
use std::{env, fs};

use crate::api_client::{Authentication, CodSpeedAPIClient};
Expand Down Expand Up @@ -382,6 +383,17 @@ impl RunEnvironmentProvider for GitHubActionsProvider {

Ok(())
}

fn export_run_id(&self, run_id: &str) -> Result<()> {
let output_path = get_env_variable("GITHUB_OUTPUT")?;
let mut output_file = fs::OpenOptions::new()
.append(true)
.create(true)
.open(output_path)?;
writeln!(output_file, "run-id={run_id}")?;

Ok(())
}
}

#[cfg(test)]
Expand Down Expand Up @@ -833,4 +845,37 @@ mod tests {
},
)
}

#[test]
fn test_export_run_id() {
Comment thread
moha-bekh marked this conversation as resolved.
let output_file = tempfile::NamedTempFile::new().unwrap();
fs::write(output_file.path(), "previous=value\n").unwrap();

with_var("GITHUB_OUTPUT", Some(output_file.path()), || {
let github_actions_provider = GitHubActionsProvider {
owner: "owner".into(),
repository: "repository".into(),
ref_: "refs/head/my-branch".into(),
head_ref: Some("my-branch".into()),
base_ref: None,
sender: None,
run_id: "123789".into(),
job_name: "my_job".into(),
event: RunEvent::Push,
repository_root_path: "/home/work/my-repo".into(),
is_head_repo_fork: false,
is_repository_private: false,
oidc_config: None,
};

github_actions_provider
.export_run_id("66f7e2c1a3b4d5e6f7a8b9c0")
.unwrap();
});

assert_eq!(
fs::read_to_string(output_file.path()).unwrap(),
"previous=value\nrun-id=66f7e2c1a3b4d5e6f7a8b9c0\n"
);
}
}
5 changes: 5 additions & 0 deletions src/run_environment/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ pub trait RunEnvironmentProvider {
Ok(())
}

/// Expose the CodSpeed run id to the next steps of the CI job.
fn export_run_id(&self, _run_id: &str) -> Result<()> {
Ok(())
}

/// Returns the metadata necessary for uploading results to CodSpeed.
///
/// `orchestrator_run_part_suffix` is structured data from the orchestrator used to differentiate
Expand Down
Loading