on:
  release:
    types: [published]
  push:
    branches:
      - master

  pull_request:
    branches:
      - master

jobs:
  Build:
    strategy:
      fail-fast: true
      matrix:
        name: [linux,windows_x86,windows_x64,mac_mac,mac_ios]
        include:
          - name: linux
            os: ubuntu-20.04
            label: Linux
          - name: windows_x86
            os: windows-2019
            label: Win_x86
          - name: windows_x64
            os: windows-2019
            label: Win_x64
          - name: mac_mac
            os: macos-11
            label: Mac_mac
          - name: mac_ios
            os: macos-11
            label: Mac_ios

    name: Build on ${{ matrix.name }}
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
          fetch-depth: 1

      - run: |
          git lfs install
          git lfs pull

      - name: Install Linux Dependencies
        if: matrix.name == 'linux'
        run: |
          sudo apt-get update
          sudo apt-get -y install libx11-dev libxrandr-dev libxi-dev libxinerama-dev libxcursor-dev libudev-dev libx11-xcb-dev
          sudo apt-get -y install libglu1-mesa-dev mesa-common-dev libvulkan-dev

      - name: Build
        shell: bash
        run: |
          if [ "${{ matrix.name }}" = "mac_mac" ];
          then
            cmake -S . -B build -DBUILD_TEST=ON -DBUILD_EXAMPLE=ON
          fi

          if [ "${{ matrix.name }}" = "mac_ios" ];
          then
            cmake -S . -B build -DCMAKE_SYSTEM_NAME=iOS "-DCMAKE_OSX_ARCHITECTURES=armv7;armv7s;arm64;i386;x86_64"
          fi

          if [ "${{ matrix.name }}" = "linux" ];
          then
            cmake -S . -B build -DBUILD_TEST=ON -DBUILD_VULKAN=ON -DBUILD_VULKAN_COMPILER=ON -DBUILD_EXAMPLE=ON -DBUILD_TOOL=ON
          fi

          if [ "${{ matrix.name }}" = "windows_x86" ];
          then
            cmake -S . -B build -A Win32 -DBUILD_TEST=ON -DBUILD_EXAMPLE=OFF
          fi

          if [ "${{ matrix.name }}" = "windows_x64" ];
          then
            cmake -S . -B build -DBUILD_TEST=ON -DBUILD_EXAMPLE=ON
          fi

          cmake --build build --config Release

      - name: Test
        if: matrix.name == 'windows_x64'
        run: |
          mkdir test_ci
          cp build/src_test/Release/LLGI_Test.exe test_ci/
          cd test_ci
          ./LLGI_Test.exe test

      - name: Upload
        uses: actions/upload-artifact@v2
        with:
          name: Test_Result_Windows
          path: test_ci