|
| 1 | +name: Benchmark |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + issue_comment: |
| 9 | + types: [created, edited] |
| 10 | + |
| 11 | +# We use a specific version so that the results are not changed because of rustc updates. |
| 12 | +env: |
| 13 | + RUSTC_VERSION: 1.89.0 |
| 14 | + |
| 15 | +permissions: |
| 16 | + # deployments permission to deploy GitHub pages website |
| 17 | + deployments: write |
| 18 | + # contents permission to update benchmark contents in gh-pages branch |
| 19 | + contents: write |
| 20 | + # allow posting comments to pull request |
| 21 | + pull-requests: write |
| 22 | + |
| 23 | +jobs: |
| 24 | + run-benchmark: |
| 25 | + if: > |
| 26 | + (contains(github.event.comment.html_url, '/pull/') && contains(github.event.comment.body, '/benchmark')) |
| 27 | + || github.event_name == 'push' |
| 28 | + || github.event.pull_request.head.repo.full_name == github.repository |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + - name: Switch to correct PR |
| 33 | + if: github.event_name == 'issue_comment' |
| 34 | + run: gh pr checkout ${{ github.event.issue.number }} |
| 35 | + env: |
| 36 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + - uses: dtolnay/rust-toolchain@master |
| 38 | + with: |
| 39 | + toolchain: ${{ env.RUSTC_VERSION }} |
| 40 | + - uses: Swatinem/rust-cache@v2 |
| 41 | + - name: Get rustc version |
| 42 | + id: rustc_version |
| 43 | + run: echo "version=$(rustc --version)" >> $GITHUB_OUTPUT |
| 44 | + - name: Run benchmark |
| 45 | + run: cargo +${{ env.RUSTC_VERSION }} bench --locked -- --output-format bencher | tee output.txt |
| 46 | + - name: Store benchmark result |
| 47 | + uses: benchmark-action/github-action-benchmark@v1 |
| 48 | + with: |
| 49 | + name: Rust Benchmark (${{ env.RUSTC_VERSION }}) |
| 50 | + tool: 'cargo' |
| 51 | + output-file-path: output.txt |
| 52 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + fail-on-alert: false |
| 54 | + comment-always: true |
| 55 | + summary-always: true |
| 56 | + # auto-push: ${{ github.event_name == 'push' }} |
| 57 | + auto-push: true |
0 commit comments