apply benchmark patch on label #4
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: Apply-Benchmark-Patch | |
| on: | |
| pull_request: | |
| types: [labeled] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| actions: read # required to list & download artifacts across workflows | |
| jobs: | |
| apply: | |
| if: ${{ github.event.label.name == 'apply-benchmark-patch' }} | |
| runs-on: Benchmarking | |
| steps: | |
| - name: Check out PR branch | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ github.event.pull_request.head.repo.full_name }} | |
| ref: ${{ github.event.pull_request.head.ref }} | |
| fetch-depth: 0 | |
| - name: Install GitHub CLI | |
| run: | | |
| sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get update | |
| sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get install -y --no-install-recommends -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" gh | |
| echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token | |
| # Look for the most recent run of the heavy workflow for this PR | |
| # that actually produced an artifact named "bench-patch". | |
| - name: Download latest bench patch artifact from heavy workflow | |
| uses: dawidd6/action-download-artifact@v3 | |
| with: | |
| workflow: run-benchmarks.yml | |
| pr: ${{ github.event.pull_request.number }} | |
| name: bench-patch | |
| path: .bench_patch | |
| allow_forks: true | |
| check_artifacts: true | |
| search_artifacts: true | |
| workflow_conclusion: "" | |
| if_no_artifact_found: warn | |
| - name: Apply and commit patch | |
| run: | | |
| set -euo pipefail | |
| if [ ! -d ".bench_patch" ]; then | |
| echo "No bench-patch artifact directory found." | |
| exit 0 | |
| fi | |
| if [ ! -f ".bench_patch/benchmark_patch.diff" ]; then | |
| echo "No benchmark_patch.diff found (likely no auto-patch possible)." | |
| if [ -f ".bench_patch/summary.txt" ]; then | |
| echo "Summary from heavy workflow:" | |
| sed -n '1,200p' .bench_patch/summary.txt || true | |
| fi | |
| exit 0 | |
| fi | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Apply with 3-way merge to be resilient to PR changes | |
| if ! git apply --index --3way .bench_patch/benchmark_patch.diff; then | |
| echo "Patch failed to apply cleanly. Please re-run Validate-Benchmarks to regenerate the patch." | |
| exit 1 | |
| fi | |
| if git diff --cached --quiet; then | |
| echo "Patch applied but produced no changes (already up to date)." | |
| exit 0 | |
| fi | |
| echo "==== diff preview ====" | |
| git diff --cached --stat | |
| git diff --cached | head -n 100 || true | |
| echo "======================" | |
| branch=$(git symbolic-ref --quiet --short HEAD || true) | |
| if [ -z "$branch" ]; then | |
| echo "Not on a branch - cannot push" >&2 | |
| exit 1 | |
| fi | |
| git commit -m "auto-update benchmark weights" | |
| git push origin "HEAD:${branch}" | |
| - name: Remove apply-benchmark-patch label | |
| if: ${{ success() }} | |
| run: | | |
| gh pr edit ${{ github.event.pull_request.number }} \ | |
| --repo "${{ github.repository }}" \ | |
| --remove-label "apply-benchmark-patch" || true |