name: Pull Request

env:
  CARGO_TERM_COLOR: always
  NEXTEST_RETRIES: 10

on:
  push:
    branches:
      - 'main'

  pull_request:
    branches:
      - 'main'
    
jobs:
  test:
    name: cargo test
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v3
      
      - name: Install stable toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
      
      - name: Install cargo-nextest
        uses: taiki-e/install-action@nextest

      - name: Run cargo nextest
        run: cargo nextest run

  format:
    name: cargo fmt --all -- --check
    runs-on: ubuntu-latest

    steps:
      - name: Checkout sources
        uses: actions/checkout@v3
      
      - name: Install stable toolchain with rustfmt component
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
          components: rustfmt

      - name: Run cargo fmt
        run: cargo fmt --all -- --check

  clippy:
    name: cargo clippy -- -D warnings
    runs-on: ubuntu-latest

    steps:
      - name: Checkout sources
        uses: actions/checkout@v3

      - name: Install stable toolchain with clippy component
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
          components: clippy

      - name: Run cargo clippy
        run: cargo clippy -- -D warnings