Run Locust Load tests #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run Locust Load tests | |
on: | |
workflow_dispatch: | |
inputs: | |
locust_file: | |
description: 'Locust file to use' | |
required: true | |
default: 'locustfile.py' | |
type: string | |
host: | |
description: 'Host (e.g. https://www.example.com)' | |
required: true | |
default: 'https://www.example.com' | |
type: string | |
users: | |
description: 'Number of users (peak concurrency)' | |
required: true | |
default: 100 | |
type: number | |
rate: | |
description: 'Spawn rate (users started/second)' | |
required: true | |
default: 10 | |
type: number | |
runtime: | |
description: 'Run time (e.g. 20, 20s, 3m, 2h, 1h20m, 3h30m10s, etc.)' | |
required: true | |
default: '30s' | |
type: string | |
workers: | |
description: 'amount of worker nodes' | |
required: true | |
default: 4 | |
type: number | |
environment: | |
description: 'Environment to test' | |
default: 'staging' | |
options: | |
- staging | |
- production | |
type: environment | |
required: true | |
summary: | |
description: only output summary stats | |
type: boolean | |
default: true | |
required: true | |
jobs: | |
log-the-inputs: | |
name: LOG the inputs | |
runs-on: ubuntu-latest | |
environment: ${{ github.event.inputs.environment }} | |
env: | |
LOCUST_LOCUSTFILE: ${{ github.event.inputs.locust_file }} | |
LOCUST_HOST: ${{ github.event.inputs.host }} | |
LOCUST_USERS: ${{ github.event.inputs.users }} | |
LOCUST_SPAWN_RATE: ${{ github.event.inputs.rate }} | |
LOCUST_RUN_TIME: ${{ github.event.inputs.runtime }} | |
ENVIRONMENT: ${{ github.event.inputs.environment }} | |
LOCUST_WORKERS: ${{ github.event.inputs.workers }} | |
LOCUST_HEADLESS: true | |
LOCUST_ONLY_SUMMARY: ${{ github.event.inputs.summary }} | |
steps: | |
- name: Adding markdown | |
run: | | |
echo "### Run load tests" >> $GITHUB_STEP_SUMMARY | |
echo "| Locust File | Host | Users | Rate | Runtime | Workers | Environment | Summary |" >> $GITHUB_STEP_SUMMARY | |
echo "|--------------------|--------------|---------------|--------------------|------------------|----------|--------------|---------|" >> $GITHUB_STEP_SUMMARY | |
echo "| $LOCUST_LOCUSTFILE | $LOCUST_HOST | $LOCUST_USERS | $LOCUST_SPAWN_RATE | $LOCUST_RUN_TIME | $LOCUST_WORKERS | $ENVIRONMENT | $LOCUST_ONLY_SUMMARY |" >> $GITHUB_STEP_SUMMARY | |
load-test: | |
name: Load test url | |
runs-on: ubuntu-latest | |
needs: log-the-inputs | |
environment: ${{ github.event.inputs.environment }} | |
timeout-minutes: 30 | |
env: | |
LOCUST_LOCUSTFILE: ${{ github.event.inputs.locust_file }} | |
LOCUST_HOST: ${{ github.event.inputs.host }} | |
LOCUST_USERS: ${{ github.event.inputs.users }} | |
LOCUST_SPAWN_RATE: ${{ github.event.inputs.rate }} | |
LOCUST_RUN_TIME: ${{ github.event.inputs.runtime }} | |
ENVIRONMENT: ${{ github.event.inputs.environment }} | |
LOCUST_WORKERS: ${{ github.event.inputs.workers }} | |
LOCUST_HEADLESS: true | |
LOCUST_ONLY_SUMMARY: ${{ github.event.inputs.summary }} | |
steps: | |
- name: Checkout 🛎️ | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
with: | |
fetch-depth: 0 | |
- name: 'Load test url ${{ github.event.inputs.host }}' | |
run: LOCUST_LOCUSTFILE=${{ github.event.inputs.locust_file }} LOCUST_HOST=${{ github.event.inputs.host }} LOCUST_USERS=${{ github.event.inputs.users }} LOCUST_SPAWN_RATE=${{ github.event.inputs.rate }} LOCUST_RUN_TIME=${{ github.event.inputs.runtime }} LOCUST_HEADLESS=true LOCUST_ONLY_SUMMARY=${{ github.event.inputs.summary }} docker compose -f locust/docker-compose.yml up --scale worker=${{ github.event.inputs.workers }} --abort-on-container-exit | |
- name: Upload HTML report | |
if: always() | |
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4 | |
with: | |
name: locust-report | |
path: locust/reports | |
retention-days: 10 | |
- name: Print CSV reports | |
if: always() | |
run: | | |
echo "### Load CSV test reports" >> $GITHUB_STEP_SUMMARY | |
echo "#### Exceptions" >> $GITHUB_STEP_SUMMARY | |
cat locust/reports/report_exceptions.csv >> $GITHUB_STEP_SUMMARY | |
echo "#### Failures" >> $GITHUB_STEP_SUMMARY | |
cat locust/reports/report_failures.csv >> $GITHUB_STEP_SUMMARY | |
echo "#### Stats history" >> $GITHUB_STEP_SUMMARY | |
cat locust/reports/report_stats_history.csv >> $GITHUB_STEP_SUMMARY | |
echo "#### Stats" >> $GITHUB_STEP_SUMMARY | |
cat locust/reports/report_stats.csv >> $GITHUB_STEP_SUMMARY | |
- name: Print HTML report | |
if: always() | |
run: | | |
echo "### Load HTML test reports" >> $GITHUB_STEP_SUMMARY | |
echo "#### HTML report" >> $GITHUB_STEP_SUMMARY | |
cat locust/reports/report.html >> $GITHUB_STEP_SUMMARY |