diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 00000000..e1ae14b2 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,87 @@ +name: check +# This workflow runs whenever a PR is opened or updated, or a commit is pushed +# to main. It runs several checks: +# - fmt: checks that the code is formatted according to `rustfmt`. +# - clippy: checks that the code does not contain any `clippy` warnings. +# - doc: checks that the code can be documented without errors. +# - typos: checks for typos across the repo. +permissions: + contents: read +# This configuration allows maintainers of this repo to create a branch and +# pull request based on the new branch. Restricting the push trigger to the +# main branch ensures that the PR only gets built once. +on: + push: + branches: [main, v*] + pull_request: +# If new code is pushed to a PR branch, then cancel in progress workflows for +# that PR. Ensures that we don't waste CI time, and returns results quicker. +# https://github.com/jonhoo/rust-ci-conf/pull/5 +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true +env: + CARGO_TERM_COLOR: always + +jobs: + cargo-build: + name: Cargo Build + runs-on: ubuntu-latest + + steps: + - name: Fetch Repository + uses: actions/checkout@v5 + + - name: Install stable toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + + - name: cargo build + run: cargo b --locked --all-targets --all-features + + cargo-fmt: + name: Cargo fmt + runs-on: ubuntu-latest + + steps: + - name: Fetch Repository + uses: actions/checkout@v5 + + - name: Install stable toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: rustfmt + toolchain: nightly + + - name: Rustfmt Check + run: cargo fmt --all --check + + cargo-clippy: + name: Cargo clippy + runs-on: ubuntu-latest + + steps: + - name: Fetch Repository + uses: actions/checkout@v5 + + - name: Install stable toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: clippy + + - name: Clippy Check + uses: giraffate/clippy-action@v1 + with: + reporter: "github-pr-check" + github_token: ${{ secrets.GITHUB_TOKEN }} + clippy_flags: --all-targets --all-features -- -D warnings -D clippy::pedantic + + typos-cli: + name: typos + runs-on: ubuntu-latest + + steps: + - name: Fetch Repository + uses: actions/checkout@v5 + + - name: Check spelling of files in the workspace + uses: crate-ci/typos@v1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..19b870f3 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,46 @@ +name: tests + +on: + pull_request: + merge_group: + push: + branches: [main] + +env: + CARGO_TERM_COLOR: always + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + cargo-next-test: + name: Cargo test + runs-on: ubuntu-latest + + steps: + - name: Fetch Repository + uses: actions/checkout@v5 + + - name: Install stable toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + + - name: Cache cargo-nextest binary + id: cache-cargo-nextest + uses: actions/cache@v4 + with: + path: ~/.cargo/bin/cargo-nextest + key: ${{ runner.os }}-cargo-nextest-${{ hashFiles('**/Cargo.lock') }} + + - name: Install cargo-nextest + if: steps.cache-cargo-nextest.outputs.cache-hit != 'true' + uses: taiki-e/install-action@v2 + with: + tool: cargo-nextest + + - name: Cargo test + run: cargo nextest run --locked --all-targets --all-features --no-tests=pass + + # https://github.com/rust-lang/cargo/issues/6669 + - name: Run doc tests + run: cargo test --locked --doc diff --git a/examples/historical_scanning/main.rs b/examples/historical_scanning/main.rs index c11e6bf3..9c1db196 100644 --- a/examples/historical_scanning/main.rs +++ b/examples/historical_scanning/main.rs @@ -1,9 +1,6 @@ use std::{sync::Arc, time::Duration}; -use alloy::providers::{ProviderBuilder}; -use alloy::rpc::types::Log; -use alloy::sol; -use alloy::sol_types::SolEvent; +use alloy::{providers::ProviderBuilder, rpc::types::Log, sol, sol_types::SolEvent}; use alloy_node_bindings::Anvil; use async_trait::async_trait; use event_scanner::{CallbackConfig, EventCallback, EventFilter, ScannerBuilder}; @@ -65,7 +62,7 @@ async fn main() -> anyhow::Result<()> { callback: Arc::new(CounterCallback), }; - counter_contract.increase().send().await?; + let _ = counter_contract.increase().send().await?.get_receipt().await?; let mut scanner = ScannerBuilder::new(anvil.ws_endpoint_url()) .add_event_filter(increase_filter) diff --git a/examples/simple_counter/main.rs b/examples/simple_counter/main.rs index 8c8ff1d9..98c3b2cd 100644 --- a/examples/simple_counter/main.rs +++ b/examples/simple_counter/main.rs @@ -1,9 +1,6 @@ use std::{sync::Arc, time::Duration}; -use alloy::providers::ProviderBuilder; -use alloy::rpc::types::Log; -use alloy::sol; -use alloy::sol_types::SolEvent; +use alloy::{providers::ProviderBuilder, rpc::types::Log, sol, sol_types::SolEvent}; use alloy_node_bindings::Anvil; use async_trait::async_trait; use event_scanner::{CallbackConfig, EventCallback, EventFilter, ScannerBuilder}; diff --git a/src/lib.rs b/src/lib.rs index 9e1e8f8f..1edd8c13 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,9 @@ pub mod callback; pub mod scanner; pub mod types; -pub use crate::builder::ScannerBuilder; -pub use crate::callback::EventCallback; -pub use crate::scanner::Scanner; -pub use crate::types::{CallbackConfig, EventFilter}; +pub use crate::{ + builder::ScannerBuilder, + callback::EventCallback, + scanner::Scanner, + types::{CallbackConfig, EventFilter}, +};