From 651294190b5846b2f4af8a714b0fec12b14bb574 Mon Sep 17 00:00:00 2001 From: Matt White Date: Thu, 19 Sep 2024 20:36:25 +0000 Subject: [PATCH] Include the client version in BundleUploads Summary: Adding client version information for upload bundles will allow us to help Flaky Test users who may be using outdated versions of the Analytics CLI. If a user is running into an old bug, we can direct them to update their tooling version. Should help with onboarding. Closes TRUNK-12763 --- cli/src/clients.rs | 2 ++ cli/src/main.rs | 23 ++++++++++++++++------- cli/src/types.rs | 2 ++ cli/tests/upload.rs | 25 ++++++++++++++----------- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/cli/src/clients.rs b/cli/src/clients.rs index 89330b0f..046994d8 100644 --- a/cli/src/clients.rs +++ b/cli/src/clients.rs @@ -53,6 +53,7 @@ pub async fn get_bundle_upload_location( api_token: &str, org_slug: &str, repo: &Repo, + client_version: &str, ) -> anyhow::Result> { let client = reqwest::Client::new(); let resp = match client @@ -63,6 +64,7 @@ pub async fn get_bundle_upload_location( .json(&CreateBundleUploadRequest { org_url_slug: org_slug.to_owned(), repo: repo.clone(), + client_version: client_version.to_owned(), }) .send() .await diff --git a/cli/src/main.rs b/cli/src/main.rs index 4062c665..7038c6ec 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -232,16 +232,18 @@ async fn run_upload( let envs = EnvScanner::scan_env(); let os_info: String = env::consts::OS.to_string(); + + let cli_version = format!( + "cargo={} git={} rustc={}", + env!("CARGO_PKG_VERSION"), + env!("VERGEN_GIT_SHA"), + env!("VERGEN_RUSTC_SEMVER") + ); let meta = BundleMeta { version: META_VERSION.to_string(), - cli_version: format!( - "cargo={} git={} rustc={}", - env!("CARGO_PKG_VERSION"), - env!("VERGEN_GIT_SHA"), - env!("VERGEN_RUSTC_SEMVER") - ), org: org_url_slug.clone(), repo: repo.clone(), + cli_version: cli_version.clone(), tags, file_sets, envs, @@ -279,8 +281,15 @@ async fn run_upload( bundler.make_tarball(&bundle_time_file)?; log::info!("Flushed temporary tarball to {:?}", bundle_time_file); + let client_version = format!("trunk-analytics-cli {}", cli_version); let upload_op = Retry::spawn(default_delay(), || { - get_bundle_upload_location(&api_address, &token, &org_url_slug, &repo.repo) + get_bundle_upload_location( + &api_address, + &token, + &org_url_slug, + &repo.repo, + &client_version, + ) }) .await?; diff --git a/cli/src/types.rs b/cli/src/types.rs index 7bf2f59f..3d4940a3 100644 --- a/cli/src/types.rs +++ b/cli/src/types.rs @@ -31,6 +31,8 @@ pub struct CreateBundleUploadRequest { pub repo: Repo, #[serde(rename = "orgUrlSlug")] pub org_url_slug: String, + #[serde(rename = "clientVersion")] + pub client_version: String, } #[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)] diff --git a/cli/tests/upload.rs b/cli/tests/upload.rs index c4820029..773ccbbd 100644 --- a/cli/tests/upload.rs +++ b/cli/tests/upload.rs @@ -10,8 +10,7 @@ use tempfile::tempdir; use test_utils::mock_git_repo::setup_repo_with_commit; use test_utils::mock_server::{spawn_mock_server, RequestPayload}; use trunk_analytics_cli::types::{ - BundleMeta, CreateBundleUploadRequest, CreateRepoRequest, FileSetType, - GetQuarantineBulkTestStatusRequest, Repo, + BundleMeta, CreateRepoRequest, FileSetType, GetQuarantineBulkTestStatusRequest, Repo, }; mod test_utils; @@ -72,17 +71,21 @@ async fn upload_bundle() { }) ); + let upload_request = assert_matches!(requests_iter.next().unwrap(), RequestPayload::CreateBundleUpload(ur) => ur); assert_eq!( - requests_iter.next().unwrap(), - RequestPayload::CreateBundleUpload(CreateBundleUploadRequest { - repo: Repo { - host: String::from("github.com"), - owner: String::from("trunk-io"), - name: String::from("analytics-cli"), - }, - org_url_slug: String::from("test-org"), - }) + upload_request.repo, + Repo { + host: String::from("github.com"), + owner: String::from("trunk-io"), + name: String::from("analytics-cli"), + } ); + assert_eq!(upload_request.org_url_slug, String::from("test-org")); + assert!(upload_request + .client_version + .starts_with("trunk-analytics-cli cargo=")); + assert!(upload_request.client_version.contains(" git=")); + assert!(upload_request.client_version.contains(" rustc=")); let tar_extract_directory = assert_matches!(requests_iter.next().unwrap(), RequestPayload::S3Upload(d) => d);