# 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
      platforms:
        description: 'Platforms to build (JSON array, e.g., ["amd64", "arm64"])'
        required: true
        type: string
      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
      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, -$platform suffix auto-appended)'
        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
      build_only:
        description: 'Build and push only — skip all tests, show summary'
        required: false
        type: boolean
        default: false
      sanitized_ref_name:
        description: 'Sanitized git ref name for branch-tagged images (used with build_only)'
        required: false
        type: string
        default: ''
    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:
        platform: ${{ fromJson(inputs.platforms) }}
        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: ${{ matrix.platform }}
      target: ${{ inputs.target }}
      cuda_version: ${{ matrix.cuda_version }}
      extra_tags: ${{ inputs.extra_tags }}
      no_cache: ${{ inputs.no_cache }}
      builder_name: ${{ inputs.builder_name }}
      build_image: ${{ inputs.build_only || 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 }}
      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 && matrix.platform == 'amd64' }} # no reason to copy ARM images to ACR
      copy_timeout_minutes: ${{ inputs.copy_timeout_minutes }}
      make_efa: ${{ inputs.make_efa }}
      show_summary: ${{ inputs.build_only || inputs.show_summary }}
      build_only: ${{ inputs.build_only }}
      sanitized_ref_name: ${{ inputs.sanitized_ref_name }}
    secrets: inherit
