name: clice

on:
  workflow_call:

jobs:
  publish-clice:
    strategy:
      fail-fast: false
      matrix:
        include:
          - 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

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

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

      - name: Setup xmake
        uses: xmake-io/github-action-setup-xmake@v1
        with:
          xmake-version: 3.0.5
          actions-cache-folder: ".xmake-cache"
          actions-cache-key: ${{ matrix.os }}
          package-cache: true
          package-cache-key: ${{ matrix.os }}-pkg-release-v1
          build-cache: true
          build-cache-key: ${{ matrix.os }}-build-release-v1

      - uses: ./.github/actions/setup-pixi
        with:
          environments: package

      - name: Remove ci llvm toolchain on Windows
        if: runner.os == 'Windows'
        run: |
          # @see https://github.com/xmake-io/xmake/issues/7158
          xmake lua os.rmdir "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/Llvm"
          xmake lua os.rmdir "C:/Program Files/LLVM"

      - name: Package
        run: pixi run package

      - 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/xpack/clice/${{ 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/xpack/clice/${{ matrix.symbol_artifact_name }}
          asset_name: ${{ matrix.symbol_asset_name }}
          tag: ${{ github.ref }}
          overwrite: true
