on: [push, pull_request]

jobs:
  build:
    runs-on: ${{matrix.os}}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
    - uses: actions/cache@v2
      if: runner.os == 'Windows'
      with:
          key: 'vcpkg-${{matrix.os}}'
          path: 'C:/vcpkg/installed'

    - uses: knicknic/os-specific-run@v1.0.4
      name: Install dependencies
      with:
        linux: sudo apt-get -y install ninja-build zlib1g-dev
        macos: brew install ninja zlib
        windows: vcpkg install zlib --triplet x64-windows-static-md

    - uses: actions/checkout@v2
      with:
        submodules: 'recursive'

    - uses: knicknic/os-specific-run@v1.0.4
      name: Build
      with:
        linux: |
          mkdir ${{runner.workspace}}/build && cd ${{runner.workspace}}/build
          cmake -G Ninja ${{github.workspace}}
          cmake --build .
        macos: |
          mkdir ${{runner.workspace}}/build && cd ${{runner.workspace}}/build
          cmake -G Ninja ${{github.workspace}}
          cmake --build .
        windows:
          ${{github.workspace}}/.github/workflows/windows_build.bat
        windowsShell: cmd
