|
| 1 | +name: Benchmarks |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - synchronize |
| 8 | + |
| 9 | +jobs: |
| 10 | + lint: |
| 11 | + name: Benchmark tests |
| 12 | + runs-on: ubuntu-latest |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + python_version: [3.12] |
| 16 | + steps: |
| 17 | + - name: Checkout branch |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + path: pr |
| 21 | + |
| 22 | + - name: Checkout main |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + ref: main |
| 26 | + path: main |
| 27 | + |
| 28 | + - name: Install python |
| 29 | + uses: actions/setup-python@v5 |
| 30 | + with: |
| 31 | + python-version: ${{matrix.python_version}} |
| 32 | + |
| 33 | + - name: Install uv |
| 34 | + uses: astral-sh/setup-uv@v4 |
| 35 | + with: |
| 36 | + enable-cache: true |
| 37 | + cache-dependency-glob: "main/uv.lock" |
| 38 | + |
| 39 | + - name: Setup benchmarks |
| 40 | + run: | |
| 41 | + echo "BASE_SHA=$(echo ${{ github.event.pull_request.base.sha }} | cut -c1-8)" >> $GITHUB_ENV |
| 42 | + echo "HEAD_SHA=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-8)" >> $GITHUB_ENV |
| 43 | + echo "PR_COMMENT=$(mktemp)" >> $GITHUB_ENV |
| 44 | +
|
| 45 | + - name: Run benchmarks on PR |
| 46 | + working-directory: ./pr |
| 47 | + run: | |
| 48 | + uv sync --group test |
| 49 | + uv run pytest --benchmark-only --benchmark-save=pr |
| 50 | +
|
| 51 | + - name: Run benchmarks on main |
| 52 | + working-directory: ./main |
| 53 | + continue-on-error: true |
| 54 | + run: | |
| 55 | + uv sync --group test |
| 56 | + uv run pytest --benchmark-only --benchmark-save=base |
| 57 | +
|
| 58 | + - name: Compare results |
| 59 | + continue-on-error: false |
| 60 | + run: | |
| 61 | + uvx pytest-benchmark compare **/.benchmarks/**/*.json | tee cmp_results |
| 62 | +
|
| 63 | + echo 'Benchmark comparison for [`${{ env.BASE_SHA }}`](${{ github.event.repository.html_url }}/commit/${{ github.event.pull_request.base.sha }}) (base) vs [`${{ env.HEAD_SHA }}`](${{ github.event.repository.html_url }}/commit/${{ github.event.pull_request.head.sha }}) (PR)' >> pr_comment |
| 64 | + echo '```' >> pr_comment |
| 65 | + cat cmp_results >> pr_comment |
| 66 | + echo '```' >> pr_comment |
| 67 | + cat pr_comment > ${{ env.PR_COMMENT }} |
| 68 | + |
| 69 | + - name: Comment on PR |
| 70 | + uses: actions/github-script@v7 |
| 71 | + with: |
| 72 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 73 | + script: | |
| 74 | + github.rest.issues.createComment({ |
| 75 | + issue_number: context.issue.number, |
| 76 | + owner: context.repo.owner, |
| 77 | + repo: context.repo.repo, |
| 78 | + body: require('fs').readFileSync('${{ env.PR_COMMENT }}').toString() |
| 79 | + }); |
| 80 | +
|
0 commit comments