name: Rust

on:
  push:

jobs:
  test:
    strategy:
      matrix:
        os: [ubuntu-22.04]
        compiler: [clang]

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

    steps:
    - name: Environment setup
      uses: actions/checkout@v3
    - name: Rust setup
      uses: dtolnay/rust-toolchain@master
      with:
        # Note: nightly required for coverage of Doctests with tarpaulin
        toolchain: nightly
    - name: Rust test with coverage
      uses: actions-rs/tarpaulin@v0.1
      env:
        CC: ${{ matrix.compiler }}
        FC: gfortran-11
      with:
        args: '--run-types Doctests Tests --exclude-files backends/* gallery/* include/* interface/* --out Xml'
    - name: Codecov upload
      uses: codecov/codecov-action@v3
      with:
        files: ./cobertura.xml
        token: ${{secrets.CODECOV_TOKEN}}

  style:
    strategy:
      matrix:
        os: [ubuntu-22.04]
        compiler: [clang]

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

    steps:
    - name: Environment setup
      uses: actions/checkout@v3
    - name: Rust setup
      uses: dtolnay/rust-toolchain@master
      with:
        # Note: rustfmt not always included in nightly, will attempt to downgrade until rustfmt found
        toolchain: nightly
        components: rustfmt
    - name: Rust style
      run: |
        cargo +nightly fmt --version
        cargo +nightly fmt -- --check
