name: 'Build CreamLinux'

on:
  push:
    branches: ['main']
  pull_request:
    branches: ['main']

env:
  CARGO_TERM_COLOR: always

jobs:
  build-tauri:
    strategy:
      fail-fast: false
      matrix:
        platform: [ubuntu-latest]

    runs-on: ${{ matrix.platform }}
    steps:
      - uses: actions/checkout@v4

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

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

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          workspaces: 'src-tauri -> target'
          cache-on-failure: true

      - name: Install system dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf

      - name: Install frontend dependencies
        run: npm install

      - name: Run ESLint
        run: npm run lint

      - name: Build the app
        run: npm run tauri build

      - name: Upload binary artifacts
        uses: actions/upload-artifact@v4
        with:
          name: creamlinux-${{ runner.os }}
          path: |
            src-tauri/target/release/creamlinux
            src-tauri/target/release/bundle/deb/*.deb
            src-tauri/target/release/bundle/appimage/*.AppImage
