name: CI

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

env:
  CARGO_TERM_COLOR: always
  CXX: g++

jobs:
  lint-test:
    name: Rust ${{ matrix.toolchain }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        toolchain: [stable, beta, nightly]
    steps:
      - name: Checkout sources
        uses: actions/checkout@v4

      - name: Install system dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y pkg-config g++ libhdf5-dev libmatio-dev

      - name: Install toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.toolchain }}
          components: clippy, rustfmt

      - name: Cache cargo artifacts
        uses: Swatinem/rust-cache@v2

      - name: cargo fmt --check
        if: matrix.toolchain == 'stable'
        run: cargo fmt --all -- --check

      - name: cargo clippy
        run: cargo clippy --locked --all-targets --all-features -- -D warnings

      - name: cargo test
        run: cargo test --locked --all --all-features

  msrv:
    name: MSRV (Rust 1.88.0)
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v4

      - name: Install system dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y pkg-config g++ libhdf5-dev

      - name: Install Rust 1.88.0
        uses: dtolnay/rust-toolchain@1.88.0

      - name: Cache cargo artifacts
        uses: Swatinem/rust-cache@v2

      - name: cargo check
        run: cargo check --locked --all-targets --all-features
