name: CI

on:
  push:
    branches: main
  pull_request:

permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: full

jobs:
  rustfmt:
    name: Rustfmt
    runs-on: ubuntu-latest

    steps:
      - name: Checkout the repository
        uses: actions/checkout@v6
      - name: Update Rust
        run: rustup update stable
      - name: Run rustfmt
        run: cargo fmt --check

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

      steps:
        - name: Checkout the repository
          uses: actions/checkout@v6
        - name: Update Rust
          run: rustup update stable
        - name: Run clippy
          run: cargo clippy -- --deny warnings

  tests:
    name: Build and test
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest, ubuntu-24.04-arm, windows-11-arm]
        # Stable and MSRV
        rust_version: [stable, 1.88]

    steps:
      - name: Checkout the repository
        uses: actions/checkout@v6
      - name: Update Rust
        run: rustup update "${{ matrix.rust_version }}" && rustup default "${{ matrix.rust_version }}"
      - name: Build
        run: cargo build --verbose
      - name: Run tests
        run: cargo test --verbose
