name: Rust

on:
  push:

jobs:
  test:
    strategy:
      matrix:
        os: [ubuntu-20.04]
        compiler: [gcc-10]

    runs-on: ${{ matrix.os }}

    steps:
    - name: Environment setup
      uses: actions/checkout@v2
    - name: Rust setup
      uses: actions-rs/toolchain@v1
      with:
        # Note: nightly required for coverage of Doctests with tarpaulin
        toolchain: nightly
        override: true
    - name: Rust test with coverage
      uses: actions-rs/tarpaulin@v0.1
      env:
        CC: ${{ matrix.compiler }}
        FC: gfortran-9
      with:
        args: '--run-types Doctests Tests --exclude-files backends/* gallery/* include/* interface/*'
    - name: Codecov upload
      uses: codecov/codecov-action@v1.0.2
      with:
        directory: target/tarpaulin
        token: ${{secrets.CODECOV_TOKEN}}

  style:
    strategy:
      matrix:
        os: [ubuntu-20.04]
        compiler: [gcc-9]

    runs-on: ${{ matrix.os }}

    steps:
    - name: Environment setup
      uses: actions/checkout@v2
    - name: Rust setup
      uses: actions-rs/toolchain@v1
      with:
        # Note: rustfmt not always included in nightly
        toolchain: stable
    - name: Rust style
      run: |
        cargo fmt -- --check
