name: build
on:
  pull_request:
  push:
    branches:
      - main

jobs:
  build:
    name: Builds for ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        name:
          - linux
          - macos
          - windows

        include:
          - name: linux
            os: ubuntu-latest
          - name: windows
            os: windows-latest
          - name: macos
            os: macos-latest

    steps:
      - uses: actions/checkout@v2

      - name: Cache .cargo and target
        uses: actions/cache@v2
        with:
          path: |
            ~/.cargo
            ./target
          key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.toml') }}
          restore-keys: |
            ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
            ${{ runner.os }}-cargo-build

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