Skip to content

Commit

Permalink
Agent: Change base path of testlogs from outputPath to BINDIR (#1230)
Browse files Browse the repository at this point in the history
  • Loading branch information
coeuvre authored Sep 28, 2021
1 parent e8b963d commit 48c9c99
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion agent/src/artifact/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod upload;
pub mod upload;
7 changes: 7 additions & 0 deletions agent/src/artifact/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use std::{
};
use tracing::error;

use crate::utils::split_path_inclusive;

#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Mode {
// Upload as Buildkite's artifacts
Expand Down Expand Up @@ -217,6 +219,11 @@ fn upload_test_log(
mode: Mode,
) -> Result<()> {
let path = uri_to_file_path(test_log)?;

if let Some((first, second)) = split_path_inclusive(&path, "testlogs") {
return upload_artifact(dry, Some(&first), &second, mode);
}

let artifact = if let Some(local_exec_root) = local_exec_root {
if let Ok(relative_path) = path.strip_prefix(local_exec_root) {
relative_path
Expand Down
3 changes: 2 additions & 1 deletion agent/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod artifact;
pub mod artifact;
pub mod utils;
35 changes: 35 additions & 0 deletions agent/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::path::{Path, PathBuf};

/// Splits [`Path`] into two parts separated by `target`. The `target` itself is included
/// in the end of first part.
///
/// ```
/// # use std::path::Path;
/// # use bazelci_agent::utils::split_path_inclusive;
///
/// let path = Path::new("a/b/c");
/// let (first, second) = split_path_inclusive(path, "b").unwrap();
/// assert_eq!(first, Path::new("a/b"));
/// assert_eq!(second, Path::new("c"));
/// ```
///
pub fn split_path_inclusive(path: &Path, target: &str) -> Option<(PathBuf, PathBuf)> {
let mut iter = path.iter();

let mut first = PathBuf::new();
let mut found = false;
while let Some(comp) = iter.next() {
first.push(Path::new(comp));
if comp == target {
found = true;
break;
}
}

if found {
let second: PathBuf = iter.collect();
Some((first, second))
} else {
None
}
}
2 changes: 1 addition & 1 deletion agent/tests/artifact/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod upload;
mod upload;
4 changes: 2 additions & 2 deletions agent/tests/artifact/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn test_logs_uploaded_to_buildkite() -> Result<()> {
]);
cmd.assert()
.success()
.stdout(predicates::str::contains("buildkite-agent artifact upload bazel-out\\x64_windows-fastbuild\\testlogs\\src\\test\\shell\\bazel\\resource_compiler_toolchain_test\\test.log"));
.stdout(predicates::str::contains("buildkite-agent artifact upload src\\test\\shell\\bazel\\resource_compiler_toolchain_test\\test.log"));

Ok(())
}
Expand All @@ -33,7 +33,7 @@ fn test_logs_uploaded_to_buildkite() -> Result<()> {
]);
cmd.assert()
.success()
.stdout(predicates::str::contains("buildkite-agent artifact upload bazel-out/darwin-fastbuild/testlogs/src/test/shell/bazel/starlark_repository_test/shard_4_of_6/test_attempts/attempt_1.log"));
.stdout(predicates::str::contains("buildkite-agent artifact upload src/test/shell/bazel/starlark_repository_test/shard_4_of_6/test_attempts/attempt_1.log"));

Ok(())
}
2 changes: 1 addition & 1 deletion agent/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod artifact;
mod artifact;

0 comments on commit 48c9c99

Please sign in to comment.