|
| 1 | +name: Release Benchmarks |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [labeled] |
| 6 | + workflow_run: |
| 7 | + workflows: ["Publish"] |
| 8 | + types: [completed] |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + versions: |
| 12 | + description: "Release tags or versions to benchmark. Leave empty to backfill from recent releases." |
| 13 | + required: false |
| 14 | + default: "" |
| 15 | + limit: |
| 16 | + description: "Number of recent releases to benchmark when versions is empty." |
| 17 | + required: false |
| 18 | + default: "10" |
| 19 | + runs: |
| 20 | + description: "Measured runs per release/input/formatter case." |
| 21 | + required: false |
| 22 | + default: "7" |
| 23 | + python_version: |
| 24 | + description: "Python version used to install and run released packages." |
| 25 | + required: false |
| 26 | + default: "3.14.2" |
| 27 | + |
| 28 | +concurrency: |
| 29 | + group: release-benchmarks-${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.ref }} |
| 30 | + cancel-in-progress: false |
| 31 | + |
| 32 | +permissions: |
| 33 | + contents: read |
| 34 | + |
| 35 | +jobs: |
| 36 | + collect: |
| 37 | + name: Collect release benchmarks |
| 38 | + runs-on: ubuntu-24.04 |
| 39 | + if: >- |
| 40 | + ${{ |
| 41 | + github.event_name == 'workflow_dispatch' || |
| 42 | + ( |
| 43 | + github.event_name == 'pull_request' && |
| 44 | + github.event.action == 'labeled' && |
| 45 | + github.event.label.name == 'run-release-benchmarks' && |
| 46 | + github.event.pull_request.head.repo.full_name == github.repository |
| 47 | + ) || |
| 48 | + ( |
| 49 | + github.event.workflow_run.conclusion == 'success' && |
| 50 | + github.event.workflow_run.event == 'push' && |
| 51 | + github.event.workflow_run.head_repository.full_name == github.repository |
| 52 | + ) |
| 53 | + }} |
| 54 | + env: |
| 55 | + BENCHMARK_PYTHON_VERSION: ${{ github.event_name == 'workflow_dispatch' && inputs.python_version || '3.14.2' }} |
| 56 | + BENCHMARK_RUNS: ${{ github.event_name == 'workflow_dispatch' && inputs.runs || (github.event_name == 'pull_request' && '3' || '7') }} |
| 57 | + BENCHMARK_LIMIT: ${{ github.event_name == 'workflow_dispatch' && inputs.limit || (github.event_name == 'pull_request' && '3' || '10') }} |
| 58 | + OS: ubuntu-24.04 |
| 59 | + steps: |
| 60 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 61 | + with: |
| 62 | + persist-credentials: false |
| 63 | + - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 |
| 64 | + with: |
| 65 | + python-version: ${{ env.BENCHMARK_PYTHON_VERSION }} |
| 66 | + - name: Install the latest version of uv |
| 67 | + uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5 |
| 68 | + - name: Resolve release versions |
| 69 | + id: versions |
| 70 | + env: |
| 71 | + GH_TOKEN: ${{ github.token }} |
| 72 | + EVENT_NAME: ${{ github.event_name }} |
| 73 | + WORKFLOW_TAG: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_branch || '' }} |
| 74 | + INPUT_VERSIONS: ${{ github.event_name == 'workflow_dispatch' && inputs.versions || '' }} |
| 75 | + run: | |
| 76 | + set -euo pipefail |
| 77 | + versions="$INPUT_VERSIONS" |
| 78 | + if [ "$EVENT_NAME" = "workflow_run" ]; then |
| 79 | + versions="$WORKFLOW_TAG" |
| 80 | + fi |
| 81 | + if [ -z "${versions//[[:space:],]/}" ]; then |
| 82 | + versions="$(gh release list \ |
| 83 | + --exclude-drafts \ |
| 84 | + --exclude-pre-releases \ |
| 85 | + --limit "$BENCHMARK_LIMIT" \ |
| 86 | + --json tagName \ |
| 87 | + --jq '.[].tagName' | paste -sd, -)" |
| 88 | + fi |
| 89 | + if [ -z "${versions//[[:space:],]/}" ]; then |
| 90 | + echo "No release versions resolved" >&2 |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | + { |
| 94 | + echo "versions<<EOF" |
| 95 | + printf '%s\n' "$versions" |
| 96 | + echo "EOF" |
| 97 | + } >> "$GITHUB_OUTPUT" |
| 98 | + - name: Collect benchmarks |
| 99 | + run: >- |
| 100 | + python scripts/collect_release_benchmarks.py |
| 101 | + --versions '${{ steps.versions.outputs.versions }}' |
| 102 | + --runs "$BENCHMARK_RUNS" |
| 103 | + --output .benchmarks/release-benchmarks.json |
| 104 | + - name: Build benchmark docs artifact |
| 105 | + run: >- |
| 106 | + python scripts/build_release_benchmark_docs.py |
| 107 | + --data .benchmarks/release-benchmarks.json |
| 108 | + --docs .benchmarks/docs/performance-benchmarks.md |
| 109 | + --svg .benchmarks/docs/assets/benchmarks/release-benchmarks.svg |
| 110 | + - name: Upload benchmark data |
| 111 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 112 | + with: |
| 113 | + name: dcg-release-benchmarks-json |
| 114 | + path: .benchmarks/release-benchmarks.json |
| 115 | + if-no-files-found: error |
| 116 | + - name: Upload benchmark docs |
| 117 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 118 | + with: |
| 119 | + name: dcg-release-benchmark-docs |
| 120 | + path: .benchmarks/docs |
| 121 | + if-no-files-found: error |
0 commit comments