# 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.
# ============================================================================
# .github/workflows/postsubmit_benchmark.yml
name: Postsubmit Benchmarks

on:
  # Required for internal services to invoke workflow runs.
  # Required inputs: benchmark_filter, environment_filter, custom_metadata.
  workflow_dispatch:
    inputs:
      benchmark_filter:
        description: "Regex to filter by benchmark name (e.g., 'gemma3_.*')."
        required: false
        type: string
        default: ""
      environment_filter:
        description: "Regex to filter by environment configuration ID (e.g., 'gpu_.*')."
        required: false
        type: string
        default: ""
      custom_metadata:
        description: "JSON string of metadata to append to the benchmark result. Overwrites static metadata from the registry but is overwritten by dynamic metadata from the workload."
        required: false
        type: string
        default: "{}"

  push:
    branches:
      - main

permissions:
  contents: read
  pull-requests: write

concurrency:
  # Group by workflow name and branch to ensure runs execute sequentially.
  # This prevents parallel postsubmit runs from clashing and ensures accurate
  # reporting history.
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: false

jobs:
  run_benchmarks:
    name: Run XLA Postsubmit Benchmarks
    uses: google-ml-infra/bap/.github/workflows/run-benchmarks.yaml@fd37d1f65a06f0124d9d2022d97efa8dc8812557 # main
    with:
      registry_file: "xla/tools/benchmarks/benchmark_registry.pbtxt"
      tag_filter: "postsubmit"
      bap_ref: "fd37d1f65a06f0124d9d2022d97efa8dc8812557"
      publish_metrics: true
      pub_sub_gcp_project_id: "ml-oss-benchmarking-production"
      pub_sub_gcp_topic_id: "public-results-prod"
      benchmark_filter: ${{ inputs.benchmark_filter || '' }}
      environment_filter: ${{ inputs.environment_filter || '' }}
      custom_metadata: ${{ inputs.custom_metadata || '{}' }}