name: CI/CD

on: [push, pull_request]

jobs:
  linux:
    name: Linux-x86
    runs-on: ubuntu-latest
    strategy:
      matrix:
        compiler: [g++, clang++]
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      
      - name: Install G++ Multilib, Clang++ & OpenGL library
        run: |
          sudo apt update
          sudo apt install -y g++-multilib clang libgl1-mesa-dev
      
      - name: Build
        run: |
          cd linux
          make COMPILER=${{ matrix.compiler }} CFG=release -j2
     
      - name: Package
        run: |
          cp -r linux/release/cl_dlls photomode/cl_dlls
          cp -r linux/release/dlls photomode/dlls
          zip -r photomode-linux.zip photomode

      - name: Deploy
        uses: actions/upload-artifact@v4
        with:
          name: Linux-x86-${{ matrix.compiler }}-${{ github.sha }}
          path: photomode

      - name: Release
        uses: softprops/action-gh-release@v2
        if: startsWith(github.ref, 'refs/tags/')
        with:
          fail_on_unmatched_files: true
          files: photomode-linux.zip

  win32:
    name: Win32
    runs-on: windows-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      
      - name: Add MSBuild to PATH
        uses: microsoft/setup-msbuild@v2
        with:
          msbuild-architecture: x86
      
      - name: Build
        run: msbuild projects/vs2019/projects.sln -t:rebuild -property:Configuration=Release -maxcpucount:2
      
      - name: Package
        run: |
          mkdir photomode\cl_dlls
          mkdir photomode\dlls
          copy projects\vs2019\Release\hl_cdll\client.dll photomode\cl_dlls\client.dll
          copy projects\vs2019\Release\hl_cdll\client.pdb photomode\cl_dlls\client.pdb
          copy projects\vs2019\Release\hldll\hl.dll photomode\dlls\hl.dll
          copy projects\vs2019\Release\hldll\hl.pdb photomode\dlls\hl.pdb
          Compress-Archive photomode photomode-windows.zip
      
      - name: Deploy
        uses: actions/upload-artifact@v4
        with:
          name: Win32-${{ github.sha }}
          path: photomode

      - name: Release
        uses: softprops/action-gh-release@v2
        if: startsWith(github.ref, 'refs/tags/')
        with:
          fail_on_unmatched_files: true
          files: photomode-windows.zip
