Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include the client version in BundleUploads #101

Merged
merged 7 commits into from
Oct 8, 2024
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
2 changes: 2 additions & 0 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub struct CreateBundleUploadRequest {
pub repo: RepoUrlParts,
#[serde(rename = "orgUrlSlug")]
pub org_url_slug: String,
#[serde(rename = "clientVersion")]
pub client_version: String,
}

#[derive(Debug, Serialize, Clone, Deserialize)]
Expand Down
2 changes: 2 additions & 0 deletions cli/src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub async fn create_bundle_upload_intent(
api_token: &str,
org_slug: &str,
repo: &Repo,
client_version: &str,
) -> anyhow::Result<CreateBundleUploadResponse> {
let client = reqwest::Client::new();
let resp = match client
Expand All @@ -63,6 +64,7 @@ pub async fn create_bundle_upload_intent(
.json(&CreateBundleUploadRequest {
org_url_slug: org_slug.to_owned(),
repo: repo.clone(),
client_version: client_version.to_owned(),
})
.send()
.await
Expand Down
22 changes: 15 additions & 7 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,21 +293,29 @@ 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 client_version = format!("trunk-analytics-cli {}", cli_version);
let upload = Retry::spawn(default_delay(), || {
create_bundle_upload_intent(&api_address, &token, &org_url_slug, &repo.repo)
create_bundle_upload_intent(
&api_address,
&token,
&org_url_slug,
&repo.repo,
&client_version,
)
})
.await?;

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,
bundle_upload_id: upload.id,
tags,
file_sets,
Expand Down
24 changes: 14 additions & 10 deletions cli/tests/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fs;
use std::io::BufReader;
use std::path::Path;

use api::{CreateBundleUploadRequest, CreateRepoRequest, GetQuarantineBulkTestStatusRequest};
use api::{CreateRepoRequest, GetQuarantineBulkTestStatusRequest};
use assert_cmd::Command;
use assert_matches::assert_matches;
use context::repo::RepoUrlParts as Repo;
Expand Down Expand Up @@ -79,17 +79,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, "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);
Expand Down
Loading