name: Build

on:
  workflow_dispatch:

jobs:
  build:
    name: ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      - uses: actions/cache@v4
        continue-on-error: false
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-build-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-build-
      - uses: extractions/setup-just@v2
      - name: Install Cargo Bundle
        run: cargo install --git https://github.com/Leinnan/cargo-bundler
      - name: Build
        working-directory: crates/rpack_egui
        run: |
          just bundle
      - name: Mac build
        if: startsWith(runner.os, 'macos')
        working-directory: crates/rpack_egui
        run: just create_mac_installer
      - name: Mac artifacts
        if: startsWith(runner.os, 'macos')
        run: |
          mkdir artifacts
          mv crates/rpack_egui/RpackInstaller.pkg artifacts/RpackInstaller.pkg
      - name: Copy artifacts
        if: ${{ !startsWith(runner.os, 'macos') }}
        run: |
          mkdir artifacts
          cp cp -r target/release/bundle/*/* artifacts/
      - uses: actions/upload-artifact@v4
        with:
          name: ${{ runner.os }}
          path: artifacts
