name: Build Electron App

on:
  workflow_dispatch:
    inputs:
      build_type:
        description: "Build type to run"
        required: true
        default: "all"
        type: choice
        options:
          - all
          - windows
          - linux

jobs:
  build-windows:
    runs-on: windows-latest
    if: github.event.inputs.build_type == 'all' || github.event.inputs.build_type == 'windows' || github.event.inputs.build_type == ''

    steps:
      - name: Checkout repository
        uses: actions/checkout@v5
        with:
          fetch-depth: 1

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

      - name: Install dependencies
        run: npm ci

      - name: Build Windows Portable
        run: npm run build:win-portable

      - name: Build Windows Installer
        run: npm run build:win-installer

      - name: Create Windows Portable zip
        run: |
          Compress-Archive -Path "release/win-unpacked/*" -DestinationPath "Termix-Windows-Portable.zip"

      - name: Upload Windows Portable Artifact
        uses: actions/upload-artifact@v4
        with:
          name: Termix-Windows-Portable
          path: Termix-Windows-Portable.zip
          retention-days: 30

      - name: Upload Windows Installer Artifact
        uses: actions/upload-artifact@v4
        with:
          name: Termix-Windows-Installer
          path: release/*.exe
          retention-days: 30

  build-linux:
    runs-on: ubuntu-latest
    if: github.event.inputs.build_type == 'all' || github.event.inputs.build_type == 'linux' || github.event.inputs.build_type == ''

    steps:
      - name: Checkout repository
        uses: actions/checkout@v5
        with:
          fetch-depth: 1

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

      - name: Install dependencies
        run: npm ci

      - name: Build Linux Portable
        run: npm run build:linux-portable

      - name: Create Linux Portable zip
        run: |
          cd release/linux-unpacked
          zip -r ../../Termix-Linux-Portable.zip *
          cd ../..

      - name: Upload Linux Portable Artifact
        uses: actions/upload-artifact@v4
        with:
          name: Termix-Linux-Portable
          path: Termix-Linux-Portable.zip
          retention-days: 30
