Skip to content

Commit

Permalink
Handle quote marks ' " in PR titles in benchmark CI (#2877)
Browse files Browse the repository at this point in the history
* escape double quote marks in PR title

* move the pr title into the env
  • Loading branch information
martinxu9 committed Mar 20, 2024
1 parent 6a071a2 commit fa99407
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/benchmarks.yml
Expand Up @@ -119,8 +119,11 @@ jobs:
- name: Upload benchmark results
# Only run if the database creds are available in this context.
if: ${{ env.DATABASE_URL }}
run: poetry run python scripts/simple_app_benchmark_upload.py --os "${{ matrix.os }}"
--python-version "${{ matrix.python-version }}" --commit-sha "${{ github.sha }}"
--benchmark-json "${{ env.OUTPUT_FILE }}" --pr-title "${{ github.event.pull_request.title }}"
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run:
poetry run python scripts/simple_app_benchmark_upload.py --os "${{ matrix.os }}"
--python-version "${{ matrix.python-version }}" --commit-sha "${{ github.sha }}"
--benchmark-json "${{ env.OUTPUT_FILE }}"
--db-url "${{ env.DATABASE_URL }}" --branch-name "${{ github.head_ref || github.ref_name }}"
--event-type "${{ github.event_name }}" --actor "${{ github.actor }}"
14 changes: 11 additions & 3 deletions scripts/simple_app_benchmark_upload.py
Expand Up @@ -4,6 +4,7 @@

import argparse
import json
import os
from datetime import datetime

import psycopg2
Expand Down Expand Up @@ -103,7 +104,11 @@ def insert_benchmarking_data(


def main():
"""Runs the benchmarks and inserts the results."""
"""Runs the benchmarks and inserts the results.
Raises:
ValueError: If the PR title is not provided.
"""
# Get the commit SHA and JSON directory from the command line arguments
parser = argparse.ArgumentParser(description="Run benchmarks and process results.")
parser.add_argument(
Expand All @@ -127,7 +132,6 @@ def main():
parser.add_argument(
"--pr-title",
help="The PR title to insert into the database.",
required=True,
)
parser.add_argument(
"--branch-name",
Expand All @@ -146,6 +150,10 @@ def main():
)
args = parser.parse_args()

pr_title = args.pr_title or os.getenv("PR_TITLE")
if not pr_title:
raise ValueError("PR title is required")

# Get the results of pytest benchmarks
cleaned_benchmark_results = extract_stats_from_json(args.benchmark_json)
# Insert the data into the database
Expand All @@ -155,7 +163,7 @@ def main():
python_version=args.python_version,
performance_data=cleaned_benchmark_results,
commit_sha=args.commit_sha,
pr_title=args.pr_title,
pr_title=pr_title,
branch_name=args.branch_name,
event_type=args.event_type,
actor=args.actor,
Expand Down

0 comments on commit fa99407

Please sign in to comment.