From 11c3e088083d3ccd063667d74f7432703f0b4352 Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Tue, 12 Nov 2024 16:31:48 +1100 Subject: [PATCH] Fix CI - Attempt #2 --- .github/workflows/build_and_test.yaml | 4 +--- .gitignore | 3 ++- test-helpers/Cargo.toml | 3 +++ test-helpers/build.rs | 20 ++++++++++++++++++++ test-helpers/src/connection/java.rs | 7 ++++++- 5 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 test-helpers/build.rs diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index 8c9891f97..077bdec1d 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -43,9 +43,7 @@ jobs: # Otherwise only the last build to finish would get saved to the cache. # We allow different test_flags to share a cache as they should have identical build outputs key: ${{ matrix.runner }} - ${{ matrix.cargo_flags }} - cache-directories: | - target/debug/jassets - target/release/jassets + cache-directories: "test-helpers/j4rs" # this line means that only the main branch writes to the cache # benefits: diff --git a/.gitignore b/.gitignore index cb452cd1c..6930429b4 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ /docs/mdbook_bin /shotover-proxy/build/packages /some_local_file -/test-helpers/src/connection/kafka/node/node_modules \ No newline at end of file +/test-helpers/src/connection/kafka/node/node_modules +/test-helpers/j4rs \ No newline at end of file diff --git a/test-helpers/Cargo.toml b/test-helpers/Cargo.toml index c0cb615a5..c07f36a17 100644 --- a/test-helpers/Cargo.toml +++ b/test-helpers/Cargo.toml @@ -42,3 +42,6 @@ rustls-pemfile = "2.0.0" tokio-tungstenite = { version = "0.24", features = ["rustls-tls-native-roots"] } pretty_assertions.workspace = true serde.workspace = true + +[build-dependencies] +j4rs = "0.21.0" \ No newline at end of file diff --git a/test-helpers/build.rs b/test-helpers/build.rs new file mode 100644 index 000000000..c42e2a526 --- /dev/null +++ b/test-helpers/build.rs @@ -0,0 +1,20 @@ +use j4rs::errors::J4RsError; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + + std::fs::create_dir("j4rs").ok(); + match j4rs::Jvm::copy_j4rs_libs_under("j4rs") { + Ok(()) => {} + Err(J4RsError::GeneralError(e)) => { + // if the jassets directory has been deleted (maybe it wasnt cached with the rest of the build) + // then we may still have a functioning j4rs directory from a previous run + if e != "Can not find jassets directory" { + panic!("j4rs lib copy failed with: GeneralError({e})") + } + } + Err(e) => { + panic!("j4rs lib copy failed with: {e}") + } + } +} diff --git a/test-helpers/src/connection/java.rs b/test-helpers/src/connection/java.rs index 25ac455c9..ee9c34fc2 100644 --- a/test-helpers/src/connection/java.rs +++ b/test-helpers/src/connection/java.rs @@ -11,7 +11,12 @@ impl Jvm { /// Construct a JVM, downloads the list of deps from the maven repository. /// Example dep string: "org.slf4j:slf4j-api:1.7.36" pub(crate) fn new(deps: &[&str]) -> Self { - let jvm = Rc::new(JvmBuilder::new().build().unwrap()); + let jvm = Rc::new( + JvmBuilder::new() + .with_base_path("../test-helpers/j4rs") + .build() + .unwrap(), + ); for dep in deps { jvm.deploy_artifact(&MavenArtifact::from(*dep)).unwrap();