name: CI
on:
  push:
    branches:
      - master
  pull_request:

jobs:
  rustfmt:
    name: Check Style
    runs-on: ubuntu-latest

    permissions:
      contents: read

    steps:
      - name: Checkout the code
        uses: actions/checkout@v6
      - name: Setup Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - name: Run cargo fmt
        run: cargo fmt --all -- --check

  clippy:
    name: Run Clippy
    runs-on: ubuntu-latest

    permissions:
      contents: read

    steps:
      - name: Checkout the code
        uses: actions/checkout@v6
      - name: Setup Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - name: Rust cache
        uses: Swatinem/rust-cache@v2
      - name: Run cargo clippy
        run: cargo clippy --workspace --features tools -- -D warnings

  test:
    name: Run Tests
    runs-on: ubuntu-latest

    permissions:
      contents: read

    steps:
      - name: Checkout the code
        uses: actions/checkout@v6
      - name: Setup Rust toolchain
        uses: dtolnay/rust-toolchain@stable
      - name: Rust cache
        uses: Swatinem/rust-cache@v2
      - name: Run cargo test
        run: cargo test --workspace --features tools
