|
| 1 | +name: Release Benchmarks |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [labeled, synchronize] |
| 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 select by PyPI download usage." |
| 13 | + required: false |
| 14 | + default: "" |
| 15 | + history_days: |
| 16 | + description: "PyPI download lookback window used for version selection." |
| 17 | + required: false |
| 18 | + default: "365" |
| 19 | + limit: |
| 20 | + description: "Maximum release versions to benchmark." |
| 21 | + required: false |
| 22 | + default: "40" |
| 23 | + runs: |
| 24 | + description: "Measured runs per release/input/formatter case." |
| 25 | + required: false |
| 26 | + default: "7" |
| 27 | + python_version: |
| 28 | + description: "Python version used to install and run released packages." |
| 29 | + required: false |
| 30 | + default: "3.14.2" |
| 31 | + |
| 32 | +concurrency: |
| 33 | + group: release-benchmarks-${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.ref }} |
| 34 | + cancel-in-progress: false |
| 35 | + |
| 36 | +permissions: |
| 37 | + contents: read |
| 38 | + |
| 39 | +jobs: |
| 40 | + resolve: |
| 41 | + name: Resolve release benchmark versions |
| 42 | + runs-on: ubuntu-24.04 |
| 43 | + if: >- |
| 44 | + ${{ |
| 45 | + github.event_name == 'workflow_dispatch' || |
| 46 | + ( |
| 47 | + github.event_name == 'pull_request' && |
| 48 | + contains(github.event.pull_request.labels.*.name, 'run-release-benchmarks') && |
| 49 | + github.event.pull_request.head.repo.full_name == github.repository |
| 50 | + ) || |
| 51 | + ( |
| 52 | + github.event.workflow_run.conclusion == 'success' && |
| 53 | + github.event.workflow_run.event == 'push' && |
| 54 | + github.event.workflow_run.head_repository.full_name == github.repository |
| 55 | + ) |
| 56 | + }} |
| 57 | + outputs: |
| 58 | + versions_json: ${{ steps.versions.outputs.versions_json }} |
| 59 | + versions: ${{ steps.versions.outputs.versions }} |
| 60 | + env: |
| 61 | + BENCHMARK_PYTHON_VERSION: ${{ github.event_name == 'workflow_dispatch' && inputs.python_version || '3.14.2' }} |
| 62 | + BENCHMARK_HISTORY_DAYS: ${{ github.event_name == 'workflow_dispatch' && inputs.history_days || '365' }} |
| 63 | + BENCHMARK_LIMIT: ${{ github.event_name == 'workflow_dispatch' && inputs.limit || '40' }} |
| 64 | + steps: |
| 65 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 66 | + with: |
| 67 | + persist-credentials: false |
| 68 | + - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 |
| 69 | + with: |
| 70 | + python-version: ${{ env.BENCHMARK_PYTHON_VERSION }} |
| 71 | + - name: Resolve release versions |
| 72 | + id: versions |
| 73 | + env: |
| 74 | + EVENT_NAME: ${{ github.event_name }} |
| 75 | + WORKFLOW_TAG: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_branch || '' }} |
| 76 | + INPUT_VERSIONS: ${{ github.event_name == 'workflow_dispatch' && inputs.versions || '' }} |
| 77 | + run: | |
| 78 | + set -euo pipefail |
| 79 | + versions="$INPUT_VERSIONS" |
| 80 | + if [ "$EVENT_NAME" = "workflow_run" ]; then |
| 81 | + versions="$WORKFLOW_TAG" |
| 82 | + fi |
| 83 | + python scripts/select_release_benchmark_versions.py \ |
| 84 | + --versions "$versions" \ |
| 85 | + --history-days "$BENCHMARK_HISTORY_DAYS" \ |
| 86 | + --limit "$BENCHMARK_LIMIT" \ |
| 87 | + --output .benchmarks/release-benchmark-selection.json |
| 88 | + - name: Upload benchmark selection |
| 89 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 90 | + with: |
| 91 | + name: dcg-release-benchmark-selection |
| 92 | + path: .benchmarks/release-benchmark-selection.json |
| 93 | + if-no-files-found: error |
| 94 | + |
| 95 | + collect: |
| 96 | + name: Collect release benchmarks (${{ matrix.version }}) |
| 97 | + needs: resolve |
| 98 | + if: needs.resolve.result == 'success' |
| 99 | + runs-on: ubuntu-24.04 |
| 100 | + strategy: |
| 101 | + fail-fast: false |
| 102 | + max-parallel: 40 |
| 103 | + matrix: |
| 104 | + version: ${{ fromJson(needs.resolve.outputs.versions_json) }} |
| 105 | + env: |
| 106 | + BENCHMARK_PYTHON_VERSION: ${{ github.event_name == 'workflow_dispatch' && inputs.python_version || '3.14.2' }} |
| 107 | + BENCHMARK_RUNS: ${{ github.event_name == 'workflow_dispatch' && inputs.runs || (github.event_name == 'pull_request' && '3' || '7') }} |
| 108 | + OS: ubuntu-24.04 |
| 109 | + steps: |
| 110 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 111 | + with: |
| 112 | + persist-credentials: false |
| 113 | + - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 |
| 114 | + with: |
| 115 | + python-version: ${{ env.BENCHMARK_PYTHON_VERSION }} |
| 116 | + - name: Install the latest version of uv |
| 117 | + uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5 |
| 118 | + - name: Collect benchmarks |
| 119 | + env: |
| 120 | + BENCHMARK_VERSION: ${{ matrix.version }} |
| 121 | + run: >- |
| 122 | + python scripts/collect_release_benchmarks.py |
| 123 | + --versions "$BENCHMARK_VERSION" |
| 124 | + --runs "$BENCHMARK_RUNS" |
| 125 | + --output ".benchmarks/fragments/release-benchmark-${BENCHMARK_VERSION}.json" |
| 126 | + - name: Upload benchmark fragment |
| 127 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 128 | + with: |
| 129 | + name: dcg-release-benchmark-fragment-${{ matrix.version }} |
| 130 | + path: .benchmarks/fragments/release-benchmark-${{ matrix.version }}.json |
| 131 | + if-no-files-found: error |
| 132 | + |
| 133 | + build: |
| 134 | + name: Build release benchmark docs artifact |
| 135 | + needs: [resolve, collect] |
| 136 | + if: needs.collect.result == 'success' |
| 137 | + runs-on: ubuntu-24.04 |
| 138 | + env: |
| 139 | + BENCHMARK_PYTHON_VERSION: ${{ github.event_name == 'workflow_dispatch' && inputs.python_version || '3.14.2' }} |
| 140 | + OS: ubuntu-24.04 |
| 141 | + steps: |
| 142 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 143 | + with: |
| 144 | + persist-credentials: false |
| 145 | + - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 |
| 146 | + with: |
| 147 | + python-version: ${{ env.BENCHMARK_PYTHON_VERSION }} |
| 148 | + - name: Download benchmark selection |
| 149 | + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 |
| 150 | + with: |
| 151 | + name: dcg-release-benchmark-selection |
| 152 | + path: .benchmarks |
| 153 | + - name: Download benchmark fragments |
| 154 | + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 |
| 155 | + with: |
| 156 | + pattern: dcg-release-benchmark-fragment-* |
| 157 | + path: .benchmarks/fragments |
| 158 | + merge-multiple: true |
| 159 | + - name: Merge benchmark data |
| 160 | + run: >- |
| 161 | + python scripts/merge_release_benchmarks.py |
| 162 | + .benchmarks/fragments/*.json |
| 163 | + --selection .benchmarks/release-benchmark-selection.json |
| 164 | + --output .benchmarks/release-benchmarks.json |
| 165 | + - name: Build benchmark docs artifact |
| 166 | + run: >- |
| 167 | + python scripts/build_release_benchmark_docs.py |
| 168 | + --data .benchmarks/release-benchmarks.json |
| 169 | + --docs .benchmarks/docs/performance-benchmarks.md |
| 170 | + --svg .benchmarks/docs/assets/benchmarks/release-benchmarks.svg |
| 171 | + - name: Upload benchmark data |
| 172 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 173 | + with: |
| 174 | + name: dcg-release-benchmarks-json |
| 175 | + path: .benchmarks/release-benchmarks.json |
| 176 | + if-no-files-found: error |
| 177 | + - name: Upload benchmark docs |
| 178 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 179 | + with: |
| 180 | + name: dcg-release-benchmark-docs |
| 181 | + path: .benchmarks/docs |
| 182 | + if-no-files-found: error |
0 commit comments