name: Unreal Engine Build

on:
  workflow_dispatch:
  push:
    branches: [main, develop]

jobs:
  # windows-build:
  #   runs-on: windows
  #   steps:
  #     - name: Checkout repository
  #       uses: actions/checkout@v3
  #       with:
  #         lfs: true
  #         fetch-depth: 0

  #     - name: Setup Unreal Engine
  #       run: | 
  #         # Ensure Unreal Engine is installed and set up
  #         # This assumes you have Unreal Engine installed on your runner
  #         # If not, you can add installation steps here

  #         # Set environment variables for Unreal Engine
  #         echo "UE_ROOT=C:\Program Files\Epic Games\UE_5.2" >> $GITHUB_ENV

  #     - name: Build Unreal Project
  #       run: |
  #         # Find your .uproject file (adjust path as needed)
  #         $UPROJECT_PATH = Get-ChildItem -Path . -Filter "*.uproject" -Recurse | Select-Object -First 1 -ExpandProperty FullName
  #         Write-Host "Building project: $UPROJECT_PATH"

  #         # Use Unreal Automation Tool to build the project
  #         & "$env:UE_ROOT\Engine\Build\BatchFiles\RunUAT.bat" BuildCookRun `
  #           -project="$UPROJECT_PATH" `
  #           -noP4 `
  #           -platform=Win64 `
  #           -clientconfig=Development `
  #           -cook -build -stage -pak -archive `
  #           -archivedirectory="$PWD\Build"

  #     - name: Upload build artifacts
  #       uses: actions/upload-artifact@v3
  #       with:
  #         name: windows-build
  #         path: Build/
  #         retention-days: 7

  macos-build:
    runs-on: macos
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          lfs: true
          fetch-depth: 0

      - name: Setup Unreal Engine
        run: |
          # Use the correct path where Unreal Engine is installed
          UE_PATH="/Users/Shared/Epic Games/UE_5.5"
          
          if [ ! -d "$UE_PATH" ]; then
            echo "Error: Unreal Engine is not installed in the expected location"
            echo "Please ensure Unreal Engine is installed at $UE_PATH"
            exit 1
          fi
          
          # Set environment variable with the correct Engine path
          echo "UE_ROOT=$UE_PATH/Engine" >> $GITHUB_ENV
          echo "Using Unreal Engine 5.5"
        
      - name: Build Unreal Project
        run: |
          chmod +x ./mac-build.sh
          ./mac-build.sh
        
      - name: Upload build artifacts
        uses: actions/upload-artifact@v3
        with:
          name: macos-build
          path: Builds/
          retention-days: 7