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

name: CI

env:
  CI_CARGO_MAKE_VERSION: 0.32.9

jobs:
  linux:
    name: Linux
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust: ["1.52.1", "stable"]
    steps:
      - name: "Install dependencies"
        run: sudo apt-get install libncurses5-dev
      - uses: hecrj/setup-rust-action@967aec96c6a27a0ce15c1dac3aaba332d60565e2
        with:
          rust-version: ${{ matrix.rust }}
          components: rustfmt,clippy
      - uses: actions/checkout@v1
      - name: "Get cargo bin directory"
        id: cargo-bin-dir
        run: echo "::set-output name=dir::$HOME/.cargo/bin"
      - name: "Cache cargo make"
        id: cache-cargo-make
        uses: actions/cache@v2
        with:
          path: ${{ steps.cargo-bin-dir.outputs.dir }}/cargo-make
          key: ${{ runner.os }}-${{ matrix.rust }}-cargo-make-${{ env.CI_CARGO_MAKE_VERSION }}
      - name: "Install cargo-make"
        if: steps.cache-cargo-make.outputs.cache-hit != 'true'
        run: cargo install cargo-make --version ${{ env.CI_CARGO_MAKE_VERSION }}
      - name: "Format"
        run: cargo make fmt
      - name: "Check"
        run: cargo make check
      - name: "Test"
        run: cargo make test
        env:
          RUST_BACKTRACE: full
      - name: "Clippy"
        run: cargo make clippy
  windows:
    name: Windows
    runs-on: windows-latest
    strategy:
      matrix:
        rust: ["1.52.1", "stable"]
    steps:
      - uses: actions/checkout@v1
      - uses: hecrj/setup-rust-action@967aec96c6a27a0ce15c1dac3aaba332d60565e2
        with:
          rust-version: ${{ matrix.rust }}
          components: rustfmt,clippy
      - uses: actions/checkout@v1
      - name: "Get cargo bin directory"
        id: cargo-bin-dir
        run: echo "::set-output name=dir::$HOME\.cargo\bin"
      - name: "Cache cargo make"
        id: cache-cargo-make
        uses: actions/cache@v2
        with:
          path: ${{ steps.cargo-bin-dir.outputs.dir }}\cargo-make.exe
          key: ${{ runner.os }}-${{ matrix.rust }}-cargo-make-${{ env.CI_CARGO_MAKE_VERSION }}
      - name: "Install cargo-make"
        if: steps.cache-cargo-make.outputs.cache-hit != 'true'
        run: cargo install cargo-make --version ${{ env.CI_CARGO_MAKE_VERSION }}
      - name: "Format"
        run: cargo make fmt
      - name: "Check"
        run: cargo make check
      - name: "Test"
        run: cargo make test
        env:
          RUST_BACKTRACE: full
      - name: "Clippy"
        run: cargo make clippy
