# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

name: Framework Matrix Pipeline

on:
  workflow_call:
    inputs:
      framework:
        description: 'Framework name (vllm, sglang, trtllm)'
        required: true
        type: string
      target:
        description: 'Target stage for Docker rendering'
        required: true
        type: string
      platform:
        description: 'Docker platform(s) to build (e.g. linux/amd64,linux/arm64)'
        required: false
        type: string
        default: 'linux/amd64,linux/arm64'
      cuda_versions:
        description: 'CUDA versions to build (JSON array, e.g., ["12.9", "13.0"])'
        required: true
        type: string
      build_timeout_minutes:
        description: 'Timeout in minutes for the build step'
        required: false
        type: number
        default: 60
      run_cpu_only_tests:
        description: 'Whether to run CPU-only tests'
        required: false
        type: boolean
        default: true
      cpu_only_test_markers:
        description: 'CPU-only pytest markers'
        required: false
        type: string
      cpu_only_test_timeout_minutes:
        description: 'Timeout in minutes for CPU tests'
        required: false
        type: number
        default: 10
      cpu_parallel_mode:
        description: 'pytest-xdist mode for CPU-only tests: auto, none/0, or a worker count'
        required: false
        type: string
        default: 'auto'
      run_single_gpu_tests:
        description: 'Whether to run single GPU tests'
        required: false
        type: boolean
        default: true
      single_gpu_test_markers:
        description: 'Single GPU pytest markers'
        required: false
        type: string
      single_gpu_test_timeout_minutes:
        description: 'Timeout in minutes for single GPU tests'
        required: false
        type: number
        default: 30
      run_multi_gpu_tests:
        description: 'Whether to run multi-gpu tests'
        required: false
        type: boolean
        default: true
      multi_gpu_test_markers:
        description: 'Multi GPU pytest markers'
        required: false
        type: string
      multi_gpu_test_timeout_minutes:
        description: 'Timeout in minutes for multi GPU tests'
        required: false
        type: number
        default: 30
      copy_to_acr:
        description: 'Whether to copy images to ACR'
        required: false
        type: boolean
        default: true
      copy_timeout_minutes:
        description: 'Timeout in minutes for the copy to ACR step'
        required: false
        type: number
        default: 10
      builder_name:
        description: 'Buildkit builder name'
        required: true
        type: string
      extra_tags:
        description: 'Additional tags (newline-separated)'
        required: false
        type: string
        default: ''
      build_image:
        description: 'Whether to build image'
        required: false
        type: boolean
        default: true
      no_cache:
        description: 'Disable Docker build cache'
        required: false
        type: boolean
        default: false
      push_image:
        description: 'Push image to registry'
        required: false
        type: boolean
        default: true
      make_efa:
        description: 'Enable AWS EFA support in the build'
        required: false
        type: boolean
        default: false
      show_summary:
        description: 'Show summary'
        required: false
        type: boolean
        default: false
      fresh_builder:
        description: 'Always create a fresh K8s BuildKit builder (skip remote worker routing)'
        required: false
        type: boolean
        default: false
    secrets:
      AWS_DEFAULT_REGION:
        required: true
      AWS_ACCOUNT_ID:
        required: true
      AZURE_ACR_HOSTNAME:
        required: true
      AZURE_ACR_USER:
        required: true
      AZURE_ACR_PASSWORD:
        required: true
      SCCACHE_S3_BUCKET:
        required: false
      AWS_ACCESS_KEY_ID:
        required: false
      AWS_SECRET_ACCESS_KEY:
        required: false
      HF_TOKEN:
        required: false

jobs:
  pipeline:
    strategy:
      fail-fast: false
      matrix:
        cuda_version: ${{ fromJson(inputs.cuda_versions) }}
    # This name weirdly shows in the checks overview, but not once you dive into
    # a specific workflow. Keeping it as a short placeholder
    name: matrix
    uses: ./.github/workflows/build-test-distribute-flavor.yml
    with:
      framework: ${{ inputs.framework }}
      platform: ${{ inputs.platform }}
      target: ${{ inputs.target }}
      cuda_version: ${{ matrix.cuda_version }}
      extra_tags: ${{ inputs.extra_tags }}
      no_cache: ${{ inputs.no_cache }}
      fresh_builder: ${{ inputs.fresh_builder }}
      builder_name: ${{ inputs.builder_name }}
      build_image: ${{ inputs.build_image }}
      build_timeout_minutes: ${{ inputs.build_timeout_minutes }}
      push_image: ${{ inputs.push_image }}
      run_cpu_only_tests: ${{ inputs.run_cpu_only_tests }}
      cpu_only_test_markers: ${{ inputs.cpu_only_test_markers }}
      cpu_only_test_timeout_minutes: ${{ inputs.cpu_only_test_timeout_minutes }}
      cpu_parallel_mode: ${{ inputs.cpu_parallel_mode }}
      run_single_gpu_tests: ${{ inputs.run_single_gpu_tests }}
      single_gpu_test_markers: ${{ inputs.single_gpu_test_markers }}
      single_gpu_test_timeout_minutes: ${{ inputs.single_gpu_test_timeout_minutes }}
      run_multi_gpu_tests: ${{ inputs.run_multi_gpu_tests }}
      multi_gpu_test_markers: ${{ inputs.multi_gpu_test_markers }}
      multi_gpu_test_timeout_minutes: ${{ inputs.multi_gpu_test_timeout_minutes }}
      copy_to_acr: ${{ inputs.copy_to_acr }}
      copy_timeout_minutes: ${{ inputs.copy_timeout_minutes }}
      make_efa: ${{ inputs.make_efa }}
      show_summary: ${{ inputs.show_summary }}
    secrets: inherit
