name: macOS aarch64 Build

on:
  workflow_dispatch:
env:
  CARGO_INCREMENTAL: 0
  RUST_BACKTRACE: short

jobs:
  macos-aarch64:
    runs-on: macos-14
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: install Rust stable
        run: |
          rustup install stable --profile minimal --no-self-update
          rustup default stable

      - uses: Swatinem/rust-cache@v2
        with:
          workspaces: "./backend/"
          prefix-key: "rust-stable"
          key: "macos-13"
          shared-key: "release"
      - uses: maxim-lobanov/setup-xcode@v1
        with:
          xcode-version: "15.0"
      - name: install the missing rust target
        run: |
          rustup target add aarch64-apple-darwin

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

      - uses: pnpm/action-setup@v4
        name: Install pnpm
        with:
          run_install: false

      - name: Pnpm install and check
        run: |
          pnpm i
          pnpm check --arch arm64 --sidecar-host aarch64-apple-darwin

      - name: Tauri build with Upload (cmd)
        env:
          TAG_NAME: dev
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
          TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
        run: |
          pnpm build --target aarch64-apple-darwin
          pnpm upload:osx-aarch64
