name: Release Desktop Apps

on:
  push:
    tags: ['v*']

jobs:
  build-linux:
    runs-on: linux
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 20 }
      - uses: dtolnay/rust-toolchain@stable
      - name: Install system deps
        run: sudo apt-get update && sudo apt-get install -y libwebkit2gtk-4.1-dev libgtk-3-dev libappindicator3-dev librsvg2-dev patchelf
      - name: Build frontend
        run: cd web && npm ci && npm run build
      - name: Build Tauri bundles
        env:
          NO_STRIP: "true"
        run: cd web && npx tauri build
      - name: Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: linux-bundles
          path: |
            web/src-tauri/target/release/bundle/appimage/*.AppImage
            web/src-tauri/target/release/bundle/deb/*.deb
            web/src-tauri/target/release/bundle/rpm/*.rpm

  build-windows:
    runs-on: windows
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 20 }
      - uses: dtolnay/rust-toolchain@stable
      - name: Build frontend
        run: cd web; npm ci; npm run build
      - name: Build Tauri bundles
        run: cd web; npx tauri build
      - name: Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: windows-bundles
          path: |
            web/src-tauri/target/release/bundle/msi/*.msi
            web/src-tauri/target/release/bundle/nsis/*.exe

  release:
    needs: [build-linux, build-windows]
    runs-on: linux
    steps:
      - uses: actions/download-artifact@v4
      - name: Create release
        uses: softprops/action-gh-release@v2
        with:
          files: |
            linux-bundles/*
            windows-bundles/*
          generate_release_notes: true
