name: CI

on: [push]

jobs:
  check:
    name: check
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - stable
          - nightly
    steps:
      - uses: actions/checkout@master
      - name: Install toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust }}
          override: true
      - name: Cargo check
        uses: actions-rs/cargo@v1
        with:
          command: check
          args: --all-features

  test:
    name: Tests
    runs-on: ubuntu-latest
    needs: check

    steps:
      - uses: actions/checkout@master

      - name: Install toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: nightly
          override: true
      - name: Run tests
        uses: actions-rs/cargo@v1
        with:
          command: build

  clippy_check:
    runs-on: ubuntu-latest
    needs: check

    steps:
      - uses: actions/checkout@v2
      - name: Install toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          components: clippy
          override: true
      - name: Run clippy
        uses: actions-rs/clippy-check@v1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          args: --all-features

  rustfmt:
    name: rustfmt
    runs-on: ubuntu-latest
    needs: check

    steps:
      - uses: actions/checkout@v2
      - name: Install toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          components: rustfmt
          override: true
      - name: Run rustfmt
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: -- --check

