|
| 1 | +name: Analysis Benchmark |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: [main] |
| 7 | + |
| 8 | +env: |
| 9 | + BCR_VERSION: "2.0.0-alpha.4" |
| 10 | + |
| 11 | +jobs: |
| 12 | + benchmark: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout PR |
| 19 | + uses: actions/checkout@v6 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + path: rules_py_pr |
| 23 | + |
| 24 | + - name: Checkout HEAD main |
| 25 | + uses: actions/checkout@v6 |
| 26 | + with: |
| 27 | + ref: main |
| 28 | + path: rules_py_main |
| 29 | + |
| 30 | + - name: Install hyperfine |
| 31 | + run: | |
| 32 | + set -euo pipefail |
| 33 | + HYPERFINE_VERSION="1.18.0" |
| 34 | + DEB="hyperfine_${HYPERFINE_VERSION}_amd64.deb" |
| 35 | + URL="https://github.com/sharkdp/hyperfine/releases/download/v${HYPERFINE_VERSION}/${DEB}" |
| 36 | + wget -qO "$DEB" "$URL" |
| 37 | + sudo dpkg -i "$DEB" |
| 38 | + rm -f "$DEB" |
| 39 | + hyperfine --version |
| 40 | +
|
| 41 | + # ── BCR baseline ──────────────────────────────────────────────────────── |
| 42 | + - name: Benchmark BCR ${{ env.BCR_VERSION }} |
| 43 | + run: | |
| 44 | + set -euo pipefail |
| 45 | + cd rules_py_pr/benchmark/analysis |
| 46 | + python3 generate_module.py bcr --version "${BCR_VERSION}" |
| 47 | + python3 workspace/generate_workspace.py --root workspace --packages 50 |
| 48 | +
|
| 49 | + OUT_BASE="/tmp/bazel-bcr" |
| 50 | + rm -rf "$OUT_BASE" |
| 51 | +
|
| 52 | + # Populate repository cache so the measured runs are analysis-only. |
| 53 | + bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc fetch //workspace/... |
| 54 | +
|
| 55 | + hyperfine --warmup 1 --runs 10 \ |
| 56 | + --prepare 'rm -rf /tmp/bazel-bcr-analysis' \ |
| 57 | + --export-json "${GITHUB_WORKSPACE}/bcr.json" \ |
| 58 | + 'bazel --output_base=/tmp/bazel-bcr-analysis --bazelrc=../../.github/workflows/ci.bazelrc build --disk_cache= --nobuild //workspace/...' |
| 59 | +
|
| 60 | + # Auxiliary metrics: loaded packages and discovered targets. |
| 61 | + bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc query //workspace/... --output=package > /tmp/bcr-packages.txt |
| 62 | + bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc query //workspace/... > /tmp/bcr-targets.txt |
| 63 | + echo "{\"packages\": $(wc -l < /tmp/bcr-packages.txt | tr -d ' '), \"targets\": $(wc -l < /tmp/bcr-targets.txt | tr -d ' ')}" > "${GITHUB_WORKSPACE}/bcr-aux.json" |
| 64 | +
|
| 65 | + # ── HEAD main ─────────────────────────────────────────────────────────── |
| 66 | + - name: Benchmark HEAD main |
| 67 | + run: | |
| 68 | + set -euo pipefail |
| 69 | + cd rules_py_pr/benchmark/analysis |
| 70 | + python3 generate_module.py local --path "$GITHUB_WORKSPACE/rules_py_main" |
| 71 | + python3 workspace/generate_workspace.py --root workspace --packages 50 |
| 72 | +
|
| 73 | + OUT_BASE="/tmp/bazel-main" |
| 74 | + rm -rf "$OUT_BASE" |
| 75 | +
|
| 76 | + bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc fetch //workspace/... |
| 77 | +
|
| 78 | + hyperfine --warmup 1 --runs 10 \ |
| 79 | + --prepare 'rm -rf /tmp/bazel-main-analysis' \ |
| 80 | + --export-json "${GITHUB_WORKSPACE}/main.json" \ |
| 81 | + 'bazel --output_base=/tmp/bazel-main-analysis --bazelrc=../../.github/workflows/ci.bazelrc build --disk_cache= --nobuild //workspace/...' |
| 82 | +
|
| 83 | + bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc query //workspace/... --output=package > /tmp/main-packages.txt |
| 84 | + bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc query //workspace/... > /tmp/main-targets.txt |
| 85 | + echo "{\"packages\": $(wc -l < /tmp/main-packages.txt | tr -d ' '), \"targets\": $(wc -l < /tmp/main-targets.txt | tr -d ' ')}" > "${GITHUB_WORKSPACE}/main-aux.json" |
| 86 | +
|
| 87 | + # ── Current commit (PR) ───────────────────────────────────────────────── |
| 88 | + - name: Benchmark current PR |
| 89 | + run: | |
| 90 | + set -euo pipefail |
| 91 | + cd rules_py_pr/benchmark/analysis |
| 92 | + python3 generate_module.py local --path "$GITHUB_WORKSPACE/rules_py_pr" |
| 93 | + python3 workspace/generate_workspace.py --root workspace --packages 50 |
| 94 | +
|
| 95 | + OUT_BASE="/tmp/bazel-pr" |
| 96 | + rm -rf "$OUT_BASE" |
| 97 | +
|
| 98 | + bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc fetch //workspace/... |
| 99 | +
|
| 100 | + hyperfine --warmup 1 --runs 10 \ |
| 101 | + --prepare 'rm -rf /tmp/bazel-pr-analysis' \ |
| 102 | + --export-json "${GITHUB_WORKSPACE}/pr.json" \ |
| 103 | + 'bazel --output_base=/tmp/bazel-pr-analysis --bazelrc=../../.github/workflows/ci.bazelrc build --disk_cache= --nobuild //workspace/...' |
| 104 | +
|
| 105 | + bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc query //workspace/... --output=package > /tmp/pr-packages.txt |
| 106 | + bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc query //workspace/... > /tmp/pr-targets.txt |
| 107 | + echo "{\"packages\": $(wc -l < /tmp/pr-packages.txt | tr -d ' '), \"targets\": $(wc -l < /tmp/pr-targets.txt | tr -d ' ')}" > "${GITHUB_WORKSPACE}/pr-aux.json" |
| 108 | +
|
| 109 | + # ── Compare & gate ────────────────────────────────────────────────────── |
| 110 | + - name: Compare results |
| 111 | + id: compare |
| 112 | + continue-on-error: true |
| 113 | + run: | |
| 114 | + set -euo pipefail |
| 115 | + for f in bcr.json main.json pr.json; do |
| 116 | + if [[ ! -f "$f" ]]; then |
| 117 | + echo "ERROR: missing result file: $f" |
| 118 | + exit 1 |
| 119 | + fi |
| 120 | + done |
| 121 | + python3 rules_py_pr/benchmark/analysis/compare.py bcr.json main.json pr.json | tee benchmark-table.txt |
| 122 | +
|
| 123 | + - name: Save PR number |
| 124 | + if: github.event_name == 'pull_request' |
| 125 | + run: echo "${{ github.event.pull_request.number }}" > pr-number.txt |
| 126 | + |
| 127 | + - name: Upload benchmark artifacts |
| 128 | + if: github.event_name == 'pull_request' |
| 129 | + uses: actions/upload-artifact@v4 |
| 130 | + with: |
| 131 | + name: analysis-benchmark-results |
| 132 | + path: | |
| 133 | + bcr.json |
| 134 | + main.json |
| 135 | + pr.json |
| 136 | + bcr-aux.json |
| 137 | + main-aux.json |
| 138 | + pr-aux.json |
| 139 | + benchmark-table.txt |
| 140 | + pr-number.txt |
| 141 | + if-no-files-found: warn |
| 142 | + |
| 143 | + - name: Fail on regression |
| 144 | + if: steps.compare.outcome == 'failure' |
| 145 | + run: exit 1 |
0 commit comments