name: Build Unity Project

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        unityVersion:
          - 2022.3.42f1
        targetPlatform:
          - WebGL
          - StandaloneLinux64
          - StandaloneWindows64
          # - StandaloneOSX

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - uses: actions/cache@v4
        with:
          path: ./Galagan/Library
          key: ${{ runner.os }}-Library-${{ hashFiles('./Galagan/ProjectSettings/ProjectSettings.asset') }}
          restore-keys: |
            ${{ runner.os }}-Library-

      - name: Build Unity Project
        uses: game-ci/unity-builder@v4
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
          UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
          UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
        with:
          projectPath: ./Galagan/
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}

      - name: Fix Build Folder
        run: |
          sudo rm -rf ./build/${{ matrix.targetPlatform }}/Galagan_BurstDebugInformation_DoNotShip/
          # sudo chown -R $USER:$USER ./build
          # sudo chmod -R 777 ./build
          sudo mv ./build/${{ matrix.targetPlatform}}/ ./build/Galagan/

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: galagan-${{ matrix.targetPlatform }}
          path: build/
