name: Benchmarks
on:
  workflow_dispatch:
  schedule:
    - cron: '0 5 * * *'
  push:
    tags:
      - 'v*'

concurrency: benchmarks

jobs:
  benchmark:
    name: Run Benchmarks
    runs-on: ubuntu-latest
    steps:
    - name: Run script on centcomm
      uses: appleboy/ssh-action@master
      with:
        host: centcomm.spacestation14.io
        username: robust-benchmark-runner
        key: ${{ secrets.CENTCOMM_ROBUST_BENCHMARK_RUNNER_KEY }}
        command_timeout: 100000m
        script: |
          mkdir benchmark_run_${{ github.sha }}
          cd benchmark_run_${{ github.sha }}
          git clone https://github.com/space-wizards/RobustToolbox.git repo_dir --recursive
          cd repo_dir
          git checkout ${{ github.sha }}
          cd Robust.Benchmarks
          dotnet restore
          export ROBUST_BENCHMARKS_ENABLE_SQL=1
          export ROBUST_BENCHMARKS_SQL_ADDRESS="${{ secrets.BENCHMARKS_WRITE_ADDRESS }}"
          export ROBUST_BENCHMARKS_SQL_PORT="${{ secrets.BENCHMARKS_WRITE_PORT }}"
          export ROBUST_BENCHMARKS_SQL_USER="${{ secrets.BENCHMARKS_WRITE_USER }}"
          export ROBUST_BENCHMARKS_SQL_PASSWORD="${{ secrets.BENCHMARKS_WRITE_PASSWORD  }}"
          export ROBUST_BENCHMARKS_SQL_DATABASE="benchmarks"
          export GITHUB_SHA="${{ github.sha }}"
          dotnet run --filter '*' --configuration Release
          cd ../../..
          rm -rf benchmark_run_${{ github.sha }}
