Skip to content

Track PR Benchmarks #1567

Track PR Benchmarks

Track PR Benchmarks #1567

name: Track PR Benchmarks
on:
workflow_run: # zizmor: ignore[dangerous-triggers] fork-PR benchmarks must run after CI; this workflow never checks out untrusted PR code and treats all PR inputs as untrusted
workflows: [CI]
types: [completed]
env:
# The Bencher project slug. For a project-scoped API key (`bencher_run_*`) this
# is also the `docker login` username for the OCI registry. Replace with your own.
BENCHER_PROJECT: bencher
jobs:
track_pr_benchmarks:
name: Track PR Benchmarks with Bencher
if: ${{ github.event.workflow_run.event == 'pull_request' }}
permissions:
checks: write
pull-requests: write
runs-on: ubuntu-22.04
env:
PR_EVENT: event.json
steps:
- name: Download Bench Image
id: download_bench
continue-on-error: true
uses: dawidd6/action-download-artifact@b6e2e70617bc3265edd6dab6c906732b2f1ae151 # v21
with:
name: bench_image.tar
run_id: ${{ github.event.workflow_run.id }}
- name: Download PR Event
if: steps.download_bench.outcome == 'success'
uses: dawidd6/action-download-artifact@b6e2e70617bc3265edd6dab6c906732b2f1ae151 # v21
with:
name: ${{ env.PR_EVENT }}
run_id: ${{ github.event.workflow_run.id }}
- name: Load and push image
if: steps.download_bench.outcome == 'success'
env:
GITHUB_EVENT_WORKFLOW_RUN_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
docker load -i bench_image.tar
docker tag bench:ci registry.bencher.dev/bencher:${GITHUB_EVENT_WORKFLOW_RUN_HEAD_SHA}
echo '${{ secrets.BENCHER_API_KEY }}' | docker login registry.bencher.dev -u "$BENCHER_PROJECT" --password-stdin
docker push registry.bencher.dev/bencher:${GITHUB_EVENT_WORKFLOW_RUN_HEAD_SHA}
- name: Read PR Event Data
if: steps.download_bench.outcome == 'success'
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
const fs = require('fs');
const prEvent = JSON.parse(fs.readFileSync(process.env.PR_EVENT, 'utf8'));
core.exportVariable('PR_HEAD', prEvent.pull_request.head.ref);
core.exportVariable('PR_HEAD_SHA', prEvent.pull_request.head.sha);
core.exportVariable('PR_BASE', prEvent.pull_request.base.ref);
core.exportVariable('PR_BASE_SHA', prEvent.pull_request.base.sha);
core.exportVariable('PR_NUMBER', prEvent.number);
- uses: bencherdev/bencher@main # zizmor: ignore[unpinned-uses] first-party action; intentionally tracks @main to exercise the latest released CLI
if: steps.download_bench.outcome == 'success'
- name: Track Benchmarks with Bencher
if: steps.download_bench.outcome == 'success'
env:
BENCHER_API_KEY: ${{ secrets.BENCHER_API_KEY }}
GITHUB_EVENT_WORKFLOW_RUN_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
bencher run \
--project "$BENCHER_PROJECT" \
--key "$BENCHER_API_KEY" \
--image "bencher:${GITHUB_EVENT_WORKFLOW_RUN_HEAD_SHA}" \
--branch "$PR_HEAD" \
--hash "$PR_HEAD_SHA" \
--start-point "$PR_BASE" \
--start-point-hash "$PR_BASE_SHA" \
--start-point-clone-thresholds \
--start-point-reset \
--testbed intel-v1 \
--spec intel-v1 \
--adapter rust_criterion \
--error-on-alert \
--github-actions '${{ secrets.GITHUB_TOKEN }}' \
--ci-number "$PR_NUMBER"