name: Cargo Build & Test
on:
push:
pull_request:
env:
CARGO_TERM_COLOR: always
jobs:
build_and_test:
name: Rust project - ${{ matrix.toolchain }}
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- stable
- beta
- nightly
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Rust toolchain
run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- name: Install Clippy
run: rustup component add clippy --toolchain ${{ matrix.toolchain }}
- name: Install Rustfmt
run: rustup component add rustfmt --toolchain ${{ matrix.toolchain }}
- name: Cache Cargo registry
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-${{ matrix.toolchain }}-
- name: Cache Cargo build
uses: actions/cache@v2
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-${{ matrix.toolchain }}-
- name: Build the project
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Lint with clippy
run: cargo clippy -- -D warnings
- name: Check formatting
run: cargo fmt -- --check