|
| 1 | +# Creates a PR benchmark comment with a comparison to main |
| 2 | +name: Benchmark pull requests |
| 3 | + |
| 4 | +on: |
| 5 | + issue_comment: |
| 6 | + types: [created] |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +jobs: |
| 13 | + setup: |
| 14 | + name: Comparative PR benchmark comment |
| 15 | + if: |
| 16 | + github.event.issue.pull_request |
| 17 | + && github.event.issue.state == 'open' |
| 18 | + && (contains(github.event.comment.body, '!benchmark')) |
| 19 | + && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + benches: ${{ steps.bench-params.outputs.benches }} |
| 23 | + env-vars: ${{ steps.bench-params.outputs.env-vars }} |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v5 |
| 26 | + - name: Parse PR comment body |
| 27 | + id: bench-params |
| 28 | + run: | |
| 29 | + # Parse `issue_comment` body |
| 30 | + printf '${{ github.event.comment.body }}' > comment.txt |
| 31 | + BENCH_COMMAND=$(head -n 1 comment.txt) |
| 32 | + echo "$BENCH_COMMAND" |
| 33 | +
|
| 34 | + BENCHES=$(echo $BENCH_COMMAND | awk -F'!benchmark ' '{ print $2 }') |
| 35 | + echo "BENCHES\n$BENCHES" |
| 36 | + JSON=$(echo $BENCHES | jq -R -c 'split(" ")') |
| 37 | +
|
| 38 | + #echo "benches<<EOF" >> $GITHUB_OUTPUT |
| 39 | + #echo "$JSON" | tee -a $GITHUB_OUTPUT |
| 40 | + #echo "EOF" >> $GITHUB_OUTPUT |
| 41 | + echo "JSON\n$JSON" |
| 42 | +
|
| 43 | + echo "benches=$JSON" | tee -a $GITHUB_OUTPUT |
| 44 | +
|
| 45 | + # Can't persist env vars between jobs, so we pass them as an output and set them in the next job |
| 46 | + echo "env-vars=$(tail -n +2 comment.txt)" | tee -a $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + benchmark: |
| 49 | + needs: [ setup ] |
| 50 | + runs-on: warp-ubuntu-latest-x64-16x |
| 51 | + strategy: |
| 52 | + matrix: |
| 53 | + # Runs a job for each benchmark specified in the `issue_comment` input |
| 54 | + bench: ${{ fromJSON(needs.setup.outputs.benches) }} |
| 55 | + steps: |
| 56 | + - name: Set env vars |
| 57 | + run: | |
| 58 | + # Trims newlines that may arise from `$GITHUB_OUTPUT` |
| 59 | + for var in ${{ inputs.default-env }} |
| 60 | + do |
| 61 | + echo "$(echo $var | tr -d '\n')" | tee -a $GITHUB_ENV |
| 62 | + done |
| 63 | + # Overrides default env vars with those specified in the `issue_comment` input if identically named |
| 64 | + for var in ${{ needs.setup.outputs.env-vars }} |
| 65 | + do |
| 66 | + echo "$(echo $var | tr -d '\n')" | tee -a $GITHUB_ENV |
| 67 | + done |
| 68 | + - uses: actions/checkout@v5 |
| 69 | + # Get base branch of the PR |
| 70 | + #- uses: xt0rted/pull-request-comment-branch@v2 |
| 71 | + # id: comment-branch |
| 72 | + - name: Checkout PR branch |
| 73 | + run: gh pr checkout $PR_NUMBER |
| 74 | + env: |
| 75 | + GH_TOKEN: ${{ github.token }} |
| 76 | + PR_NUMBER: ${{ github.event.issue.number }} |
| 77 | + - uses: leanprover/lean-action@v1 |
| 78 | + with: |
| 79 | + test: false |
| 80 | + - name: Run bench |
| 81 | + run: | |
| 82 | + lake exe ${{ matrix.bench }} | tee out.txt 2>&1 |
| 83 | + - name: Comment on successful run |
| 84 | + if: success() |
| 85 | + uses: peter-evans/create-or-update-comment@v4 |
| 86 | + with: |
| 87 | + issue-number: ${{ github.event.issue.number }} |
| 88 | + body: | |
| 89 | + `!${{ needs.setup.outputs.command }}` action succeeded! :rocket: |
| 90 | +
|
| 91 | + Bench output: |
| 92 | + $(cat out.txt) |
| 93 | +
|
| 94 | + https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 95 | +
|
| 96 | + - name: Comment on failing run |
| 97 | + if: failure() |
| 98 | + uses: peter-evans/create-or-update-comment@v4 |
| 99 | + with: |
| 100 | + issue-number: ${{ github.event.issue.number }} |
| 101 | + body: | |
| 102 | + `!${{ needs.setup.outputs.command }}` action failed :x: |
| 103 | +
|
| 104 | + https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |
0 commit comments