name: build

on:
  pull_request:
  push:
    branches: [master]

env:
  RUST_BACKTRACE: 1

jobs:
  test-stable:
    strategy:
      matrix:
        os: [linux, macos, windows]
        include:
        - os: linux
          runs-on: ubuntu-latest
        - os: windows
          runs-on: windows-latest
        - os: macos
          runs-on: macos-latest
    name: Test (${{ matrix.os }}, stable)
    runs-on: ${{ matrix.runs-on }}
    steps:
    - uses: actions/checkout@v2
    - uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        profile: minimal
    - name: Test
      uses: actions-rs/cargo@v1
      with:
        command: test
        args: --verbose
  test-non-stable:
    strategy:
      matrix:
        version: [beta, nightly, 1.43.0]
    name: Test (linux, ${{ matrix.version }})
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions-rs/toolchain@v1
      with:
        toolchain: ${{ matrix.version }}
        override: true
        profile: minimal
    - name: Test
      uses: actions-rs/cargo@v1
      with:
        command: test
        args: --verbose
  format:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions-rs/toolchain@v1
      with:
        toolchain: nightly
        profile: minimal
        override: true
        components: rustfmt
    - name: Check formatting
      uses: actions-rs/cargo@v1
      with:
        command: fmt
        args: --all -- --check
  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - run: rustup component add clippy
      - uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: -- -D warnings
