name: Benchmark Dolt vs MySQL

on:
  repository_dispatch:
    types: [ release-dolt ]
  workflow_dispatch:
    inputs:
      version:
        description: 'SemVer format release tag, i.e. 0.24.5'
        required: true
        default: ''
      email:
        description: 'Email address to receive results'
        required: true
        default: ''

jobs:
  set-version-actor:
    name: Set Version and Actor
    runs-on: ubuntu-22.04
    outputs:
      version: ${{ steps.set-vars.outputs.version }}
      actor: ${{ steps.set-vars.outputs.actor }}
      actor_email: ${{ steps.set-vars.outputs.actor_email }}
    steps:
      - name: Set variables
        id: set-vars
        run: |
          echo "version=$VERSION" >> $GITHUB_OUTPUT
          echo "actor=$ACTOR" >> $GITHUB_OUTPUT
          echo "actor_email=$ACTOR_EMAIL" >> $GITHUB_OUTPUT
        env:
          VERSION: ${{ github.event.inputs.version || github.event.client_payload.version }}
          ACTOR: ${{ github.event.client_payload.actor || github.actor }}
          ACTOR_EMAIL: ${{ github.event.inputs.email }}

  benchmark-dolt-mysql:
    runs-on: ubuntu-22.04
    needs: set-version-actor
    name: Trigger Benchmark Latency and Benchmark Import K8s Workflows
    steps:
      - uses: peter-evans/repository-dispatch@v3
        if: ${{ github.event.client_payload.profile_key == '' }}
        with:
          token: ${{ secrets.REPO_ACCESS_TOKEN }}
          event-type: benchmark-latency
          client-payload: '{"from_server": "mysql", "from_version": "8.0.35", "to_server": "dolt", "to_version": "${{ needs.set-version-actor.outputs.version }}", "mode": "release", "actor": "${{ needs.set-version-actor.outputs.actor }}", "actor_email": "${{ needs.set-version-actor.outputs.actor_email }}", "template_script": "./.github/scripts/performance-benchmarking/get-mysql-dolt-job-json.sh"}'
      - uses: peter-evans/repository-dispatch@v3
        if: ${{ github.event.client_payload.profile_key != '' }}
        with:
          token: ${{ secrets.REPO_ACCESS_TOKEN }}
          event-type: benchmark-latency
          client-payload: '{"from_server": "mysql", "from_version": "8.0.35", "to_server": "dolt", "to_version": "${{ needs.set-version-actor.outputs.version }}", "profile_key": "${{ github.event.client_payload.profile_key }}", "mode": "release", "actor": "${{ needs.set-version-actor.outputs.actor }}", "actor_email": "${{ needs.set-version-actor.outputs.actor_email }}", "template_script": "./.github/scripts/performance-benchmarking/get-mysql-dolt-job-json.sh"}'
      - uses: peter-evans/repository-dispatch@v3
        with:
          token: ${{ secrets.REPO_ACCESS_TOKEN }}
          event-type: benchmark-import
          client-payload: |
            {
              "email_recipient":  "${{ needs.set-version-actor.outputs.actor_email }}",
              "version": "${{ github.sha }}",
              "run_file": "ci.yaml",
              "report": "three_way_compare.sql",
              "summary": "summary.sql",
              "commit_to_branch": "main",
              "actor": "${{ github.actor }}"
            }
      - uses: peter-evans/repository-dispatch@v3
        with:
          token: ${{ secrets.REPO_ACCESS_TOKEN }}
          event-type: benchmark-systab
          client-payload: |
            {
              "email_recipient":  "${{ needs.set-version-actor.outputs.actor_email }}",
              "version": "${{ github.sha }}",
              "run_file": "systab.yaml",
              "report": "systab.sql",
              "summary": "systab_summary.sql",
              "commit_to_branch": "main",
              "actor": "${{ github.actor }}"
            }
