Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/actions/fetch-bench-baseline/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand All @@ -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
63 changes: 63 additions & 0 deletions .github/actions/upload-fork-bench-report/action.yml
Original file line number Diff line number Diff line change
@@ -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/"
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
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
10 changes: 10 additions & 0 deletions .github/workflows/pr-bench-gpu-compress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand Down
218 changes: 218 additions & 0 deletions .github/workflows/pr-bench-report.yml
Original file line number Diff line number Diff line change
@@ -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("^(?<base>fork-bench-report-.+?)(?:-attempt-(?<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"
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
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
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
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 }}
11 changes: 11 additions & 0 deletions .github/workflows/pr-bench-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand Down
Loading
Loading