Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
gnalh committed Sep 30, 2024
1 parent d10aebb commit 1af7bda
Show file tree
Hide file tree
Showing 9 changed files with 574 additions and 9 deletions.
25 changes: 22 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ codeowners = { path = "../codeowners" }
sentry = { version = "0.34.0", features = ["debug-images"] }
openssl = { version = "0.10.66", features = ["vendored"] }
uuid = { version = "1.10.0", features = ["v5"] }
xml-builder = "0.5.3"
flate2 = "1.0.34"
ctor = "0.2.8"

[dev-dependencies]
assert_cmd = "2.0.16"
Expand Down
1 change: 1 addition & 0 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pub mod runner;
pub mod scanner;
pub mod types;
pub mod utils;
pub mod xcresult;
37 changes: 31 additions & 6 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::env;
use std::io::Write;
use std::io::{Seek, Write};
use std::time::{SystemTime, UNIX_EPOCH};
use trunk_analytics_cli::xcresult::XCResultFile;

use clap::{Args, Parser, Subcommand};
use tokio_retry::strategy::ExponentialBackoff;
Expand Down Expand Up @@ -37,11 +38,13 @@ struct Cli {
struct UploadArgs {
#[arg(
long,
required = true,
required = false,
value_delimiter = ',',
help = "Comma-separated list of glob paths to junit files."
)]
junit_paths: Vec<String>,
#[arg(long, required = false, help = "Path of xcresult directory")]
xcresult_path: Option<String>,
#[arg(long, help = "Organization url slug.")]
org_url_slug: String,
#[arg(
Expand Down Expand Up @@ -143,6 +146,7 @@ async fn run_upload(
) -> anyhow::Result<i32> {
let UploadArgs {
junit_paths,
xcresult_path,
org_url_slug,
token,
repo_root,
Expand All @@ -167,8 +171,10 @@ async fn run_upload(
repo_head_commit_epoch,
)?;

if junit_paths.is_empty() {
return Err(anyhow::anyhow!("No junit paths provided."));
if junit_paths.is_empty() && xcresult_path.is_none() {
return Err(anyhow::anyhow!(
"Neither junit nor xcresult paths were provided."
));
}

let api_address = from_non_empty_or_default(
Expand All @@ -192,9 +198,28 @@ async fn run_upload(
}

let tags = parse_custom_tags(&tags)?;
let mut temp_paths = Vec::new();
// NOTE: This temp directory must be in a higher scope, otherwise it will be dropped before we can use it.
let junit_temp_dir = tempfile::tempdir()?;
if xcresult_path.is_some() && cfg!(target_os = "macos") {
let xcresult = XCResultFile::new(xcresult_path.unwrap());
let junit = xcresult?.junit();
let junit_temp_path = junit_temp_dir.path().join("xcresult_junit.xml");
let mut junit_temp = std::fs::File::create(&junit_temp_path)?;
junit_temp.write_all(&junit)?;
junit_temp.seek(std::io::SeekFrom::Start(0))?;
temp_paths.push(junit_temp_path.to_str().unwrap().to_string());
} else if xcresult_path.is_some() && !cfg!(target_os = "macos") {
log::warn!("xcresult was specified but it is only supported on macOS. Ignoring xcresult.");
}

let (file_sets, file_counter) =
build_filesets(&repo, &junit_paths, team.clone(), &codeowners, exec_start)?;
let (file_sets, file_counter) = build_filesets(
&repo,
&[junit_paths.as_slice(), temp_paths.as_slice()].concat(),
team.clone(),
&codeowners,
exec_start,
)?;

if !allow_missing_junit_files && (file_counter.get_count() == 0 || file_sets.is_empty()) {
return Err(anyhow::anyhow!("No JUnit files found to upload."));
Expand Down
Loading

0 comments on commit 1af7bda

Please sign in to comment.