Merge pull request #10 from DeterminateSystems/fix-clippy-issues

Fix Clippy issues and add Rust checks to CI
This commit is contained in:
Luc Perkins 2023-06-22 12:27:46 -07:00 committed by GitHub
commit 30c448f8f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 13 deletions

20
.github/workflows/checks.yaml vendored Normal file
View file

@ -0,0 +1,20 @@
name: Rust checks
on:
pull_request:
push:
branches: [main]
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

View file

@ -390,8 +390,7 @@ impl Api {
future::join_all(futures)
.await
.into_iter()
.map(|join_result| join_result.unwrap())
.collect::<Result<()>>()?;
.try_for_each(|join_result| join_result.unwrap())?;
tracing::debug!("Received all chunks for cache {:?}", allocation.0);

View file

@ -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<T> = std::result::Result<T, Error>;
#[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,

View file

@ -33,7 +33,7 @@ pub async fn get_store_paths() -> Result<HashSet<PathBuf>> {
}
// 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<HashSet<PathBuf>> {
pub async fn upload_paths(mut paths: Vec<PathBuf>, 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<PathBuf>, 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()