diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..7890c34 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,91 @@ +name: Rust Tests + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + PROTOC_VERSION: 33.3 + ARCH: linux-x86_64 + +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + test: + name: Test + runs-on: ubuntu-latest + if: github.event_name == 'push' || !github.event.pull_request.draft + steps: + - name: Cache protoc + id: cache-protoc + uses: actions/cache@v4 + with: + path: ~/.local/protoc + key: protoc-${{ env.PROTOC_VERSION }}-${{ runner.arch }} + + - name: Install protoc (if not cached) + if: steps.cache-protoc.outputs.cache-hit != 'true' + run: | + set -euxo pipefail + mkdir -p ~/.local/protoc + curl -L -o /tmp/protoc.zip \ + "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${ARCH}.zip" + unzip -q /tmp/protoc.zip -d ~/.local/protoc + + - name: Add protoc to PATH + run: echo "$HOME/.local/protoc/bin" >> "$GITHUB_PATH" + + - uses: actions/checkout@v4 + with: + lfs: true + - uses: dsherret/rust-toolchain-file@v1 + - uses: Swatinem/rust-cache@v2 + - name: Run tests + run: cargo test --all-features + + fmt: + name: Rustfmt + runs-on: ubuntu-latest + if: github.event_name == 'push' || !github.event.pull_request.draft + steps: + - uses: actions/checkout@v4 + - uses: dsherret/rust-toolchain-file@v1 + - run: cargo fmt --all -- --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + if: github.event_name == 'push' || !github.event.pull_request.draft + steps: + - name: Cache protoc + id: cache-protoc + uses: actions/cache@v4 + with: + path: ~/.local/protoc + key: protoc-${{ env.PROTOC_VERSION }}-${{ runner.arch }} + + - name: Install protoc (if not cached) + if: steps.cache-protoc.outputs.cache-hit != 'true' + run: | + set -euxo pipefail + mkdir -p ~/.local/protoc + curl -L -o /tmp/protoc.zip \ + "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${ARCH}.zip" + unzip -q /tmp/protoc.zip -d ~/.local/protoc + + - name: Add protoc to PATH + run: echo "$HOME/.local/protoc/bin" >> "$GITHUB_PATH" + + - uses: actions/checkout@v4 + - name: Fetch LFS files + run: git lfs fetch --all && git lfs checkout + - uses: dsherret/rust-toolchain-file@v1 + - uses: Swatinem/rust-cache@v2 + - run: cargo clippy --all-targets --all-features -- -D clippy::correctness -D clippy::suspicious diff --git a/Cargo.lock b/Cargo.lock index 1581383..19577d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7216,7 +7216,7 @@ dependencies = [ [[package]] name = "sqd-assignments" version = "0.1.0" -source = "git+https://github.com/subsquid/sqd-network.git?rev=32b959b#32b959bc85f548840f3d4d93852e633af32c61a6" +source = "git+https://github.com/subsquid/sqd-network.git?rev=020e5e9#020e5e9da5b05101c956cba79a57bcc6760266f1" dependencies = [ "anyhow", "crypto_box", @@ -7240,7 +7240,7 @@ dependencies = [ [[package]] name = "sqd-contract-client" version = "1.2.1" -source = "git+https://github.com/subsquid/sqd-network.git?rev=32b959b#32b959bc85f548840f3d4d93852e633af32c61a6" +source = "git+https://github.com/subsquid/sqd-network.git?rev=020e5e9#020e5e9da5b05101c956cba79a57bcc6760266f1" dependencies = [ "async-trait", "clap", @@ -7260,7 +7260,7 @@ dependencies = [ [[package]] name = "sqd-messages" version = "2.1.0" -source = "git+https://github.com/subsquid/sqd-network.git?rev=32b959b#32b959bc85f548840f3d4d93852e633af32c61a6" +source = "git+https://github.com/subsquid/sqd-network.git?rev=020e5e9#020e5e9da5b05101c956cba79a57bcc6760266f1" dependencies = [ "bytemuck", "flate2", @@ -7276,7 +7276,7 @@ dependencies = [ [[package]] name = "sqd-network-transport" version = "3.0.0" -source = "git+https://github.com/subsquid/sqd-network.git?rev=32b959b#32b959bc85f548840f3d4d93852e633af32c61a6" +source = "git+https://github.com/subsquid/sqd-network.git?rev=020e5e9#020e5e9da5b05101c956cba79a57bcc6760266f1" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 0fd8c67..92f8d91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,10 +57,11 @@ url = "2.5.2" walkdir = "2.5.0" zstd = "0.13" -sqd-assignments = { git = "https://github.com/subsquid/sqd-network.git", rev = "32b959b", features = ["reader"] } -sqd-contract-client = { git = "https://github.com/subsquid/sqd-network.git", rev = "32b959b", version = "1.2.1" } -sqd-messages = { git = "https://github.com/subsquid/sqd-network.git", rev = "32b959b", version = "2.0.2", features = ["bitstring"] } -sqd-network-transport = { git = "https://github.com/subsquid/sqd-network.git", rev = "32b959b", version = "3.0.0", features = ["worker", "metrics"] } +sqd-assignments = { git = "https://github.com/subsquid/sqd-network.git", rev = "020e5e9", features = ["reader"] } +sqd-contract-client = { git = "https://github.com/subsquid/sqd-network.git", rev = "020e5e9", version = "1.2.1" } +sqd-messages = { git = "https://github.com/subsquid/sqd-network.git", rev = "020e5e9", version = "2.0.2", features = ["bitstring"] } +sqd-network-transport = { git = "https://github.com/subsquid/sqd-network.git", rev = "020e5e9", version = "3.0.0", features = ["worker", "metrics"] } + sqd-query = { git = "https://github.com/subsquid/data.git", rev = "4c089d8", features = ["parquet"] } sqd-polars = { git = "https://github.com/subsquid/data.git", rev = "4c089d8" } sql_query_plan = {git = "https://github.com/subsquid/qplan.git", rev = "658f88f" } diff --git a/src/cli.rs b/src/cli.rs index f3468a9..2b2c415 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -71,7 +71,7 @@ pub struct Args { pub sentry_traces_sample_rate: f32, #[clap(env, hide(true), default_value_t = true)] - pub sentry_is_enabled: bool + pub sentry_is_enabled: bool, } fn parse_seconds(s: &str) -> Result { diff --git a/src/controller/p2p.rs b/src/controller/p2p.rs index f8f7937..f3a845b 100644 --- a/src/controller/p2p.rs +++ b/src/controller/p2p.rs @@ -595,10 +595,7 @@ impl + Send + 'static> P2PController sqd_messages::WorkerStatus { let status = worker.status().await; - let assignment_id = match status.assignment_id { - Some(assignment_id) => assignment_id, - None => String::new(), - }; + let assignment_id = status.assignment_id.unwrap_or_default(); sqd_messages::WorkerStatus { assignment_id, missing_chunks: Some(BitString::new(&status.unavailability_map)), diff --git a/src/controller/polars_target.rs b/src/controller/polars_target.rs index f1522d4..b9bc6b3 100644 --- a/src/controller/polars_target.rs +++ b/src/controller/polars_target.rs @@ -345,7 +345,7 @@ impl ExprTransformer for PolarsExprTransformer { l: &expression::SingularOrList, ) -> Result { let field = match l.value { - Some(ref x) => self.transform_expr(&*x, source, tctx), + Some(ref x) => self.transform_expr(x, source, tctx), None => polars_err("no field in list expression".to_string()), }?; diff --git a/src/controller/worker.rs b/src/controller/worker.rs index 4b8f20c..47ce278 100644 --- a/src/controller/worker.rs +++ b/src/controller/worker.rs @@ -9,9 +9,9 @@ use polars::{ prelude::{JsonFormat, JsonWriter}, }; use prost::Message; -use sql_query_plan::plan; use sqd_assignments::Assignment; use sqd_query::ParquetChunk; +use sql_query_plan::plan; use substrait::proto::Plan; use tokio_util::sync::CancellationToken; diff --git a/src/main.rs b/src/main.rs index 7c7b51d..d526081 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,15 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +#![warn(clippy::correctness)] +#![warn(clippy::suspicious)] +#![warn(clippy::perf)] +#![warn(clippy::complexity)] +#![allow(clippy::style)] +#![allow(clippy::pedantic)] +#![allow(clippy::nursery)] +#![cfg_attr(test, allow(clippy::all))] + use std::borrow::Cow; use std::sync::Arc;