name: Build Executable

on:
    push:
        branches: ["main"]

jobs:
    build-macos-intel:
        runs-on: macos-15-intel
        steps:
            - uses: actions/checkout@v3
            - name: Set up Python
              uses: actions/setup-python@v4
              with:
                  python-version: "3.12"
            - name: Install uv
              uses: astral-sh/setup-uv@v6
            - name: Install the project
              run: uv sync
            - name: Install pyinstaller
              run: uv add --dev pyinstaller
            - name: Compile
              run: uv run --dev pyinstaller ShoggothStandalone.spec
            - uses: actions/upload-artifact@v4
              with:
                  name: shoggoth-mac-intel
                  path: dist/

    build-macos:
        runs-on: macos-latest
        steps:
            - uses: actions/checkout@v3
            - name: Set up Python
              uses: actions/setup-python@v4
              with:
                  python-version: "3.12"
            - name: Install uv
              uses: astral-sh/setup-uv@v6
            - name: Install the project
              run: uv sync
            - name: Install pyinstaller
              run: uv add --dev pyinstaller
            - name: Compile
              run: uv run --dev pyinstaller ShoggothStandalone.spec
            - uses: actions/upload-artifact@v4
              with:
                  name: shoggoth-mac
                  path: dist/

    build-windows:
        runs-on: windows-latest

        env:
            SDL_VERSION: 2.26.0

        steps:
            - uses: actions/checkout@v3

            - name: Cache SDL
              id: cache-windows-sdl
              uses: actions/cache@v3
              env:
                  cache-name: cache-sdl
              with:
                  path: C:\SDL2-*
                  key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.SDL_VERSION }}

            - if: ${{ steps.cache-windows-sdl.outputs.cache-hit != 'true' }}
              name: Download SDL if not cached
              run: |
                  Invoke-WebRequest "https://github.com/libsdl-org/SDL/releases/download/release-$env:SDL_VERSION/SDL2-devel-$env:SDL_VERSION-VC.zip" -OutFile C:\SDL.zip
                  Expand-Archive C:\SDL.zip -DestinationPath C:\

            - name: Set up Python
              uses: actions/setup-python@v4
              with:
                  python-version: "3.12"
            - name: Install uv
              uses: astral-sh/setup-uv@v6
            - name: Install the project
              run: uv sync
            - name: Install pyinstaller
              run: uv add --dev pyinstaller
            - name: Compile
              run: uv run --dev pyinstaller ShoggothStandalone.spec
            - uses: actions/upload-artifact@v4
              with:
                  name: shoggoth-win
                  path: dist/
