name: Build Artifacts

on:
  workflow_dispatch:
    inputs:
      version:
        description: 'Version label (e.g. dev, 0.3.0-test)'
        required: false
        default: 'dev'

jobs:
  build-windows:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Install system dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-recommends zip libportaudio2 nsis msitools

      - name: Cross-build Windows distribution
        run: |
          chmod +x build-dist-windows.sh
          ./build-dist-windows.sh "v${{ inputs.version }}"

      - uses: actions/upload-artifact@v3
        with:
          name: LedGrab-${{ inputs.version }}-win-x64
          path: |
            build/LedGrab-*.zip
            build/LedGrab-*-setup.exe
          retention-days: 90

  build-linux:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Install system dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-recommends libportaudio2

      - name: Build Linux distribution
        run: |
          chmod +x build-dist.sh
          ./build-dist.sh "v${{ inputs.version }}"

      - uses: actions/upload-artifact@v3
        with:
          name: LedGrab-${{ inputs.version }}-linux-x64
          path: build/LedGrab-*.tar.gz
          retention-days: 90
