name: Release Tamigo CLI

on:
  release:
    types: [published]

jobs:
  release-linux:
    name: Build & Release Linux
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.12'
      - name: Install dependencies
        run: |
          pip install -r requirements.txt
      - name: Build
        run: |
          pyinstaller --onefile --name tamigo-cli tamigo.py
      - name: Rename for release
        run: mv dist/tamigo-cli dist/tamigo-cli-linux
      - name: Upload to Release
        uses: softprops/action-gh-release@v2
        with:
          files: dist/tamigo-cli-linux
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  release-windows:
    name: Build & Release Windows
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Build Windows executable via Docker (Modern & Robust)
        run: |
          CONTAINER_NAME="rel-builder-${{ github.run_id }}"
          docker rm -f $CONTAINER_NAME || true
          
          # Using burningtyger/pyinstaller-windows for better path handling
          docker create --name $CONTAINER_NAME burningtyger/pyinstaller-windows "pip install -r requirements.txt && pyinstaller --onefile --name tamigo-cli tamigo.py"
          
          docker cp . $CONTAINER_NAME:/src
          docker start -a $CONTAINER_NAME
          docker cp $CONTAINER_NAME:/src/dist .
          docker rm $CONTAINER_NAME
          
      - name: Debug - List output files
        run: ls -R dist/
      - name: Rename for release
        run: mv dist/*.exe dist/tamigo-cli-windows.exe
      - name: Upload to Release
        uses: softprops/action-gh-release@v2
        with:
          files: dist/tamigo-cli-windows.exe
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
