on: [push, pull_request]

name: MSRV

jobs:
  check:
    name: Check
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - 1.56.1
          - stable
          - beta
          - nightly

    steps:
      - name: Checkout sources
        uses: actions/checkout@v3

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

      - name: Install Cargo.lock.msrv
        run: cp Cargo.lock.msrv Cargo.lock

      - name: Run cargo check
        if: matrix.rust != 'nightly'
        uses: actions-rs/cargo@v1
        with:
          command: check

      - name: Run cargo check (nightly)
        if: matrix.rust == 'nightly'
        continue-on-error: true
        uses: actions-rs/cargo@v1
        with:
          command: check

  test:
    needs: [check]
    name: Test Suite
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - 1.56.1
          - stable
          - beta
          - nightly
    steps:
      - name: Checkout sources
        uses: actions/checkout@v3

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

      - name: Install Cargo.lock.msrv
        run: cp Cargo.lock.msrv Cargo.lock

      - name: Run cargo test
        if: matrix.rust != 'nightly' && matrix.rust != '1.56.1'
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --all-features

      - name: Run cargo test (nightly)
        if: matrix.rust == '1.56.1'
        continue-on-error: true
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --tests --all-features

      - name: Run cargo test (nightly)
        if: matrix.rust == 'nightly'
        continue-on-error: true
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --all-features

  fmt:
    needs: [check]
    name: Rustfmt
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - stable
          - beta
    steps:
      - name: Checkout sources
        uses: actions/checkout@v3

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

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

  clippy:
    needs: [check]
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v3

      - name: Install toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: 1.56.1
          override: true
          components: clippy

      - name: Install Cargo.lock.msrv
        run: cp Cargo.lock.msrv Cargo.lock

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

  check-examples:
    name: Check examples
    needs: [check]
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - 1.56.1
          - stable

    steps:
      - name: Checkout sources
        uses: actions/checkout@v3

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

      - name: Install Cargo.lock.msrv
        run: cp Cargo.lock.msrv Cargo.lock

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

