bencher.dev Upload #2763
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: bencher.dev Upload | |
| on: | |
| workflow_run: | |
| workflows: ["cargo bench", "Performance comparison"] | |
| # SAFETY: We are not running any code from the triggering PR, so this is safe. | |
| types: [completed] # zizmor: ignore[dangerous-triggers] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| jobs: | |
| bencher_upload: | |
| name: Upload | |
| # The bench workflow fails when a regression is detected, but we want to upload results regardless. | |
| if: github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure' | |
| permissions: | |
| pull-requests: write # This permission is required to post comments on PRs. | |
| checks: write # This permission is required to post "check" comments. | |
| runs-on: ubuntu-24.04 | |
| env: | |
| BENCHER_PROJECT: ${{ github.event.repository.name }} | |
| BENCHER_API_TOKEN: ${{ secrets.BENCHER_API_TOKEN }} | |
| GITHUB_EVENT_PATH: event.json | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SHA: ${{ github.event.workflow_run.referenced_workflows[0].sha != '' && github.event.workflow_run.referenced_workflows[0].sha || github.event.workflow_run.head_sha }} | |
| DATA_TAG: ${{ github.event.workflow.name == 'cargo bench' && 'bench' || 'perfcompare' }} | |
| steps: | |
| - env: | |
| EVENT: ${{ toJson(github.event) }} | |
| run: | | |
| echo "$EVENT" | jq | |
| - name: Download benchmark results | |
| uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 | |
| with: | |
| run-id: ${{ github.event.workflow_run.id }} | |
| name: ${{ github.event.repository.name }}-${{ env.SHA }}-${{ env.DATA_TAG }}-perf | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Export PR event data | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| with: | |
| script: | | |
| let fs = require('fs'); | |
| let prEvent = JSON.parse(fs.readFileSync('event.json', {encoding: 'utf8'})); | |
| core.exportVariable("PR_HEAD", prEvent.pull_request.head.ref || ''); | |
| 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@v0.5.6 # zizmor: ignore[unpinned-uses] | |
| - name: Set env | |
| run: | | |
| { | |
| echo "MAIN_SHA=$(cat main-sha.txt)" | |
| echo "TESTBED=$(cat testbed.txt)" | |
| } >> "$GITHUB_ENV" | |
| - name: Upload main-branch results | |
| run: | | |
| if [ "$DATA_TAG" == "bench" ]; then | |
| bencher run \ | |
| --branch main \ | |
| --hash "$MAIN_SHA" \ | |
| --testbed "$TESTBED" \ | |
| --threshold-measure latency \ | |
| --threshold-test t_test \ | |
| --threshold-upper-boundary 0.99 \ | |
| --thresholds-reset \ | |
| --err \ | |
| --adapter rust_criterion \ | |
| --github-actions "$GITHUB_TOKEN" \ | |
| --file results-main.txt || true # bencher exits with error if it detects an alert | |
| else | |
| FILES="" | |
| for file in hyperfine-main/*neqo*.json; do | |
| FILES="$FILES --file $file" | |
| done | |
| # shellcheck disable=SC2086 | |
| bencher run \ | |
| --branch main \ | |
| --hash "$MAIN_SHA" \ | |
| --testbed "$TESTBED" \ | |
| --threshold-measure latency \ | |
| --threshold-test t_test \ | |
| --threshold-upper-boundary 0.99 \ | |
| --thresholds-reset \ | |
| --err \ | |
| --adapter shell_hyperfine \ | |
| --github-actions "$GITHUB_TOKEN" \ | |
| $FILES || true # bencher exits with error if it detects | |
| fi | |
| - name: Upload PR results | |
| if: env.PR_HEAD != '' && env.PR_BASE != '' && env.PR_BASE_SHA != '' && env.PR_NUMBER != '' | |
| run: | | |
| if [ "$DATA_TAG" == "bench" ]; then | |
| bencher run \ | |
| --branch "$PR_HEAD" \ | |
| --testbed "$TESTBED" \ | |
| --start-point "$PR_BASE" \ | |
| --start-point-hash "$PR_BASE_SHA" \ | |
| --start-point-clone-thresholds \ | |
| --start-point-reset \ | |
| --err \ | |
| --adapter rust_criterion \ | |
| --github-actions "$GITHUB_TOKEN" \ | |
| --ci-number "$PR_NUMBER" \ | |
| --ci-only-on-alert \ | |
| --file results.txt || true # bencher exits with error if it detects | |
| else | |
| FILES="" | |
| for file in hyperfine/*neqo*.json; do | |
| FILES="$FILES --file $file" | |
| done | |
| # shellcheck disable=SC2086 | |
| bencher run \ | |
| --branch "$PR_HEAD" \ | |
| --testbed "$TESTBED" \ | |
| --start-point "$PR_BASE" \ | |
| --start-point-hash "$PR_BASE_SHA" \ | |
| --start-point-clone-thresholds \ | |
| --start-point-reset \ | |
| --err \ | |
| --adapter shell_hyperfine \ | |
| --github-actions "$GITHUB_TOKEN" \ | |
| --ci-number "$PR_NUMBER" \ | |
| --ci-only-on-alert \ | |
| $FILES || true # bencher exits with error if it detects | |
| fi |