From 0a48bd3b4b6d441e2bfbdcd5235ffba42420f718 Mon Sep 17 00:00:00 2001 From: Bob McWhirter Date: Thu, 9 May 2024 09:56:55 -0400 Subject: [PATCH] A bit of cleanup and adding a GHA. --- .github/workflows/ci-actions.yaml | 11 +++++++++++ crate/src/lib.rs | 19 ++++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci-actions.yaml b/.github/workflows/ci-actions.yaml index d1d37218..6614f1b7 100644 --- a/.github/workflows/ci-actions.yaml +++ b/.github/workflows/ci-actions.yaml @@ -17,6 +17,7 @@ jobs: steps: - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 - name: Use Node.js uses: actions/setup-node@v4 with: @@ -31,3 +32,13 @@ jobs: run: npm run build - name: Test run: npm run test -- --coverage --watchAll=false + + - name: Format + run: cargo fmt --check + working-directory: ./crate + - name: Check + run: cargo check + working-directory: ./crate + - name: Clippy + run: cargo clippy --all-targets --all-features -- -D warnings -D clippy::unwrap_used -D clippy::expect_used + working-directory: ./crate diff --git a/crate/src/lib.rs b/crate/src/lib.rs index 54f6290d..86b6afcf 100644 --- a/crate/src/lib.rs +++ b/crate/src/lib.rs @@ -6,11 +6,9 @@ use serde::Serialize; use serde_json::Value; use static_files::resource::new_resource; use static_files::Resource; -use std::cell::OnceCell; use std::collections::HashMap; -use std::fs; use std::str::from_utf8; -use std::sync::{Arc, Mutex, OnceLock}; +use std::sync::OnceLock; #[derive(Serialize, Clone, Default)] pub struct UI { @@ -77,7 +75,7 @@ pub fn generate_index_html( tera::Tera::one_off(&template, &context, true) } -pub fn trustify_ui(ui: &UI) -> Result, ()> { +pub fn trustify_ui(ui: &UI) -> HashMap<&'static str, Resource> { let mut resources = generate(); let template_file = resources.get("index.html.ejs"); @@ -87,10 +85,8 @@ pub fn trustify_ui(ui: &UI) -> Result, ()> { if let (Some(template_file), Some(branding_file_content)) = (template_file, branding_file_content) { - let template_file = from_utf8(template_file.data).map_err(|_| ()).unwrap(); - let branding_file_content = from_utf8(branding_file_content.data) - .map_err(|_| ()) - .unwrap(); + let template_file = from_utf8(template_file.data).unwrap(); + let branding_file_content = from_utf8(branding_file_content.data).unwrap(); generate_index_html( ui, template_file.to_string(), @@ -102,12 +98,9 @@ pub fn trustify_ui(ui: &UI) -> Result, ()> { } }); - resources.insert( - "", - new_resource(index_html.as_bytes(), 0, "text/html"), - ); + resources.insert("", new_resource(index_html.as_bytes(), 0, "text/html")); - Ok(resources) + resources } static INDEX_HTML: OnceLock = OnceLock::new();