name: Build and Test

on:
  push:
    branches: [main, ci_testing]
  pull_request:
    branches: [main]

jobs:
  cargo-build:
    strategy:
      matrix:
        rust_toolchain: [stable, 1.81.0]
        os: [ubuntu-latest]

    name: Build
    runs-on: ${{ matrix.os }}
    steps:
      - name: checkout
        uses: actions/checkout@v2

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

      - name: enable Cargo.lock
        if: ${{ matrix.rust_toolchain == '1.81.0' }}
        run: cp .Cargo.lock.msrv Cargo.lock

      - name: cargo check
        uses: actions-rs/cargo@v1
        with:
          command: check
          args: --all-features --all-targets

  cargo-tests:
    strategy:
      matrix:
        rust_toolchain: [stable]
        os: [ubuntu-latest]

    name: Build
    runs-on: ${{ matrix.os }}
    steps:
      - name: checkout
        uses: actions/checkout@v2

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

      - name: cargo fmt
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --check

      - name: cargo doc
        uses: actions-rs/cargo@v1
        with:
          command: doc
          args: --no-deps --config 'build.rustdocflags="-D warnings"'

      - name: cargo clippy
        uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: --all-features --all-targets -- -D warnings

      - name: Test with default features
        uses: actions-rs/cargo@v1
        with:
          command: test
