name: CI

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  tests:
    name: Run tests - Rust (${{ matrix.rust }}) on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - { rust: stable, os: ubuntu-latest }
          - { rust: 1.50.0, os: ubuntu-latest }
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          submodules: true
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.rust }}
          override: true
      - name: Build with all features
        run: cargo build --all-features
      - name: Build
        run: cargo build --all --verbose
      - name: Run tests
        run: cargo test --all --all-features
      - name: Clean
        run: cargo clean

  rustfmt:
    name: Run rustfmt - Rust (${{ matrix.rust }}) on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - { rust: stable, os: ubuntu-latest }
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          submodules: true
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.rust }}
          override: true
          components: rustfmt
      - name: Check format
        run: cargo fmt --all -- --check

  clippy:
    name: Run clippy - Rust (${{ matrix.rust }}) on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - { rust: stable, os: ubuntu-latest }
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          submodules: true
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.rust }}
          override: true
          components: clippy
      - name: Check with clippy
        run: cargo clippy --all

  examples:
    name: Build examples - Rust (${{ matrix.rust }}) on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - { rust: stable, os: ubuntu-latest }
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          submodules: true
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.rust }}
          override: true
          components: clippy, rustfmt
      - name: Check examples format
        run: cargo fmt --all -- --check
        working-directory: ./examples
      - name: Check examples with clippy
        run: cargo clippy --all
        working-directory: ./examples
      - name: Build examples
        run: cargo build --all --verbose
        working-directory: ./examples
      - name: Clean examples
        run: cargo clean
        working-directory: ./examples

  build-nightly:
    name: Build nightly - Rust (${{ matrix.rust }}) on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - { rust: nightly, os: ubuntu-latest }
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          submodules: true
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.rust }}
          override: true
      - name: Build on nightly with all features
        run: cargo build --all-features
      - name: Build on nightly
        run: cargo build --all --verbose
