From 5b42f89b315f639466cfceb8ae9d9a34f9b43872 Mon Sep 17 00:00:00 2001 From: gagliardetto Date: Tue, 13 Feb 2024 17:53:29 +0100 Subject: [PATCH] Add rust tests --- .github/workflows/tests-rust.yml | 59 ++++++++++++++++++++++++++++++++ ci/rust-version.sh | 9 +++++ 2 files changed, 68 insertions(+) create mode 100644 .github/workflows/tests-rust.yml create mode 100644 ci/rust-version.sh diff --git a/.github/workflows/tests-rust.yml b/.github/workflows/tests-rust.yml new file mode 100644 index 00000000..7416da22 --- /dev/null +++ b/.github/workflows/tests-rust.yml @@ -0,0 +1,59 @@ +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + workflow_dispatch: + push: + +env: + CARGO_TERM_COLOR: always + CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse + +jobs: + test: + strategy: + matrix: + os: [ubuntu-20.04, ubuntu-22.04] + + runs-on: [self-hosted, '${{ matrix.os }}'] + steps: + - uses: actions/checkout@v4 + + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + ./target + key: ${{ matrix.os }}-geyser-plugin-runner-${{ hashFiles('rust-toolchain.toml') }}-${{ hashFiles('**/Cargo.lock') }}-0001 + restore-keys: | + ${{ matrix.os }}-geyser-plugin-runner + + - name: Set rust version + run: | + RUST_VERSION="$(./ci/rust-version.sh)" + echo "RUST_VERSION=$RUST_VERSION" >> "$GITHUB_ENV" + + - uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ env.RUST_VERSION }} + profile: minimal + components: clippy, rustfmt + + - name: cargo tree + run: | + cargo tree + git checkout Cargo.lock + cargo tree --frozen --offline + + - name: Run fmt + run: cargo fmt --all -- --check + + - name: Run clippy + run: cargo clippy --all-targets --tests -- -Dwarnings + + - name: Run test + run: cargo test --all-targets diff --git a/ci/rust-version.sh b/ci/rust-version.sh new file mode 100644 index 00000000..6127e8e2 --- /dev/null +++ b/ci/rust-version.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +# Prints Rust version + +while read -r name equals value _; do + if [[ $name = "channel" && $equals = = ]]; then + echo "${value//\"/}" + fi +done < <(cat $(dirname "${BASH_SOURCE[0]}")/../rust-toolchain.toml)