|
| 1 | +# .github/workflows/apply-benchmark-patch.yml |
| 2 | +name: Apply-Benchmark-Patch |
| 3 | + |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + types: [labeled] |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + pull-requests: write |
| 11 | + actions: read # required to list & download artifacts across workflows |
| 12 | + |
| 13 | +jobs: |
| 14 | + apply: |
| 15 | + if: ${{ github.event.label.name == 'apply-benchmark-patch' }} |
| 16 | + runs-on: Benchmarking |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Check out PR branch |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 23 | + ref: ${{ github.event.pull_request.head.ref }} |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Install GitHub CLI |
| 27 | + run: | |
| 28 | + sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get update |
| 29 | + 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 |
| 30 | + echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token |
| 31 | +
|
| 32 | + - name: Download latest bench patch artifact from heavy workflow |
| 33 | + uses: dawidd6/action-download-artifact@v3 |
| 34 | + with: |
| 35 | + workflow: run-benchmarks.yml |
| 36 | + pr: ${{ github.event.pull_request.number }} |
| 37 | + name: bench-patch |
| 38 | + path: . |
| 39 | + allow_forks: true |
| 40 | + check_artifacts: true |
| 41 | + search_artifacts: true |
| 42 | + workflow_conclusion: "" |
| 43 | + if_no_artifact_found: warn |
| 44 | + |
| 45 | + - name: Extract bench patch archive |
| 46 | + run: | |
| 47 | + set -euo pipefail |
| 48 | + if [ -f "bench-patch.tgz" ]; then |
| 49 | + tar -xzf bench-patch.tgz |
| 50 | + elif [ -f "bench-patch/bench-patch.tgz" ]; then |
| 51 | + tar -xzf bench-patch/bench-patch.tgz |
| 52 | + else |
| 53 | + echo "No bench-patch.tgz found after download." |
| 54 | + exit 0 |
| 55 | + fi |
| 56 | + ls -la .bench_patch || true |
| 57 | +
|
| 58 | + - name: Apply and commit patch |
| 59 | + run: | |
| 60 | + set -euo pipefail |
| 61 | +
|
| 62 | + if [ ! -d ".bench_patch" ]; then |
| 63 | + echo "No .bench_patch directory found after extraction." |
| 64 | + exit 0 |
| 65 | + fi |
| 66 | +
|
| 67 | + if [ -f ".bench_patch/summary.txt" ]; then |
| 68 | + echo "==== summary.txt ====" |
| 69 | + sed -n '1,200p' .bench_patch/summary.txt || true |
| 70 | + echo "=====================" |
| 71 | + fi |
| 72 | +
|
| 73 | + if [ ! -f ".bench_patch/benchmark_patch.diff" ]; then |
| 74 | + echo "No benchmark_patch.diff found (no auto-patch created)." |
| 75 | + exit 0 |
| 76 | + fi |
| 77 | +
|
| 78 | + git config user.name "github-actions[bot]" |
| 79 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 80 | +
|
| 81 | + if ! git apply --index --3way .bench_patch/benchmark_patch.diff; then |
| 82 | + echo "Patch failed to apply cleanly. Please re-run Validate-Benchmarks to regenerate." |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | +
|
| 86 | + if git diff --cached --quiet; then |
| 87 | + echo "Patch applied but produced no changes (already up to date)." |
| 88 | + exit 0 |
| 89 | + fi |
| 90 | +
|
| 91 | + echo "==== diff preview ====" |
| 92 | + git diff --cached --stat |
| 93 | + git diff --cached | head -n 120 || true |
| 94 | + echo "======================" |
| 95 | +
|
| 96 | + branch=$(git symbolic-ref --quiet --short HEAD || true) |
| 97 | + if [ -z "$branch" ]; then |
| 98 | + echo "Not on a branch - cannot push" >&2 |
| 99 | + exit 1 |
| 100 | + fi |
| 101 | +
|
| 102 | + git commit -m "auto-update benchmark weights" |
| 103 | + git push origin "HEAD:${branch}" |
| 104 | +
|
| 105 | + - name: Remove apply-benchmark-patch label |
| 106 | + if: ${{ success() }} |
| 107 | + run: | |
| 108 | + gh pr edit ${{ github.event.pull_request.number }} \ |
| 109 | + --repo "${{ github.repository }}" \ |
| 110 | + --remove-label "apply-benchmark-patch" || true |
0 commit comments