name: PyTaiko
on:
    push:
        branches: ["main"]
    pull_request:
        branches: ["main"]
permissions:
    contents: write
    pull-requests: write
    issues: write
    repository-projects: write
jobs:
    build:
        strategy:
            matrix:
                os: [ubuntu-22.04, windows-latest]
        runs-on: ${{ matrix.os }}
        steps:
            - name: Check-out repository
              uses: actions/checkout@v4
            - name: Install uv
              uses: astral-sh/setup-uv@v4
            - name: Setup Python
              run: uv python install
            - name: Install Dependencies
              run: |
                  uv sync
            - name: Install Nuitka
              run: |
                  uv add nuitka
            - name: Build Executable
              run: |
                  uv run nuitka --mode=app --noinclude-setuptools-mode=nofollow --noinclude-IPython-mode=nofollow --assume-yes-for-downloads PyTaiko.py
            - name: Create Release Directory
              run: |
                  mkdir -p release
                  cp -r Graphics Sounds Videos Songs config.toml shader model release/
                  # Copy executable based on OS
                  if [ "${{ runner.os }}" == "Windows" ]; then
                    cp *.exe release/ 2>/dev/null || true
                  elif [ "${{ runner.os }}" == "macOS" ]; then
                    cp -r *.app release/ 2>/dev/null || true
                  else
                    cp *.bin release/ 2>/dev/null || true
                  fi
              shell: bash
            - name: Create Zip Archive
              run: |
                  cd release
                  if [ "${{ runner.os }}" == "Windows" ]; then
                    7z a ../PyTaiko-${{ runner.os }}-${{ runner.arch }}.zip *
                  else
                    zip -r ../PyTaiko-${{ runner.os }}-${{ runner.arch }}.zip *
                  fi
              shell: bash
            - name: Upload Artifacts
              uses: actions/upload-artifact@v4
              with:
                  name: PyTaiko-${{ runner.os }}-${{ runner.arch }}
                  path: release/
            - name: Upload Release
              uses: softprops/action-gh-release@v2
              if: github.ref == 'refs/heads/main' && github.event_name == 'push'
              with:
                  files: PyTaiko-${{ runner.os }}-${{ runner.arch }}.zip
                  name: "PyTaiko [Rolling Release]"
                  tag_name: "latest"
                  make_latest: true
              env:
                  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
