From d8fbc93e4f25d7608875ba30c8ae0e21f530422d Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Thu, 22 Jun 2023 11:57:02 -0700 Subject: [PATCH] Fix Clippy issues and add Rust checks to CI --- .github/workflows/build.yaml | 14 ++++++++++++++ gha-cache/src/api.rs | 3 +-- nix-actions-cache/src/error.rs | 10 +++------- nix-actions-cache/src/util.rs | 8 ++++---- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 02eae46..ab8550e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -5,6 +5,20 @@ on: workflow_call: jobs: + checks: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + + - uses: DeterminateSystems/nix-installer-action-cache@main + + - name: Check Rust formatting + run: nix develop --command cargo fmt --check + + - name: Clippy + run: nix develop --command cargo clippy + + build-artifacts-X64-macOS: runs-on: macos-12 steps: diff --git a/gha-cache/src/api.rs b/gha-cache/src/api.rs index c7ec242..bab198a 100644 --- a/gha-cache/src/api.rs +++ b/gha-cache/src/api.rs @@ -390,8 +390,7 @@ impl Api { future::join_all(futures) .await .into_iter() - .map(|join_result| join_result.unwrap()) - .collect::>()?; + .try_for_each(|join_result| join_result.unwrap())?; tracing::debug!("Received all chunks for cache {:?}", allocation.0); diff --git a/nix-actions-cache/src/error.rs b/nix-actions-cache/src/error.rs index fffb0ea..9b99701 100644 --- a/nix-actions-cache/src/error.rs +++ b/nix-actions-cache/src/error.rs @@ -1,21 +1,17 @@ //! Errors. -use std::io::Error as IoError; - use axum::{ http::StatusCode, response::{IntoResponse, Response}, }; use thiserror::Error; -use gha_cache::api::Error as ApiError; - pub type Result = std::result::Result; #[derive(Error, Debug)] pub enum Error { #[error("GitHub API error: {0}")] - ApiError(#[from] ApiError), + Api(#[from] gha_cache::api::Error), #[error("Not Found")] NotFound, @@ -24,7 +20,7 @@ pub enum Error { BadRequest, #[error("I/O error: {0}")] - IoError(#[from] IoError), + Io(#[from] std::io::Error), #[error("Failed to upload paths")] FailedToUpload, @@ -34,7 +30,7 @@ impl IntoResponse for Error { fn into_response(self) -> Response { let code = match &self { // HACK: HTTP 418 makes Nix throw a visible error but not retry - Self::ApiError(_) => StatusCode::IM_A_TEAPOT, + Self::Api(_) => StatusCode::IM_A_TEAPOT, Self::NotFound => StatusCode::NOT_FOUND, Self::BadRequest => StatusCode::BAD_REQUEST, _ => StatusCode::INTERNAL_SERVER_ERROR, diff --git a/nix-actions-cache/src/util.rs b/nix-actions-cache/src/util.rs index 127560a..3036be5 100644 --- a/nix-actions-cache/src/util.rs +++ b/nix-actions-cache/src/util.rs @@ -33,7 +33,7 @@ pub async fn get_store_paths() -> Result> { } // Special paths (so far only `.links`) - if s.starts_with(".") { + if s.starts_with('.') { continue; } } @@ -47,7 +47,7 @@ pub async fn get_store_paths() -> Result> { pub async fn upload_paths(mut paths: Vec, store_uri: &str) -> Result<()> { // When the daemon started Nix may not have been installed let env_path = Command::new("sh") - .args(&["-lc", "echo $PATH"]) + .args(["-lc", "echo $PATH"]) .output() .await? .stdout; @@ -66,8 +66,8 @@ pub async fn upload_paths(mut paths: Vec, store_uri: &str) -> Result<() tracing::debug!("{} paths in this batch", batch.len()); let status = Command::new("nix") - .args(&["--extra-experimental-features", "nix-command"]) - .args(&["copy", "--to", store_uri]) + .args(["--extra-experimental-features", "nix-command"]) + .args(["copy", "--to", store_uri]) .args(&batch) .env("PATH", &env_path) .status()