# Copyright 2025 The OpenXLA Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
name: CI
permissions:
  contents: read
on:
  workflow_dispatch:
    inputs:
      halt-for-connection:
        description: 'Should this workflow run wait for a remote connection?'
        type: choice
        required: true
        default: 'no'
        options:
          - 'yes'
          - 'no'
  pull_request:
  push:
    branches:
      - main

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
  cancel-in-progress: ${{ github.ref != 'main' }}

jobs:
  Tests:
    strategy:
      # Don't fail fast - want to see results for all builds even if one fails.
      fail-fast: false
      matrix:
        job_info: [
          {
            pool: "linux-x86-n2-16",
            container: "us-docker.pkg.dev/ml-oss-artifacts-published/ml-public-container/ml-build:latest",
            name: "XLA Linux x86 CPU",
            repo: "openxla/xla",
          },
          {
            pool: "windows-x86-n2-16",
            container: null,
            name: "XLA Windows x86 CPU",
            repo: "openxla/xla",
          },
          {
            pool: "linux-x86-n2-16",
            container: "us-docker.pkg.dev/ml-oss-artifacts-published/ml-public-container/ml-build:latest",
            name: "XLA Linux x86 CPU Bzlmod",
            repo: "openxla/xla",
          },
          {
            pool: "linux-x86-n2-16",
            container: "us-docker.pkg.dev/ml-oss-artifacts-published/ml-public-container/ml-build:latest",
            name: "XLA Linux X86 GPU ONEAPI",
            repo: "openxla/xla",
          },
          {
            pool: "linux-x86-n2-16",
            container: "us-docker.pkg.dev/ml-oss-artifacts-published/ml-public-container/ml-build:latest",
            name: "XLA Linux x86 GPU Hermetic ROCm",
            repo: "openxla/xla",
          },
          {
            pool: "linux-x86-g2-16-l4-1gpu",
            container: "us-docker.pkg.dev/ml-oss-artifacts-published/ml-public-container/ml-build:latest",
            name: "XLA Linux x86 GPU L4",
            repo: "openxla/xla",
          },
          {
            pool: "linux-arm64-c4a-16",
            container: "us-docker.pkg.dev/ml-oss-artifacts-published/ml-public-container/ml-build-arm64:latest",
            name: "XLA Linux ARM64 CPU",
            repo: "openxla/xla",
          },
          {
            pool: "linux-x86-n2-16",
            container: "gcr.io/tensorflow-sigs/build:latest-python3.11",
            name: "JAX Linux x86 CPU Bzlmod",
            repo: "jax-ml/jax",
          },
          {
            pool: "windows-x86-n2-16",
            container: null,
            name: "JAX Windows x86 CPU",
            repo: "jax-ml/jax",
          },
          {
            pool: "linux-x86-g2-16-l4-1gpu",
            container: "gcr.io/tensorflow-sigs/build:latest-python3.12",
            name: "JAX Linux x86 GPU L4",
            repo: "jax-ml/jax",
          },
        ]
    name: ${{ matrix.job_info.name }}
    runs-on: ${{ matrix.job_info.pool }}
    container: ${{ matrix.job_info.container }} # zizmor: ignore[unpinned-images]
    defaults:
      run:
        shell: bash
    steps:
      - name: "Checking out openxla/xla"
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          path: "openxla/xla"
          persist-credentials: false
      - name: Checking out ${{ matrix.job_info.repo }}
        if: ${{ matrix.job_info.repo != 'openxla/xla' }}
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          repository: ${{ matrix.job_info.repo }}
          path: ${{ matrix.job_info.repo }}
          persist-credentials: false
      - name: "Wait For Connection"
        uses: google-ml-infra/actions/ci_connection@7f5ca0c263a81ed09ea276524c1b9192f1304e3c
        with:
          halt-dispatch-input: ${{ inputs.halt-for-connection }}
      - name: "Run build.py"
        working-directory: ${{ matrix.job_info.repo }}
        timeout-minutes: 60
        run: |
          # Shellcheck doesn't understand GitHub Actions expressions and incorrectly
          # thinks this comparison will always fail.
          # shellcheck disable=SC2193
          if [[ "${{ matrix.job_info.pool }}" == *"windows"* ]]; then
            python "$GITHUB_WORKSPACE"\\openxla\\xla\\build_tools\\ci\\build.py --build="${{ matrix.job_info.name }}_github_actions"
          else
            "$GITHUB_WORKSPACE"/openxla/xla/build_tools/ci/build.py --build="${{ matrix.job_info.name }}_github_actions"
          fi



































































