name: Setup ONNX Runtime
description: Download and stage ONNX Runtime libraries for bindings
inputs:
  ort-version:
    description: ONNX Runtime version to download
    required: true
  dest-dir:
    description: Directory (relative to workspace) where libraries should be copied
    required: false
    default: crates/kreuzberg-node
  arch-id:
    description: Override architecture (x64|arm64). Defaults to runner architecture.
    required: false
    default: ""
  strategy:
    description: "ORT linking strategy: 'system' (dynamic link, default) or 'bundled' (static link via ort-bundled cargo feature)"
    required: false
    default: system
runs:
  using: composite
  steps:
    - name: Cache ONNX Runtime
      id: cache-onnx
      uses: actions/cache@v5
      with:
        path: |
          ${{ runner.temp }}/onnxruntime
        key: onnx-v2-${{ runner.os }}-${{ inputs.arch-id != '' && inputs.arch-id || runner.arch }}-${{ inputs.ort-version }}
        restore-keys: |
          onnx-v2-${{ runner.os }}-${{ inputs.arch-id != '' && inputs.arch-id || runner.arch }}-
          onnx-v2-${{ runner.os }}-

    - name: Prepare ONNX Runtime (Linux)
      if: runner.os == 'Linux'
      shell: bash
      run: scripts/ci/actions/setup-onnx-runtime/linux.sh "${{ inputs.ort-version }}" "${{ inputs.dest-dir }}" "${{ inputs.arch-id }}" "${{ inputs.strategy }}"

    - name: Prepare ONNX Runtime (macOS)
      if: runner.os == 'macOS'
      shell: bash
      run: scripts/ci/actions/setup-onnx-runtime/macos.sh "${{ inputs.ort-version }}" "${{ inputs.dest-dir }}" "${{ inputs.arch-id }}" "${{ inputs.strategy }}"

    - name: Prepare ONNX Runtime (Windows)
      if: runner.os == 'Windows'
      shell: pwsh
      run: scripts/ci/actions/setup-onnx-runtime/windows.ps1 "${{ inputs.ort-version }}" "${{ inputs.dest-dir }}" "${{ inputs.arch-id }}" "${{ inputs.strategy }}"
