|
| 1 | +name: Benchmark |
| 2 | +on: |
| 3 | + issue_comment: |
| 4 | + types: [created] |
| 5 | + pull_request: |
| 6 | + types: [labeled] |
| 7 | +jobs: |
| 8 | + benchmark: |
| 9 | + name: Benchmark |
| 10 | + if: | |
| 11 | + (github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '/benchmark')) || |
| 12 | + (github.event_name == 'pull_request' && github.event.label.name == 'benchmark') |
| 13 | + runs-on: macos-26 |
| 14 | + permissions: |
| 15 | + contents: read |
| 16 | + pull-requests: write |
| 17 | + steps: |
| 18 | + - name: Get PR number |
| 19 | + id: pr-number |
| 20 | + run: | |
| 21 | + if [ "${{ github.event_name }}" = "issue_comment" ]; then |
| 22 | + echo "number=${{ github.event.issue.number }}" >> "$GITHUB_OUTPUT" |
| 23 | + else |
| 24 | + echo "number=${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT" |
| 25 | + fi |
| 26 | +
|
| 27 | + - name: Get PR details |
| 28 | + id: pr |
| 29 | + env: |
| 30 | + GH_TOKEN: ${{ github.token }} |
| 31 | + run: | |
| 32 | + PR_DATA=$(gh api repos/${{ github.repository }}/pulls/${{ steps.pr-number.outputs.number }}) |
| 33 | + HEAD_SHA=$(echo "$PR_DATA" | jq -r '.head.sha') |
| 34 | + HEAD_REF=$(echo "$PR_DATA" | jq -r '.head.ref') |
| 35 | + BASE_REF=$(echo "$PR_DATA" | jq -r '.base.ref') |
| 36 | + echo "head_sha=$HEAD_SHA" >> "$GITHUB_OUTPUT" |
| 37 | + echo "head_ref=$HEAD_REF" >> "$GITHUB_OUTPUT" |
| 38 | + echo "base_ref=$BASE_REF" >> "$GITHUB_OUTPUT" |
| 39 | +
|
| 40 | + - name: Add reaction to comment |
| 41 | + if: github.event_name == 'issue_comment' |
| 42 | + env: |
| 43 | + GH_TOKEN: ${{ github.token }} |
| 44 | + run: | |
| 45 | + gh api repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions \ |
| 46 | + -f content='+1' |
| 47 | +
|
| 48 | + - uses: actions/checkout@master |
| 49 | + with: |
| 50 | + ref: ${{ steps.pr.outputs.head_sha }} |
| 51 | + fetch-depth: 0 |
| 52 | + |
| 53 | + - name: Select Xcode version |
| 54 | + run: sudo xcode-select -s /Applications/Xcode_26.2.0.app |
| 55 | + |
| 56 | + - name: Install hyperfine |
| 57 | + run: brew install hyperfine |
| 58 | + |
| 59 | + - name: Get merge-base |
| 60 | + id: commits |
| 61 | + run: | |
| 62 | + git fetch origin ${{ steps.pr.outputs.base_ref }} |
| 63 | + MERGE_BASE=$(git merge-base HEAD origin/${{ steps.pr.outputs.base_ref }}) |
| 64 | + echo "merge_base=$MERGE_BASE" >> "$GITHUB_OUTPUT" |
| 65 | + echo "Head SHA: ${{ steps.pr.outputs.head_sha }}" |
| 66 | + echo "Merge-base SHA: $MERGE_BASE" |
| 67 | +
|
| 68 | + - name: Build PR |
| 69 | + run: swift build -c release --product periphery --enable-index-store |
| 70 | + |
| 71 | + - name: Benchmark HEAD |
| 72 | + run: | |
| 73 | + hyperfine --show-output --warmup 3 --export-json head-benchmark.json './.build/release/periphery scan --quiet --skip-build --strict --baseline baselines/macOS-release.json --index-store-path .build/release/index/store' |
| 74 | +
|
| 75 | + - name: Build merge-base |
| 76 | + run: | |
| 77 | + git checkout ${{ steps.commits.outputs.merge_base }} |
| 78 | + swift build -c release --product periphery --enable-index-store |
| 79 | +
|
| 80 | + - name: Benchmark merge-base |
| 81 | + run: | |
| 82 | + hyperfine --warmup 3 --export-json base-benchmark.json './.build/release/periphery scan --quiet --skip-build --strict --baseline baselines/macOS-release.json --index-store-path .build/release/index/store' |
| 83 | +
|
| 84 | + - name: Post results |
| 85 | + env: |
| 86 | + GH_TOKEN: ${{ github.token }} |
| 87 | + run: | |
| 88 | + HEAD_MEAN=$(jq '.results[0].mean' head-benchmark.json) |
| 89 | + BASE_MEAN=$(jq '.results[0].mean' base-benchmark.json) |
| 90 | + HEAD_STDDEV=$(jq '.results[0].stddev' head-benchmark.json) |
| 91 | + BASE_STDDEV=$(jq '.results[0].stddev' base-benchmark.json) |
| 92 | +
|
| 93 | + CHANGE=$(echo "scale=2; (($HEAD_MEAN - $BASE_MEAN) / $BASE_MEAN) * 100" | bc) |
| 94 | +
|
| 95 | + COMMENT="## Benchmark Results |
| 96 | +
|
| 97 | + | Commit | Mean (s) | Std Dev (s) | |
| 98 | + |--------|----------|-------------| |
| 99 | + | Merge-base (\`$(echo ${{ steps.commits.outputs.merge_base }} | cut -c1-7)\`) | $(printf "%.3f" $BASE_MEAN) | ±$(printf "%.3f" $BASE_STDDEV) | |
| 100 | + | HEAD (\`$(echo ${{ steps.pr.outputs.head_sha }} | cut -c1-7)\`) | $(printf "%.3f" $HEAD_MEAN) | ±$(printf "%.3f" $HEAD_STDDEV) | |
| 101 | +
|
| 102 | + **Change: $(printf "%+.1f%%" $CHANGE)**" |
| 103 | +
|
| 104 | + gh pr comment ${{ steps.pr-number.outputs.number }} --body "$COMMENT" |
| 105 | +
|
| 106 | + - name: Remove benchmark label |
| 107 | + if: github.event_name == 'pull_request' |
| 108 | + env: |
| 109 | + GH_TOKEN: ${{ github.token }} |
| 110 | + run: | |
| 111 | + gh pr edit ${{ steps.pr-number.outputs.number }} --remove-label benchmark |
| 112 | +
|
| 113 | + - name: Upload benchmark results |
| 114 | + uses: actions/upload-artifact@v4 |
| 115 | + with: |
| 116 | + name: benchmark-results |
| 117 | + path: "*-benchmark.json" |
0 commit comments