From a67479f4c06ebb13de9eb2541c1ab6cde985650d Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Wed, 22 Oct 2025 17:48:10 -0500 Subject: [PATCH] Add steps for comparing with 'main' branch --- .github/workflows/pull_request.yml | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 16352631..2a550d45 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -26,6 +26,7 @@ jobs: BUILD_CMD: swift build -c release BENCH_CMD: .build/release/RegexBenchmark BASELINE_FILE: benchmark-baseline + MAIN_FILE: benchmark-main COMPARE_FILE: benchmark-pr COMPARE_OUT_FILE: benchmark-results.txt steps: @@ -46,6 +47,26 @@ jobs: set -euo pipefail eval "$BENCH_CMD --save $RUNNER_TEMP/$BASELINE_FILE" test -s "$RUNNER_TEMP/$BASELINE_FILE" || { echo "Baseline not created at $BASELINE_FILE"; exit 1; } + - name: Check out main branch + if: ${{ github.event.pull_request.base.ref != 'main' }} + uses: actions/checkout@v4 + with: + ref: main + path: main-branch + fetch-depth: 0 + - name: Build main branch + if: ${{ github.event.pull_request.base.ref != 'main' }} + working-directory: main-branch + run: | + set -euo pipefail + eval "$BUILD_CMD" + - name: Run main benchmark + if: ${{ github.event.pull_request.base.ref != 'main' }} + working-directory: main-branch + run: | + set -euo pipefail + eval "$BENCH_CMD --save $RUNNER_TEMP/$MAIN_FILE" + test -s "$RUNNER_TEMP/$MAIN_FILE" || { echo "Baseline (main) not created at $MAIN_FILE"; exit 1; } - name: Check out PR branch uses: actions/checkout@v4 with: @@ -64,11 +85,17 @@ jobs: eval "$BENCH_CMD --save $RUNNER_TEMP/$COMPARE_FILE" test -s "$RUNNER_TEMP/$COMPARE_FILE" || { echo "Comparison not created at $COMPARE_FILE"; exit 1; } eval "$BENCH_CMD --compare $RUNNER_TEMP/$BASELINE_FILE" | tee "$RUNNER_TEMP/$COMPARE_OUT_FILE" - - name: 📊 Compare benchmarks + - name: 📊 Compare benchmarks with base working-directory: pr run: | set -euo pipefail eval "$BENCH_CMD --load $RUNNER_TEMP/$COMPARE_FILE --compare $RUNNER_TEMP/$BASELINE_FILE --compare-compile-time $RUNNER_TEMP/$BASELINE_FILE" | tee "$RUNNER_TEMP/$COMPARE_OUT_FILE" + - name: 📊 Compare benchmarks with `main` + if: ${{ github.event.pull_request.base.ref != 'main' }} + working-directory: pr + run: | + set -euo pipefail + eval "$BENCH_CMD --load $RUNNER_TEMP/$COMPARE_FILE --compare $RUNNER_TEMP/$MAIN_FILE --compare-compile-time $RUNNER_TEMP/$MAIN_FILE" - name: Upload benchmark artifacts uses: actions/upload-artifact@v4 with: