name: Release
on:
  push:
    tags: ['v*']
jobs:
  build-server:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6
      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
      - name: Cache Cargo dependencies
        uses: actions/cache@v6
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
      - name: Build server binary
        run: cargo build --release -p clean-copy-server
      - name: Create release artifact archive
        run: |
          tar -czf clean-copy-server-linux-x86_64.tar.gz -C target/release clean-copy-server
      - name: Upload release artifacts
        uses: actions/upload-artifact@v3
        with:
          name: server-release
          path: clean-copy-server-linux-x86_64.tar.gz
  build-tauri:
    runs-on: windows-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6
      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
      - name: Install Node.js
        uses: actions/setup-node@v6
        with:
          node-version: "20"
      - name: Install frontend dependencies
        run: npm ci
        working-directory: app
      - name: Build Tauri app
        run: npx tauri build
        working-directory: app
      - name: Upload release artifacts
        uses: actions/upload-artifact@v4
        with:
          name: tauri-release
          path: |
            app/src-tauri/target/release/clean-copy.exe
            app/src-tauri/target/release/bundle/msi/*.msi
