Skip to content

Commit

Permalink
add GH workflow for rust pr checks
Browse files Browse the repository at this point in the history
  • Loading branch information
simisimis committed Dec 19, 2024
1 parent eb23490 commit 32b9c75
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/check-rust.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
name: PR checks for rust server backend

on:
pull_request:
push:

concurrency:
group: '${{ github.workflow }} @ ${{ github.head_ref || github.ref }}'
cancel-in-progress: true

jobs:
changed-files:
name: Check changes for rust server app
runs-on: minafoundation-default-interruptible-runners
steps:
- name: 📥 Checkout
uses: actions/checkout@v4
- uses: tj-actions/changed-files@v39
id: changed
with:
files_yaml: |
server:
- 'server/**'
write_output_files: true
outputs:
modified_keys: ${{ steps.changed.outputs.modified_keys }}
rust-checks:
needs: changed-files
if: needs.changed-files.outputs.modified_keys != '[]' && needs.changed-files.outputs.modified_keys != ''
name: Rust PR Checks
runs-on: minafoundation-default-interruptible-runners
strategy:
matrix:
# In case in the future we want to add beta/nightly
toolchain: [stable]
steps:
- uses: actions/checkout@v4
- name: Install ${{ matrix.toolchain }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
- name: ✍️ Check formatting
run: cargo fmt --all -- --check
- name: 🧐 Check linting
run: cargo clippy -- -D warnings -D clippy::unwrap_used
- name: 🏗️ Build the app
run: cargo build --release
- name: 📋 Run the tests
run: cargo test --locked --all-features --all-targets
13 changes: 5 additions & 8 deletions server/src/ledger.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{collections::HashMap, fs, io::Read, path::PathBuf};

use anyhow::{Result, anyhow};
use anyhow::{anyhow, Result};
use flate2::read::GzDecoder;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use tar::Archive;

use crate::{Ocv, ProposalVersion, Vote, Wrapper, s3_client};
use crate::{s3_client, Ocv, ProposalVersion, Vote, Wrapper};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
pub struct Ledger(pub Vec<LedgerAccount>);
Expand All @@ -18,7 +18,7 @@ impl Ledger {
Self::download(ocv, hash, &dest).await?;
}
let contents = fs::read(dest)?;
Ok(Ledger(serde_json::from_slice(&contents[..]).unwrap()))
Ok(Ledger(serde_json::from_slice(&contents[..]).expect("Expecting a valid list of ledger accounts.")))
}

async fn download(ocv: &Ocv, hash: &String, to: &PathBuf) -> Result<()> {
Expand All @@ -30,10 +30,7 @@ impl Ledger {
.await?
.contents
.and_then(|objects| {
objects
.into_iter()
.find(|object| object.key.as_ref().map_or(false, |key| key.contains(hash)))
.and_then(|x| x.key)
objects.into_iter().find(|object| object.key.as_ref().is_some_and(|key| key.contains(hash))).and_then(|x| x.key)
})
.ok_or(anyhow!("Could not retrieve dump corresponding to {hash}"))?;
let bytes =
Expand All @@ -42,7 +39,7 @@ impl Ledger {
let mut archive = Archive::new(tar_gz);
for entry in archive.entries()? {
let mut entry = entry?;
let path = entry.path()?.to_str().unwrap().to_owned();
let path = entry.path()?.to_str().expect("Expecting a valid path").to_owned();
if s3_path.contains(&path) {
let mut buffer = Vec::new();
entry.read_to_end(&mut buffer)?;
Expand Down

0 comments on commit 32b9c75

Please sign in to comment.