name: CI

on:
  pull_request:
  push:
    branches:
      - master

jobs:
  build_and_test:
    name: Build and test
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macOS-latest]
        rust: [nightly, beta, stable]

    steps:
      - uses: actions/checkout@master

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

      - name: build
        uses: actions-rs/cargo@v1
        with:
          command: build

      - name: tests
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --all

  check_fmt:
    name: Checking fmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master

      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: nightly
          override: true
          components: rustfmt

      - name: setup
        run: |
          rustup component add rustfmt
          rustc --version

      - name: fmt
        run: cargo fmt --all -- --check