name: clice

on:
  workflow_call:

jobs:
  publish-clice:
    strategy:
      fail-fast: false
      matrix:
        include:
          # Native builds
          - os: windows-2025
            artifact_name: clice.zip
            asset_name: clice-x64-windows-msvc.zip
            symbol_artifact_name: clice-symbol.zip
            symbol_asset_name: clice-x64-windows-msvc-symbol.zip

          - os: ubuntu-24.04
            artifact_name: clice.tar.gz
            asset_name: clice-x86_64-linux-gnu.tar.gz
            symbol_artifact_name: clice-symbol.tar.gz
            symbol_asset_name: clice-x86_64-linux-gnu-symbol.tar.gz

          - os: macos-15
            artifact_name: clice.tar.gz
            asset_name: clice-arm64-macos-darwin.tar.gz
            symbol_artifact_name: clice-symbol.tar.gz
            symbol_asset_name: clice-arm64-macos-darwin-symbol.tar.gz

          # Cross-compilation builds
          - os: macos-15
            target_triple: x86_64-apple-darwin
            pixi_env: cross-macos-x64
            artifact_name: clice.tar.gz
            asset_name: clice-x86_64-macos-darwin.tar.gz
            symbol_artifact_name: clice-symbol.tar.gz
            symbol_asset_name: clice-x86_64-macos-darwin-symbol.tar.gz

          - os: ubuntu-24.04
            target_triple: aarch64-linux-gnu
            pixi_env: cross-linux-aarch64
            artifact_name: clice.tar.gz
            asset_name: clice-aarch64-linux-gnu.tar.gz
            symbol_artifact_name: clice-symbol.tar.gz
            symbol_asset_name: clice-aarch64-linux-gnu-symbol.tar.gz

          - os: windows-2025
            target_triple: aarch64-pc-windows-msvc
            pixi_env: cross-windows-arm64
            artifact_name: clice.zip
            asset_name: clice-aarch64-windows-msvc.zip
            symbol_artifact_name: clice-symbol.zip
            symbol_asset_name: clice-aarch64-windows-msvc-symbol.zip

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

    defaults:
      run:
        shell: bash

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - uses: ./.github/actions/setup-pixi
        with:
          environments: ${{ matrix.pixi_env || 'package' }}

      - name: Package (native)
        if: ${{ !matrix.target_triple }}
        run: pixi run package

      - name: Package (cross-compile)
        if: ${{ matrix.target_triple }}
        run: |
          ENV="${{ matrix.pixi_env }}"
          pixi run -e "$ENV" package-config -- \
            "-DCLICE_TARGET_TRIPLE=${{ matrix.target_triple }}"
          pixi run -e "$ENV" cmake-build

      - name: Upload Main Package to Release
        if: startsWith(github.ref, 'refs/tags/v')
        uses: svenstaro/upload-release-action@v2
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: build/RelWithDebInfo/${{ matrix.artifact_name }}
          asset_name: ${{ matrix.asset_name }}
          tag: ${{ github.ref }}
          overwrite: true

      - name: Upload Symbol Package to Release
        if: startsWith(github.ref, 'refs/tags/v')
        uses: svenstaro/upload-release-action@v2
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: build/RelWithDebInfo/${{ matrix.symbol_artifact_name }}
          asset_name: ${{ matrix.symbol_asset_name }}
          tag: ${{ github.ref }}
          overwrite: true
