name: 'Build CreamLinux'

on:
  push:
    branches: [main, master, develop]
  pull_request:
    branches: [main, master, develop]
  workflow_dispatch: # Allows manual triggering

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        include:
          - platform: 'ubuntu-22.04' # Stable Debian-based release
            args: ''

    runs-on: ${{ matrix.platform }}

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: lts/*
          cache: 'npm'

      - name: Install Rust stable
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

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

      - name: Install system dependencies (Ubuntu)
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            libwebkit2gtk-4.1-dev \
            libayatana-appindicator3-dev \
            librsvg2-dev \
            patchelf \
            build-essential \
            curl \
            wget \
            file \
            libssl-dev \
            libgtk-3-dev

      - name: Install frontend dependencies
        run: npm ci

      - name: Build Tauri app
        uses: tauri-apps/tauri-action@v0
        # env:
        # No GITHUB_TOKEN since we're not creating releases
        # TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
        # TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
        with:
          # Build configuration
          projectPath: '.'
          includeDebug: false
          includeRelease: true
          includeUpdaterJson: false
          tauriScript: 'npm run tauri'
          args: ${{ matrix.args }}

          # No release configuration - just build artifacts
          # Omitting tagName, releaseName, and releaseId means no release creation

      - name: Upload build artifacts
        uses: actions/upload-artifact@v4
        with:
          name: creamlinux-ubuntu-20.04-artifacts
          path: |
            src-tauri/target/release/bundle/
            src-tauri/target/release/creamlinux
            src-tauri/target/release/creamlinux.exe
          retention-days: 30
          if-no-files-found: warn

      - name: Upload AppImage (if exists)
        uses: actions/upload-artifact@v4
        with:
          name: creamlinux-appimage
          path: |
            src-tauri/target/release/bundle/appimage/*.AppImage
          retention-days: 30
          if-no-files-found: ignore

      - name: Upload DEB package (if exists)
        uses: actions/upload-artifact@v4
        with:
          name: creamlinux-deb
          path: |
            src-tauri/target/release/bundle/deb/*.deb
          retention-days: 30
          if-no-files-found: ignore
