name: "Nightly Builds"

on:
  push:
    branches:
      - '*'
  pull_request:
    branches:
      - '*'
  workflow_dispatch:

jobs:
  publish-tauri:
    strategy:
      fail-fast: false
      matrix:
        platform: [ubuntu-latest, windows-latest]

    runs-on: ${{ matrix.platform }}
    env:
      TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
    steps:
      - uses: actions/checkout@v4
      
      - name: setup node
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: install Rust stable
        uses: dtolnay/rust-toolchain@stable

      - name: Rust cache
        uses: swatinem/rust-cache@v2
        with:
          workspaces: "./src-tauri -> target"

      - name: pnpm cache
        uses: actions/cache@v3
        with:
          path: ~/.pnpm-store
          key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-

      - name: install dependencies (ubuntu only)
        if: matrix.platform == 'ubuntu-latest'
        run: |
          sudo apt update
          sudo apt install libwebkit2gtk-4.1-dev build-essential curl wget file libssl-dev libayatana-appindicator3-dev librsvg2-dev libasound2-dev
          echo "PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig" >> $GITHUB_ENV

      - name: install frontend dependencies
        run: npm install -g pnpm && pnpm install

      - uses: tauri-apps/tauri-action@v0

      - name: Publish Windows Artifact
        if: matrix.platform == 'windows-latest'
        uses: actions/upload-artifact@v3
        with:
          name: build-windows-msi
          path: src-tauri/target/release/bundle/msi/*.msi

      - name: Publish Ubuntu Artifacts
        if: matrix.platform == 'ubuntu-latest'
        uses: actions/upload-artifact@v3
        with:
          name: build-ubuntu-deb
          path: src-tauri/target/release/bundle/deb/*.deb
      - uses: actions/upload-artifact@v3
        if: matrix.platform == 'ubuntu-latest'
        with:
          name: build-ubuntu-appimage
          path: src-tauri/target/release/bundle/appimage/*.AppImage
      - uses: actions/upload-artifact@v3
        if: matrix.platform == 'ubuntu-latest'
        with:
          name: build-ubuntu-rpm
          path: src-tauri/target/release/bundle/rpm/*.rpm
