# Do not edit this YAML file. This file is generated automatically by executing
# python scripts/split_tox_gh_actions/split_tox_gh_actions.py
# The template responsible for it is in
# scripts/split_tox_gh_actions/templates/test_orchestrator.jinja
#
# Top-level test orchestrator. It runs every test group (each a reusable
# workflow) in a single run, then combines their coverage and reports it once.
name: Test

on:
  push:
    branches:
      - master
      - release/**
      - major/**

  pull_request:

# Cancel in progress workflows on pull_requests.
concurrency:
  group: {% raw %}${{ github.workflow }}-${{ github.head_ref || github.run_id }}{% endraw %}
  cancel-in-progress: true

permissions:
  contents: read
  actions: read
  checks: write
  pull-requests: write
  statuses: write

# To temporarily skip a group for unblocking a release,
# add `if: false` to its job below, e.g.:
#
#   dbs:
#     name: DBs
#     if: false  # TEMP: skipping, see PR #xxxx
#     uses: ./.github/workflows/test-integrations-dbs.yml
#     secrets: inherit
jobs:
{% for g in orchestrated_groups %}
  {{ g.id }}:
    name: {{ g.name }}
    uses: ./.github/workflows/test-integrations-{{ g.slug }}.yml
    secrets: inherit
{% endfor %}

  report:
    name: Combine and report coverage
    needs:
{% for g in orchestrated_groups %}
      - {{ g.id }}
{% endfor %}
    # Report whatever coverage exists, even if some test jobs failed.
    if: {% raw %}${{ !cancelled() }}{% endraw %}
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
      - name: Install uv
        uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
      - name: Download coverage data
        # Artifacts from the reusable test workflows live in this same run.
        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          pattern: coverage-*
          merge-multiple: true
      - name: Combine coverage and generate XML
        run: |
          uv sync
          # relative_files + [tool.coverage.paths] let the 3.6/3.7 container and
          # the runner data files merge into one source tree.
          uv run coverage combine .coverage-sentry-*
          uv run coverage xml
      - name: Report coverage and test results
        uses: getsentry/codecov-action@d90e69cdf071dfbb0430159125321dc09c424d4c # main
        with:
          token: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %}
          files: coverage.xml
          junit-xml-pattern: .junitxml-*
          base-branch: master
          post-pr-comment: true
          verbose: true

  check-required:
    name: All tests passed
    needs:
{% for g in orchestrated_groups %}
      - {{ g.id }}
{% endfor %}
    # Always run so it can gate merges even when a dependency failed.
    if: always()
    runs-on: ubuntu-22.04
    steps:
      - name: Check for failures
        if: {% raw %}${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}{% endraw %}
        run: |
          echo "One of the test jobs failed. You may need to re-run it." && exit 1
