Skip to content

Commit

Permalink
Make CI cached to speed up build times (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bennett-Petzold authored Nov 19, 2023
1 parent d2a4e7e commit 1061b28
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 47 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/rust-clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ jobs:
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #@v1
- uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: llvm \
libclang-dev \
libopencv-dev

- uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
toolchain: stable
components: clippy
override: true
- uses: Swatinem/rust-cache@v2

- name: Install required cargo
run: cargo install clippy-sarif sarif-fmt
Expand All @@ -49,7 +52,7 @@ jobs:
continue-on-error: true

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v1
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: rust-clippy-results.sarif
wait-for-processing: true
23 changes: 15 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install system requirements
run: |
sudo apt-get update
sudo apt-get install -y aptitude
- uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: aptitude \
llvm \
libclang-dev \
libopencv-dev

- name: Install gstreamer
run: |
sudo apt update
sudo apt install -y aptitude
sudo aptitude install -y libgstreamer1.0-dev
sudo apt-get install -y llvm \
libclang-dev \
libopencv-dev \
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2

- name: Run tests
run: cargo test --all-features --verbose
66 changes: 35 additions & 31 deletions src/comms/auv_control_board/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ pub async fn get_messages<T>(
serial_conn: &mut T,
#[cfg(feature = "logging")] dump_file: &str,
) -> Vec<Vec<u8>>
where
T: AsyncReadExt + Unpin + Send,
where
T: AsyncReadExt + Unpin + Send,
{
if serial_conn.read_buf(buffer).await.unwrap() != 0 {
let mut messages = Vec::new();
Expand All @@ -92,7 +92,8 @@ pub async fn get_messages<T>(
}
}

#[cfg(feature = "logging")] {
#[cfg(feature = "logging")]
{
write_log(&messages, dump_file).await;
}

Expand All @@ -105,20 +106,16 @@ pub async fn get_messages<T>(
}

#[cfg(feature = "logging")]
pub async fn write_log(messages: &Vec<Vec<u8>>, #[cfg(feature = "logging")] dump_file: &str) {
let mut file =
OpenOptions::new()
.create(true)
.append(true)
.open(dump_file)
.await
.unwrap();
pub async fn write_log(messages: &[Vec<u8>], #[cfg(feature = "logging")] dump_file: &str) {
let mut file = OpenOptions::new()
.create(true)
.append(true)
.open(dump_file)
.await
.unwrap();

for msg in messages.iter() {
file
.write_all(&msg)
.await
.unwrap()
file.write_all(msg).await.unwrap()
}

file.flush().await.unwrap();
Expand All @@ -137,22 +134,32 @@ mod tests {
let mut buffer: Vec<u8> = Vec::with_capacity(512);

assert_eq!(
stream::iter(get_messages(
&mut buffer,
&mut &*input,
#[cfg(feature = "logging")] "test.dat").await)
.collect::<Vec<Vec<u8>>>()
.await,
stream::iter(
get_messages(
&mut buffer,
&mut &*input,
#[cfg(feature = "logging")]
"test.dat"
)
.await
)
.collect::<Vec<Vec<u8>>>()
.await,
vec![vec![]]
);

assert_eq!(
stream::iter(get_messages(
&mut buffer,
&mut &*input2,
#[cfg(feature = "logging")] "test.dat").await)
.collect::<Vec<Vec<u8>>>()
.await,
stream::iter(
get_messages(
&mut buffer,
&mut &*input2,
#[cfg(feature = "logging")]
"test.dat"
)
.await
)
.collect::<Vec<Vec<u8>>>()
.await,
vec![vec![3]]
);
}
Expand All @@ -171,9 +178,6 @@ mod tests {
get_messages(&mut buffer, &mut &*input2, dump_file).await;
}

assert_eq!(
std::fs::read(dump_file).unwrap(),
vec![0, 1, 3, 5]
);
assert_eq!(std::fs::read(dump_file).unwrap(), vec![0, 1, 3, 5]);
}
}
2 changes: 1 addition & 1 deletion src/missions/vision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ where
{
println!("Running detection...");
}

#[allow(unused_mut)]
let mut mat = self.context.get_mat().await;
let detections = self.model.detect(&mat);
Expand Down

0 comments on commit 1061b28

Please sign in to comment.