name: Flaky test debugging
run-name: Flaky test debugging - ${{ inputs.flaky_test }} (${{ inputs.flaky_test_runs_per_job }}x${{ inputs.flaky_test_parallel_jobs }})
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true
on:
  workflow_dispatch:
    inputs:
      flaky_test:
        required: true
        type: string
        description: Test to run
      flaky_test_runs_per_job:
        required: false
        default: 8
        type: number
        description: Number of times to run the test
      flaky_test_parallel_jobs:
        required: false
        default: 32
        type: number
        description: Number of parallel jobs to run
jobs:
  build:
    name: Build Citus
    runs-on: ubuntu-latest
    container:
      image: ${{ vars.build_image_name }}:${{ vars.pg15_version  }}${{ vars.image_suffix }}
      options: --user root
    steps:
    - uses: actions/checkout@v4
    - name: Configure, Build, and Install
      run: |
        echo "PG_MAJOR=${PG_MAJOR}" >> $GITHUB_ENV
        ./ci/build-citus.sh
      shell: bash
    - uses: actions/upload-artifact@v4.6.0
      with:
        name: build-${{ env.PG_MAJOR }}
        path: |-
          ./build-${{ env.PG_MAJOR }}/*
          ./install-${{ env.PG_MAJOR }}.tar
  prepare_parallelization_matrix:
    name: Prepare parallelization matrix
    runs-on: ubuntu-latest
    outputs:
      json: ${{ steps.parallelization.outputs.json }}
    steps:
      - uses: actions/checkout@v4
      - uses: "./.github/actions/parallelization"
        id: parallelization
        with:
          count: ${{ inputs.flaky_test_parallel_jobs }}
  test_flakyness:
    name: Test flakyness
    runs-on: ubuntu-latest
    container:
      image: ${{ vars.fail_test_image_name }}:${{ vars.pg15_version  }}${{ vars.image_suffix }}
      options: --user root
    needs:
      [build, prepare_parallelization_matrix]
    env:
      test: "${{ inputs.flaky_test }}"
      runs: "${{ inputs.flaky_test_runs_per_job }}"
      skip: false
    strategy:
      fail-fast: false
      matrix: ${{ fromJson(needs.prepare_parallelization_matrix.outputs.json) }}
    steps:
    - uses: actions/checkout@v4
    - uses: "./.github/actions/setup_extension"
    - name: Run minimal tests
      run: |-
          gosu circleci src/test/regress/citus_tests/run_test.py ${{ env.test }} --repeat ${{ env.runs }} --use-whole-schedule-line
      shell: bash
    - uses: "./.github/actions/save_logs_and_results"
      if: always()
      with:
          folder: check_flakyness_parallel_${{ matrix.id }}
