diff --git a/.github/actions/fetch-bench-baseline/action.yml b/.github/actions/fetch-bench-baseline/action.yml
index 7141c6f655b..b0bfc41be0c 100644
--- a/.github/actions/fetch-bench-baseline/action.yml
+++ b/.github/actions/fetch-bench-baseline/action.yml
@@ -16,6 +16,11 @@ inputs:
output:
description: "Where to write the baseline records"
default: base.ingest.jsonl
+ head:
+ description: >-
+ The PR head commit. The baseline is the newest recorded commit reachable from it. The fork PR
+ report gives it, because its checkout is the default branch and not the PR.
+ default: HEAD
role-arn:
description: "The read-only benchmarks role (vars.GH_BENCH_READ_ROLE_ARN)"
required: true
@@ -50,6 +55,7 @@ runs:
env:
PR_RECORDS: ${{ inputs.pr-records }}
OUTPUT: ${{ inputs.output }}
+ PR_HEAD: ${{ inputs.head }}
AWS_OUTCOME: ${{ steps.aws.outcome }}
AWS_ACCESS_KEY_ID: ${{ steps.aws.outputs.aws-access-key-id }}
AWS_SECRET_ACCESS_KEY: ${{ steps.aws.outputs.aws-secret-access-key }}
@@ -59,16 +65,18 @@ runs:
RDS_BENCH_DB_NAME: ${{ inputs.database }}
run: |
set -Eeu -o pipefail
+ rm -f "$OUTPUT"
if [[ "$AWS_OUTCOME" != "success" ]]; then
# No baseline file tells the report that the baseline could not be read.
echo "::warning::Could not assume the read-only benchmarks role; reporting without a baseline."
exit 0
fi
+ mkdir -p "$(dirname "$OUTPUT")"
curl -fsSL https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem \
-o "${RUNNER_TEMP}/rds-global-bundle.pem"
DSN="postgresql://bench_ci_read@${RDS_BENCH_INSTANCE_ENDPOINT}:5432/${RDS_BENCH_DB_NAME}?sslmode=verify-full&sslrootcert=${RUNNER_TEMP}/rds-global-bundle.pem"
if ! uv run --no-project scripts/fetch-benchmark-baseline.py "$PR_RECORDS" "$OUTPUT" \
- --postgres "$DSN" --region "$AWS_REGION"; then
+ --postgres "$DSN" --region "$AWS_REGION" --head "$PR_HEAD"; then
echo "::warning::Could not read the baseline from the benchmarks database; reporting without a baseline."
rm -f "$OUTPUT"
fi
diff --git a/.github/actions/upload-fork-bench-report/action.yml b/.github/actions/upload-fork-bench-report/action.yml
new file mode 100644
index 00000000000..5f30fd008c4
--- /dev/null
+++ b/.github/actions/upload-fork-bench-report/action.yml
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: Apache-2.0
+# SPDX-FileCopyrightText: Copyright the Vortex contributors
+
+name: "Upload fork benchmark report"
+description: >-
+ Upload the records of a fork PR benchmark run for pr-bench-report.yml. A fork PR's job gets no
+ OIDC token and no repository variables, so it can neither read the baseline nor comment on the
+ PR. pr-bench-report.yml runs after the dispatch run in the base repository, reads the baseline
+ for these records, and posts the comment under the same tag as a same-repository PR.
+
+inputs:
+ benchmark-name:
+ description: "The benchmark name in the comment heading"
+ required: true
+ comment-tag:
+ description: "The comment tag of the PR comment, which identifies the report"
+ required: true
+ matrix-preset:
+ description: "Optional SQL matrix preset name, shown when entries did not report"
+ default: ""
+ missing-entries:
+ description: "Optional formatted list of SQL matrix entries that did not report"
+ default: ""
+ failed:
+ description: "Set to true when the benchmark job failed so pr-bench-report.yml posts a failure comment"
+ default: "false"
+
+runs:
+ using: "composite"
+ steps:
+ - name: Collect the report
+ shell: bash
+ env:
+ BENCHMARK_NAME: ${{ inputs.benchmark-name }}
+ COMMENT_TAG: ${{ inputs.comment-tag }}
+ MATRIX_PRESET: ${{ inputs.matrix-preset }}
+ MISSING_ENTRIES: ${{ inputs.missing-entries }}
+ FAILED: ${{ inputs.failed }}
+ run: |
+ set -Eeu -o pipefail
+ REPORT="${RUNNER_TEMP}/fork-bench-report"
+ rm -rf "$REPORT"
+ mkdir -p "$REPORT"
+ if [[ "$FAILED" == "true" ]]; then
+ printf 'true' > "$REPORT/failed.txt"
+ else
+ cp results.json results.ingest.jsonl "$REPORT/"
+ fi
+ printf '%s' "$BENCHMARK_NAME" > "$REPORT/name.txt"
+ printf '%s' "$COMMENT_TAG" > "$REPORT/comment-tag.txt"
+ if [[ -n "$MATRIX_PRESET" ]]; then
+ printf '%s' "$MATRIX_PRESET" > "$REPORT/matrix-preset.txt"
+ fi
+ if [[ -n "$MISSING_ENTRIES" ]]; then
+ printf '%s' "$MISSING_ENTRIES" > "$REPORT/missing.txt"
+ fi
+ - name: Upload the report
+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
+ with:
+ name: fork-bench-report-${{ inputs.comment-tag }}-attempt-${{ github.run_attempt }}
+ path: ${{ runner.temp }}/fork-bench-report/
+ retention-days: 5
+ if-no-files-found: error
diff --git a/.github/workflows/pr-bench-gpu-compress.yml b/.github/workflows/pr-bench-gpu-compress.yml
index 13b6e6fe087..24d42115d2a 100644
--- a/.github/workflows/pr-bench-gpu-compress.yml
+++ b/.github/workflows/pr-bench-gpu-compress.yml
@@ -95,7 +95,9 @@ jobs:
FLAT_LAYOUT_INLINE_ARRAY_NODE: "1"
run: |
python3 scripts/compress-split.py --gpu-decompress --emit-ingest-records
+ # A fork PR's job has no OIDC token, so pr-bench-report.yml reads its baseline.
- name: Fetch baseline from the benchmarks database
+ if: github.event.pull_request.head.repo.fork != true
uses: ./.github/actions/fetch-bench-baseline
with:
role-arn: ${{ vars.GH_BENCH_READ_ROLE_ARN }}
@@ -111,6 +113,14 @@ jobs:
uv run --no-project scripts/compare-benchmark-jsons.py base.ingest.jsonl results.json \
"GPU Compression" --pr-records results.ingest.jsonl > comment.md
cat comment.md >> "$GITHUB_STEP_SUMMARY"
+ # A fork PR's job has no OIDC token, so pr-bench-report.yml reads its baseline and comments.
+ - name: Upload report for pr-bench-report.yml
+ if: (success() || failure()) && github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true
+ uses: ./.github/actions/upload-fork-bench-report
+ with:
+ benchmark-name: GPU Compression
+ comment-tag: bench-pr-comment-gpu-compress
+ failed: ${{ job.status == 'failure' }}
- name: Comment PR
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false
uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3
diff --git a/.github/workflows/pr-bench-report.yml b/.github/workflows/pr-bench-report.yml
new file mode 100644
index 00000000000..e5d5363d60a
--- /dev/null
+++ b/.github/workflows/pr-bench-report.yml
@@ -0,0 +1,218 @@
+# Reads the baseline for the benchmarks of a fork PR and comments the comparison on the PR.
+#
+# GitHub gives a fork PR's `pull_request` run a read-only token with no OIDC token and no repository
+# variables, so its benchmark jobs can neither read the baseline from the benchmarks database nor
+# comment. Those jobs upload their records (upload-fork-bench-report) instead. This workflow runs
+# after the dispatch run, in the base repository and from the default branch, so it can assume the
+# read-only benchmarks role and comment.
+#
+# The artifacts come from a run of fork code, so they are untrusted data: this workflow only parses
+# them, and never checks out or runs code from the PR. It fetches the PR head commits only to walk
+# their history for the baseline commit.
+
+name: PR Benchmark Report
+
+on:
+ workflow_run:
+ workflows: ["PR Benchmark Dispatch"]
+ types: [completed]
+
+permissions: { }
+
+jobs:
+ find-reports:
+ if: >-
+ github.event.workflow_run.event == 'pull_request'
+ && github.event.workflow_run.head_repository.full_name != github.repository
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ permissions:
+ actions: read # to list the artifacts of the dispatch run
+ pull-requests: read # to find the PR of the dispatch run
+ outputs:
+ pr-number: ${{ steps.find.outputs.pr-number }}
+ reports: ${{ steps.find.outputs.reports }}
+ steps:
+ - name: Find the PR and its benchmark reports
+ id: find
+ shell: bash
+ env:
+ GH_TOKEN: ${{ github.token }}
+ REPO: ${{ github.repository }}
+ RUN_ID: ${{ github.event.workflow_run.id }}
+ HEAD_OWNER: ${{ github.event.workflow_run.head_repository.owner.login }}
+ HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
+ RUN_TITLE: ${{ github.event.workflow_run.display_title }}
+ run: |
+ set -Eeu -o pipefail
+
+ # A fork's `workflow_run` event lists no pull requests, so look up open PRs with this
+ # head and prefer the PR number named in the dispatch run title when more than one matches.
+ OPEN_PRS=$(gh api -X GET "repos/${REPO}/pulls" -f state=open -f "head=${HEAD_OWNER}:${HEAD_BRANCH}" \
+ --jq '[.[].number]')
+ RUN_PR=""
+ if [[ "$RUN_TITLE" =~ ^PR\ \#([0-9]+)\ ]]; then
+ RUN_PR="${BASH_REMATCH[1]}"
+ fi
+ PR_NUMBER=$(jq -r --arg run_pr "$RUN_PR" \
+ 'if ($run_pr != "" and any(.[]; tostring == $run_pr)) then $run_pr else (.[0] // empty | tostring) end' \
+ <<<"$OPEN_PRS")
+ REPORTS=$(gh api --paginate "repos/${REPO}/actions/runs/${RUN_ID}/artifacts" \
+ | jq -s -c '
+ [
+ .[].artifacts[]
+ | select(.expired == false and (.name | startswith("fork-bench-report-")))
+ | (.name | capture("^(?fork-bench-report-.+?)(?:-attempt-(?[0-9]+))?$")) as $m
+ | {name: .name, base: $m.base, attempt: (($m.attempt // "0") | tonumber)}
+ ]
+ | group_by(.base)
+ | map(max_by(.attempt).name)
+ ')
+ if [[ -z "$PR_NUMBER" ]]; then
+ echo "::notice::No open PR has the head ${HEAD_OWNER}:${HEAD_BRANCH}; nothing to report."
+ REPORTS='[]'
+ fi
+ echo "pr-number=${PR_NUMBER}" >> "$GITHUB_OUTPUT"
+ echo "reports=${REPORTS}" >> "$GITHUB_OUTPUT"
+
+ report:
+ needs: find-reports
+ if: needs.find-reports.outputs.reports != '[]'
+ runs-on: ubuntu-latest
+ timeout-minutes: 20
+ permissions:
+ actions: read # to download the artifacts of the dispatch run
+ contents: read
+ id-token: write # enables AWS-GitHub OIDC
+ pull-requests: write # for commenting on PRs
+ strategy:
+ fail-fast: false
+ matrix:
+ report: ${{ fromJSON(needs.find-reports.outputs.reports) }}
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
+ with:
+ fetch-depth: 0
+ persist-credentials: false
+ - name: Install uv
+ uses: spiraldb/actions/.github/actions/setup-uv@a746510eafaa926484c354541cfc49b2ec06cc63 # 0.18.6
+ with:
+ sync: false
+ # The baseline is the newest recorded commit reachable from the PR head. The commits are only
+ # read for their history, never checked out.
+ - name: Fetch the PR head commits
+ shell: bash
+ env:
+ HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
+ run: git fetch --no-tags origin "$HEAD_SHA"
+ - name: Download the report
+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
+ with:
+ name: ${{ matrix.report }}
+ path: ${{ runner.temp }}/report
+ run-id: ${{ github.event.workflow_run.id }}
+ github-token: ${{ github.token }}
+ - name: Read the report metadata
+ id: meta
+ shell: bash
+ env:
+ REPORT: ${{ runner.temp }}/report
+ run: |
+ set -Eeu -o pipefail
+
+ COMMENT_TAG=$(head -c 200 "$REPORT/comment-tag.txt")
+ if [[ ! "$COMMENT_TAG" =~ ^bench-pr-comment-[A-Za-z0-9._-]+$ ]]; then
+ echo "::error::The report has an unexpected comment tag."
+ exit 1
+ fi
+ BENCHMARK_NAME=$(head -c 200 "$REPORT/name.txt" | tr -d '\r\n')
+ if [[ ! "$BENCHMARK_NAME" =~ ^[A-Za-z0-9][A-Za-z0-9\ ._/+:=()-]*$ ]]; then
+ echo "::error::The report has an unexpected benchmark name."
+ exit 1
+ fi
+ FAILED=$([[ -s "$REPORT/failed.txt" ]] && echo true || echo false)
+ REPORTED=false
+ if [[ "$FAILED" != "true" && -s "$REPORT/results.ingest.jsonl" ]]; then
+ MAX_BYTES=$((16 * 1024 * 1024))
+ MAX_RECORDS=5000
+ for f in "$REPORT/results.ingest.jsonl" "$REPORT/results.json"; do
+ if [[ -f "$f" ]] && (( $(wc -c < "$f") > MAX_BYTES )); then
+ echo "::error::Report file $(basename "$f") exceeds ${MAX_BYTES} bytes."
+ exit 1
+ fi
+ done
+ if (( $(wc -l < "$REPORT/results.ingest.jsonl") > MAX_RECORDS )); then
+ echo "::error::results.ingest.jsonl exceeds ${MAX_RECORDS} records."
+ exit 1
+ fi
+ REPORTED=true
+ fi
+ echo "comment-tag=${COMMENT_TAG}" >> "$GITHUB_OUTPUT"
+ echo "benchmark-name=${BENCHMARK_NAME}" >> "$GITHUB_OUTPUT"
+ echo "failed=${FAILED}" >> "$GITHUB_OUTPUT"
+ echo "reported=${REPORTED}" >> "$GITHUB_OUTPUT"
+ - name: Fetch baseline from the benchmarks database
+ if: steps.meta.outputs.reported == 'true'
+ uses: ./.github/actions/fetch-bench-baseline
+ with:
+ pr-records: ${{ runner.temp }}/report/results.ingest.jsonl
+ output: ${{ runner.temp }}/baseline/base.ingest.jsonl
+ head: ${{ github.event.workflow_run.head_sha }}
+ role-arn: ${{ vars.GH_BENCH_READ_ROLE_ARN }}
+ region: ${{ vars.RDS_BENCH_REGION }}
+ endpoint: ${{ vars.RDS_BENCH_INSTANCE_ENDPOINT }}
+ database: ${{ vars.RDS_BENCH_DB_NAME }}
+ - name: Compare results
+ id: compare
+ shell: bash
+ env:
+ REPORT: ${{ runner.temp }}/report
+ BASELINE: ${{ runner.temp }}/baseline/base.ingest.jsonl
+ BENCHMARK_NAME: ${{ steps.meta.outputs.benchmark-name }}
+ FAILED: ${{ steps.meta.outputs.failed }}
+ REPORTED: ${{ steps.meta.outputs.reported }}
+ RUN_URL: ${{ github.event.workflow_run.html_url }}
+ run: |
+ set -Eeu -o pipefail
+
+ : > comment.md
+ if [[ "$FAILED" == "true" ]]; then
+ echo "# BENCHMARK FAILED" >> comment.md
+ echo >> comment.md
+ echo "Benchmark \`${BENCHMARK_NAME}\` failed! Check the [workflow run](${RUN_URL}) for details." >> comment.md
+ else
+ if [[ -s "$REPORT/missing.txt" ]]; then
+ MISSING=$(head -c 2000 "$REPORT/missing.txt" | tr -d '\r\n')
+ if [[ ! "$MISSING" =~ ^\`[A-Za-z0-9._-]+\`(\ \`[A-Za-z0-9._-]+\`)*$ ]]; then
+ echo "::error::The report has unexpected missing entry names."
+ exit 1
+ fi
+ PRESET=""
+ if [[ -s "$REPORT/matrix-preset.txt" ]]; then
+ PRESET_VAL=$(head -c 100 "$REPORT/matrix-preset.txt" | tr -d '\r\n')
+ if [[ ! "$PRESET_VAL" =~ ^[A-Za-z0-9._-]+$ ]]; then
+ echo "::error::The report has an unexpected matrix preset."
+ exit 1
+ fi
+ PRESET=" (${PRESET_VAL})"
+ fi
+ echo "# 🚨🚨🚨❌❌❌ SQL BENCHMARK FAILED ❌❌❌🚨🚨🚨" >> comment.md
+ echo >> comment.md
+ echo "Benchmark \`${BENCHMARK_NAME}\`${PRESET} has entries that did not report: ${MISSING}. Check the [workflow run](${RUN_URL}) for details." >> comment.md
+ echo >> comment.md
+ fi
+ if [[ "$REPORTED" == "true" ]]; then
+ uv run --no-project scripts/compare-benchmark-jsons.py "$BASELINE" \
+ "$REPORT/results.json" "$BENCHMARK_NAME" --pr-records "$REPORT/results.ingest.jsonl" \
+ >> comment.md
+ fi
+ fi
+ cat comment.md >> "$GITHUB_STEP_SUMMARY"
+ echo "has-comment=$([[ -s comment.md ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"
+ - name: Comment PR
+ if: steps.compare.outputs.has-comment == 'true'
+ uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3
+ with:
+ file-path: comment.md
+ pr-number: ${{ needs.find-reports.outputs.pr-number }}
+ comment-tag: ${{ steps.meta.outputs.comment-tag }}
diff --git a/.github/workflows/pr-bench-runner.yml b/.github/workflows/pr-bench-runner.yml
index 693120a16bc..4a4c590b6b5 100644
--- a/.github/workflows/pr-bench-runner.yml
+++ b/.github/workflows/pr-bench-runner.yml
@@ -286,7 +286,9 @@ jobs:
run: |
python3 scripts/string-split.py
+ # A fork PR's job has no OIDC token, so pr-bench-report.yml reads its baseline.
- name: Fetch baseline from the benchmarks database
+ if: github.event.pull_request.head.repo.fork != true
uses: ./.github/actions/fetch-bench-baseline
with:
role-arn: ${{ vars.GH_BENCH_READ_ROLE_ARN }}
@@ -303,6 +305,15 @@ jobs:
"${{ inputs.benchmark_name }}" --pr-records results.ingest.jsonl > comment.md
cat comment.md >> "$GITHUB_STEP_SUMMARY"
+ # A fork PR's job has no OIDC token, so pr-bench-report.yml reads its baseline and comments.
+ - name: Upload report for pr-bench-report.yml
+ if: (success() || failure()) && github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true
+ uses: ./.github/actions/upload-fork-bench-report
+ with:
+ benchmark-name: ${{ inputs.benchmark_name }}
+ comment-tag: bench-pr-comment-${{ inputs.benchmark_id }}${{ inputs.variant_id }}
+ failed: ${{ job.status == 'failure' }}
+
- name: Comment PR
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false
uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3
diff --git a/.github/workflows/sql-bench-matrix.yml b/.github/workflows/sql-bench-matrix.yml
index c3e1503db77..3beb7a8a2e2 100644
--- a/.github/workflows/sql-bench-matrix.yml
+++ b/.github/workflows/sql-bench-matrix.yml
@@ -499,8 +499,9 @@ jobs:
done < <(jq -r '.[]' <<<"$IDS")
echo "missing=${missing[*]}" >> "$GITHUB_OUTPUT"
echo "reported=$([[ -s results.ingest.jsonl ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"
+ # A fork PR's job has no OIDC token, so pr-bench-report.yml reads its baseline.
- name: Fetch baseline from the benchmarks database
- if: steps.merge.outputs.reported == 'true'
+ if: steps.merge.outputs.reported == 'true' && github.event.pull_request.head.repo.fork != true
uses: ./.github/actions/fetch-bench-baseline
with:
role-arn: ${{ vars.GH_BENCH_READ_ROLE_ARN }}
@@ -527,6 +528,15 @@ jobs:
"${{ matrix.name }}" --pr-records results.ingest.jsonl >> comment.md
fi
cat comment.md >> "$GITHUB_STEP_SUMMARY"
+ # A fork PR's job has no OIDC token, so pr-bench-report.yml reads its baseline and comments.
+ - name: Upload report for pr-bench-report.yml
+ if: github.event.pull_request.head.repo.fork == true
+ uses: ./.github/actions/upload-fork-bench-report
+ with:
+ benchmark-name: ${{ matrix.name }}
+ comment-tag: bench-pr-comment-${{ matrix.group }}-${{ inputs.matrix_preset }}
+ matrix-preset: ${{ inputs.matrix_preset }}
+ missing-entries: ${{ steps.merge.outputs.missing }}
- name: Comment PR
if: github.event.pull_request.head.repo.fork == false
uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3
diff --git a/scripts/fetch-benchmark-baseline.py b/scripts/fetch-benchmark-baseline.py
index 56318c36348..2bc92b3ca77 100644
--- a/scripts/fetch-benchmark-baseline.py
+++ b/scripts/fetch-benchmark-baseline.py
@@ -10,9 +10,9 @@
"""Fetch the develop baseline for a PR benchmark run from the benchmarks Postgres.
Reads the PR's `--ingest-jsonl` records, finds the newest commit reachable from
-`HEAD` that recorded any of the same measurements, and writes that commit's
-matching rows in the same JSONL record shape. `compare-benchmark-jsons.py` then
-compares the two record files.
+the PR head (`HEAD` unless `--head` names another commit) that recorded any of
+the same measurements, and writes that commit's matching rows in the same JSONL
+record shape. `compare-benchmark-jsons.py` then compares the two record files.
It connects as the read-only `bench_ci_read` Postgres user, with an RDS IAM token minted
(by `post-ingest.py`'s token helper) from the AWS credentials of the assumed
@@ -80,6 +80,11 @@ def parse_args() -> argparse.Namespace:
help="Libpq DSN of the benchmarks database. Without a password, an RDS IAM token is minted.",
)
parser.add_argument("--region", default=None, help="AWS region for RDS IAM token minting.")
+ parser.add_argument(
+ "--head",
+ default="HEAD",
+ help="The PR head commit. Give it when the checkout is not the PR, as in the fork PR report.",
+ )
return parser.parse_args()
@@ -103,8 +108,8 @@ def identities_by_kind(records: list[dict]) -> dict[str, list[tuple]]:
return {kind: sorted(keys, key=repr) for kind, keys in identities.items()}
-def reachable_commits() -> list[str]:
- """Return every commit reachable from `HEAD`; a shallow checkout cannot pick a baseline."""
+def reachable_commits(head: str) -> list[str]:
+ """Return every commit reachable from `head`; a shallow checkout cannot pick a baseline."""
is_shallow = subprocess.run(
["git", "rev-parse", "--is-shallow-repository"], check=True, capture_output=True, text=True
@@ -112,9 +117,9 @@ def reachable_commits() -> list[str]:
if is_shallow == "true":
raise SystemExit(
"Cannot resolve a baseline from a shallow checkout: the baseline is the newest "
- "recorded commit reachable from HEAD. Check the repository out with `fetch-depth: 0`."
+ "recorded commit reachable from the PR head. Check the repository out with `fetch-depth: 0`."
)
- commits = subprocess.run(["git", "rev-list", "HEAD"], check=True, capture_output=True, text=True).stdout
+ commits = subprocess.run(["git", "rev-list", head, "--"], check=True, capture_output=True, text=True).stdout
return commits.split()
@@ -170,7 +175,7 @@ def newest_baseline_commit(
"""Return the newest reachable commit that recorded any PR identity, with its timestamp.
Each identity's rows are read newest first, a page at a time, until one is from a commit
- reachable from `HEAD`. That is usually the first page: the baseline is the PR's merge base
+ reachable from the PR head. That is usually the first page: the baseline is the PR's merge base
or close to it. One query per identity, as Postgres plans a `UNION ALL` of them far worse.
"""
@@ -260,7 +265,7 @@ def main() -> None:
identities = identities_by_kind(read_records(args.pr_records))
records: list[dict] = []
if identities:
- commits = reachable_commits()
+ commits = reachable_commits(args.head)
with connect_postgres(args.postgres, args.region) as conn:
identities = existing_kinds(conn, identities)
newest = newest_baseline_commit(conn, commit_selection_identities(identities), set(commits))
diff --git a/scripts/tests/test_benchmark_reporting.py b/scripts/tests/test_benchmark_reporting.py
index 74a3d8787c6..707c70b9f64 100644
--- a/scripts/tests/test_benchmark_reporting.py
+++ b/scripts/tests/test_benchmark_reporting.py
@@ -10,6 +10,7 @@
from types import ModuleType
import pandas as pd
+import pytest
REPO_ROOT = Path(__file__).resolve().parents[2]
COMPARE_SCRIPT = REPO_ROOT / "scripts" / "compare-benchmark-jsons.py"
@@ -751,6 +752,27 @@ def test_baseline_fetch_refuses_a_shallow_checkout(tmp_path: Path) -> None:
assert "fetch-depth: 0" in result.stderr
+def test_baseline_fetch_walks_the_given_head(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
+ """The fork PR report checks out the default branch, so the PR head is not `HEAD`.
+
+ The baseline must come from the history of the PR head that `--head` names, which
+ includes commits that the checked-out branch does not reach.
+ """
+
+ fetch = load_module("fetch_benchmark_baseline", FETCH_BASELINE_SCRIPT)
+ repo = git_repo_with_one_commit(tmp_path / "repo")
+ identity = ["-c", "user.name=Vortex Test", "-c", "user.email=test@example.com"]
+ subprocess.run(["git", *identity, "commit", "--quiet", "--allow-empty", "-m", "pr"], cwd=repo, check=True)
+ pr_head = subprocess.run(
+ ["git", "rev-parse", "HEAD"], cwd=repo, check=True, capture_output=True, text=True
+ ).stdout.strip()
+ subprocess.run(["git", "checkout", "--quiet", "--detach", "HEAD~1"], cwd=repo, check=True)
+ monkeypatch.chdir(repo)
+
+ assert pr_head not in fetch.reachable_commits("HEAD")
+ assert pr_head in fetch.reachable_commits(pr_head)
+
+
def test_baseline_fetch_groups_distinct_pr_identities_by_kind() -> None:
fetch = load_module("fetch_benchmark_baseline", FETCH_BASELINE_SCRIPT)
records = [