name: CI

on:
  push:
  pull_request:
    branches:
    - master
  schedule:
  - cron: '0 0 15 * *'
jobs:
  test:
    name: test
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        build:
        - stable
        - beta
        - nightly
        include:
        - build: stable
          os: ubuntu-18.04
          rust: stable
        - build: beta
          os: ubuntu-18.04
          rust: beta
        - build: nightly
          os: ubuntu-18.04
          rust: nightly
        - build: macos
          os: macos-latest
          rust: stable
        - build: win-msvc
          os: windows-2019
          rust: stable
        - build: win-gnu
          os: windows-2019
          rust: stable
    steps:
    - name: Checkout repository
      uses: actions/checkout@v2

    - name: Install suitesparse
      if: matrix.os == 'ubuntu-18.04'
      run: |
          sudo apt-get install libsuitesparse-dev

    - name: Install rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: ${{ matrix.rust }}
        profile: minimal
        override: true

    - name: Build (exclude suitesparse)
      run: cargo build --verbose --workspace --exclude suitesparse_ldl_sys --exclude sprs_suitesparse_ldl
      if: matrix.os != 'ubuntu-18.04'

    - name: Build (all)
      run: cargo build --verbose --workspace
      if: matrix.os == 'ubuntu-18.04'

    - name: Test (exclude suitesparse)
      run: cargo test --verbose --workspace --exclude suitesparse_ldl_sys --exclude sprs_suitesparse_ldl
      if: matrix.os != 'ubuntu-18.04'

    - name: Test (all)
      run: cargo test --verbose --workspace
      if: matrix.os == 'ubuntu-18.04'

    - name: Test (suitesparse integration)
      run: cargo test -p sprs-ldl --features sprs_suitesparse_ldl -Zpackage-features
      if: matrix.os == 'ubuntu-18.04' && matrix.build == 'nightly'

  rustfmt:
    name: rustfmt
    runs-on: ubuntu-18.04
    steps:
    - name: Checkout repository
      uses: actions/checkout@v2
    - name: Install rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        override: true
        profile: minimal
        components: rustfmt
    - name: Check formatting
      run: |
        cargo fmt -- --check
    - name: Documentation
      run: cargo doc

  benches:
    name: benchmarks
    runs-on: ubuntu-18.04
    steps:
    - name: Checkout repository
      uses: actions/checkout@v2
    - name: Install dependencies
      run: |
          sudo apt-get install libeigen3-dev libsuitesparse-dev
    - name: Install rust
      uses: actions-rs/toolchain@v1
      with:
          toolchain: nightly
          override: true
          profile: minimal
    - name: Run benchmarks
      run: |
          cargo bench --workspace
