name: Rust Tests

on:
  pull_request:
  push:
    branches: [main]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  unit-tests:
    name: Unit Tests
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v6
      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
      - name: Install cargo-nextest
        uses: taiki-e/install-action@nextest
      - name: Cache cargo build
        uses: Swatinem/rust-cache@v2
        with:
          key: ubuntu-latest
      - name: Run unit tests
        run: cargo nextest run --bins

  integration-tests:
    name: Integration Tests
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v6
      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
      - name: Install cargo-nextest
        uses: taiki-e/install-action@nextest
      - name: Cache cargo build
        uses: Swatinem/rust-cache@v2
      - name: Run integration tests
        run: cargo nextest run --tests
