Skip to content

Commit

Permalink
Upload test logs with a UTF-8 content type
Browse files Browse the repository at this point in the history
This fixes rendering of test `.log` files when opened in a browser.

Updating the deps was required to get the project to compile due to:
```
error[E0635]: unknown feature `proc_macro_span_shrink`
  --> /Users/fmeum/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.56/src/lib.rs:92:30
   |
92 |     feature(proc_macro_span, proc_macro_span_shrink)
   |                              ^^^^^^^^^^^^^^^^^^^^^^
```

Update command:
```
cargo update proc-macro2 --precise 1.0.60
```
  • Loading branch information
fmeum committed Nov 22, 2024
1 parent 721d577 commit d55cc65
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions agent/Cargo.lock

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

17 changes: 12 additions & 5 deletions agent/src/artifact/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ fn upload_bep_json_file(
build_event_json_file: &Path,
mode: Mode,
) -> Result<()> {
uploader.upload_artifact(dry, None, build_event_json_file, mode)
uploader.upload_artifact(dry, None, build_event_json_file, mode, Some("application/json"))
}

fn gen_error_content(bazelci_task: &str, label: &str, name: &str, test_log: &str) -> String {
Expand Down Expand Up @@ -329,7 +329,7 @@ fn parse_test_xml(path: &Path, bazelci_task: &str, label: &str) -> Result<Option
Ok(Some(writer.into_inner().into_inner()))
}

fn execute_command(dry: bool, cwd: Option<&Path>, program: &str, args: &[&str]) -> Result<()> {
fn execute_command(dry: bool, cwd: Option<&Path>, program: &str, args: &Vec<&str>) -> Result<()> {
println!("{} {}", program, args.join(" "));

if dry {
Expand Down Expand Up @@ -384,6 +384,7 @@ impl Uploader {
cwd: Option<&Path>,
artifact: &Path,
mode: Mode,
content_type: Option<&str>,
) -> Result<()> {
{
let file = match cwd {
Expand All @@ -405,7 +406,7 @@ impl Uploader {
}

match mode {
Mode::Buildkite => self.upload_artifact_buildkite(dry, cwd, artifact),
Mode::Buildkite => self.upload_artifact_buildkite(dry, cwd, artifact, content_type),
}
}

Expand All @@ -414,13 +415,19 @@ impl Uploader {
dry: bool,
cwd: Option<&Path>,
artifact: &Path,
content_type: Option<&str>,
) -> Result<()> {
let artifact = artifact.display().to_string();
let mut args = vec!["artifact", "upload", artifact.as_str()];
let ct_arg = content_type.map(|ct| "--content_type=".to_owned() + ct).unwrap_or_default();
if !ct_arg.is_empty() {
args.push(ct_arg.as_str());
}
execute_command(
dry,
cwd,
"buildkite-agent",
&["artifact", "upload", artifact.as_str()],
&args,
)
}

Expand Down Expand Up @@ -631,7 +638,7 @@ fn upload_test_log(
mode: Mode,
) -> Result<()> {
let (cwd, artifact) = resolve_artifact(test_log, local_exec_root)?;
return uploader.upload_artifact(dry, cwd.as_ref().map(|pb| pb.as_path()), &artifact, mode);
return uploader.upload_artifact(dry, cwd.as_ref().map(|pb| pb.as_path()), &artifact, mode, Some("text/plain;encoding=utf-8"));
}

fn upload_test_xml(
Expand Down
4 changes: 2 additions & 2 deletions agent/tests/artifact/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn test_logs_uploaded_to_buildkite() -> Result<()> {
]);
cmd.assert()
.success()
.stdout(predicates::str::contains("buildkite-agent artifact upload src\\test\\shell\\bazel\\resource_compiler_toolchain_test\\test.log"));
.stdout(predicates::ord::eq("buildkite-agent artifact upload src\\test\\shell\\bazel\\resource_compiler_toolchain_test\\test.log --content_type=text/plain;encoding=utf-8\n"));

Ok(())
}
Expand All @@ -37,7 +37,7 @@ fn test_logs_uploaded_to_buildkite() -> Result<()> {
]);
cmd.assert()
.success()
.stdout(predicates::str::contains("buildkite-agent artifact upload src/test/shell/bazel/starlark_repository_test/shard_4_of_6/test_attempts/attempt_1.log"));
.stdout(predicates::ord::eq("buildkite-agent artifact upload src/test/shell/bazel/starlark_repository_test/shard_4_of_6/test_attempts/attempt_1.log --content_type=text/plain;encoding=utf-8\n"));

Ok(())
}
Expand Down

0 comments on commit d55cc65

Please sign in to comment.