name: Build Fechamento de Caixa

on:
  push:
    branches: [main]
  workflow_dispatch:

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        include:
          - platform: ubuntu-22.04
            target: deb
          - platform: windows-2022
            target: msi
          - platform: macos-14
            target: app

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

    steps:
      - uses: actions/checkout@v4

      - name: Install dependencies (Ubuntu)
        if: matrix.platform == 'ubuntu-22.04'
        run: |
          sudo apt-get update
          sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 20

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

      - name: Add targets
        run: rustup target add ${{ matrix.platform == 'windows-2022' && 'x86_64-pc-windows-gnu' || 'aarch64-apple-darwin' }}

      - name: Install frontend deps
        run: npm ci

      - name: Build
        run: npm run build

      - name: Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: fechamento-caixa-${{ matrix.platform }}
          path: |
            src-tauri/target/release/bundle/**/*
            src-tauri/target/release/fechamento-caixa*
          if-no-files-found: ignore
