From 5d99abd047085055206de35f6c9dae4e90007876 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 1 Apr 2024 12:01:34 -0400 Subject: [PATCH] fix: ci --- .github/workflows/ci.yaml | 2 +- crates/analytics/src/time.rs | 4 +--- crates/future/src/lib.rs | 19 ++++++++++--------- examples/geoblock.rs | 2 +- justfile | 25 ++++++++++++++++++++++--- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6cc2c3d..2333a07 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -28,7 +28,7 @@ jobs: cargo: - name: "Clippy" cmd: clippy - args: --workspace --all-features --tests -- -D clippy::all -W clippy::style + args: --workspace --all-features --all-targets -- -D warnings rust: stable - name: "Formatting" cmd: fmt diff --git a/crates/analytics/src/time.rs b/crates/analytics/src/time.rs index 5d53b83..a988279 100644 --- a/crates/analytics/src/time.rs +++ b/crates/analytics/src/time.rs @@ -3,9 +3,7 @@ use chrono::{NaiveDateTime, Utc}; pub const TIMESTAMP_FORMAT: &str = "%Y-%m-%d %H:%M:%S"; pub fn now() -> NaiveDateTime { - let now = Utc::now(); - NaiveDateTime::from_timestamp_opt(now.timestamp(), now.timestamp_subsec_nanos()) - .expect("invalid timestamp") + Utc::now().naive_utc() } pub fn format(t: &NaiveDateTime) -> String { diff --git a/crates/future/src/lib.rs b/crates/future/src/lib.rs index bd70191..1ab40ac 100644 --- a/crates/future/src/lib.rs +++ b/crates/future/src/lib.rs @@ -174,15 +174,16 @@ pub trait FutureExt { /// # async fn example() { /// let token = CancellationToken::new(); /// - /// let answer = async { - /// tokio::time::sleep(Duration::from_millis(500)).await; - /// 42 - /// } - /// .with_cancellation(token.clone()) - /// .on_cancel(async { - /// // Run some cleanup routine... - /// }) - /// .spawn(""); + /// let answer = tokio::task::spawn( + /// async { + /// tokio::time::sleep(Duration::from_millis(500)).await; + /// 42 + /// } + /// .with_cancellation(token.clone()) + /// .on_cancel(async { + /// // Run some cleanup routine... + /// }), + /// ); /// /// tokio::time::sleep(Duration::from_millis(100)).await; /// token.cancel(); diff --git a/examples/geoblock.rs b/examples/geoblock.rs index 167c87d..7d651ff 100644 --- a/examples/geoblock.rs +++ b/examples/geoblock.rs @@ -34,7 +34,7 @@ fn resolve_ip(_addr: IpAddr) -> geoip2::City<'static> { #[tokio::main] async fn main() -> Result<(), Box> { - let resolver: LocalResolver = LocalResolver::new(Some(|caller| resolve_ip(caller)), None); + let resolver: LocalResolver = LocalResolver::new(Some(resolve_ip), None); // The number after the colon is the ISO code of the subdivision when you don't // want to block the whole country. let blocked_countries = vec!["CU:12".into(), "IR".into(), "KP".into()]; diff --git a/justfile b/justfile index 06b436e..81e8a83 100644 --- a/justfile +++ b/justfile @@ -43,8 +43,16 @@ clean: @echo '==> Cleaning project target/*' cargo clean +# Make sure we are running the right submodule versions +update-submodules: + git submodule update --init --recursive + # Lint the project for any quality issues -lint: check fmt clippy commit-check +lint: clippy fmt commit-check + +unit: update-submodules lint test test-all + +devloop: unit fmt-imports # Run project linter clippy: @@ -53,7 +61,7 @@ clippy: if command -v cargo-clippy >/dev/null; then echo '==> Running clippy' - cargo clippy --workspace --all-features --tests -- -D clippy::all -W clippy::style + cargo clippy --workspace --all-features --all-targets -- -D warnings else echo '==> clippy not found in PATH, skipping' echo ' ^^^^^^ To install `rustup component add clippy`, see https://github.com/rust-lang/rust-clippy for details' @@ -66,12 +74,23 @@ fmt: if command -v cargo-fmt >/dev/null; then echo '==> Running rustfmt' - cargo +nightly fmt --all -- --check + cargo +nightly fmt --all else echo '==> rustfmt not found in PATH, skipping' echo ' ^^^^^^ To install `rustup component add rustfmt`, see https://github.com/rust-lang/rustfmt for details' fi +fmt-imports: + #!/bin/bash + set -euo pipefail + + if command -v cargo-fmt >/dev/null; then + echo '==> Running rustfmt' + cargo +nightly fmt -- --config group_imports=StdExternalCrate,imports_granularity=One + else + echo '==> rustfmt not found in PATH, skipping' + fi + # Run commit checker commit-check: #!/bin/bash