name: Nightly load test

on:
  schedule:
    - cron: '0 0 * * 1-5'
  workflow_call:
  workflow_dispatch:

  pull_request:
    paths:
      - ".github/workflows/load_test.yaml"

env:
  AWS_DEFAULT_REGION: us-east-1
  AWS_ACCESS_KEY_ID: ${{ secrets.S3_AWS_ACCESS_KEY_ID }}
  AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_AWS_SECRET_ACCESS_KEY }}

jobs:
  load-tests:
    concurrency:
      group: ${{ github.workflow }}-${{ github.job }}-${{ github.head_ref || github.run_id }}
      cancel-in-progress: true
    runs-on:
      group: aws-g6-12xl-plus-priv-cache
    env:
      DOCKER_VOLUME: /cache
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Install Python 3.11
        uses: actions/setup-python@v2
        with:
          python-version: 3.11

      - name: Install poetry
        run: |
          curl -sSL https://install.python-poetry.org | python3 -
          export PATH="$HOME/.local/bin:$PATH"
          poetry --version

      - name: Run bench test
        run: |
          export PATH="$HOME/.local/bin:$PATH"
          cd load_tests
          poetry install
          poetry run python benchmarks.py --sha ${{ github.sha }} --results-file "s3://text-generation-inference-ci/benchmarks/ci/${{ github.sha }}.parquet"
        shell: bash
        env:
          HF_TOKEN: ${{ secrets.HF_TOKEN_BENCHMARK }}
