name: Tests

on:
  pull_request:
    paths:
      - 'src/**'
      - 'Cargo.toml'
      - '.github/workflows/build.yml'

jobs:
  test-rust:
    name: Build and test Rust
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
          components: rustfmt, clippy
      - name: Cache Cargo
        uses: actions/cache@v3
        with:
          path: /github/home/.cargo
          key: cargo-cache-test-rs
      - name: Cache Rust dependencies
        uses: actions/cache@v3
        with:
          path: /github/home/target
          key: ubuntu-x86-64-target-cache-stable
      - name: Run formatting checks
        run: |
          cargo fmt --all -- --check
      - name: Run lints
        run: |
          export RUSTFLAGS="-C debuginfo=0"
            cargo clippy --all-features
            cargo clippy -- -D warnings
      - name: Run tests
        run: |
          cargo test --all-features