From fa99407b81a1815fa43913b13d6541635b661511 Mon Sep 17 00:00:00 2001 From: Martin Xu <15661672+martinxu9@users.noreply.github.com> Date: Wed, 20 Mar 2024 11:30:47 -0700 Subject: [PATCH] Handle quote marks ' " in PR titles in benchmark CI (#2877) * escape double quote marks in PR title * move the pr title into the env --- .github/workflows/benchmarks.yml | 9 ++++++--- scripts/simple_app_benchmark_upload.py | 14 +++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index 6de6f369bdb..a480dfe0ba3 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -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 }}" diff --git a/scripts/simple_app_benchmark_upload.py b/scripts/simple_app_benchmark_upload.py index d6c26e58a76..392a0d9a219 100644 --- a/scripts/simple_app_benchmark_upload.py +++ b/scripts/simple_app_benchmark_upload.py @@ -4,6 +4,7 @@ import argparse import json +import os from datetime import datetime import psycopg2 @@ -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( @@ -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", @@ -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 @@ -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,