Skip to content

Commit

Permalink
Add job for commenting benchmark results on the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
gruuya committed Mar 6, 2024
1 parent f51a754 commit b92732e
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions .github/workflows/pr_benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
ref: ${{ github.event.pull_request.base.sha }}
clean: false

- name: Benchmark baseline and compare
- name: Benchmark baseline and generate comparison message
env:
RESULTS_NAME: ${{ env.BASE_REF_SHA }}
run: |
Expand All @@ -60,4 +60,55 @@ jobs:
mv -f results/HEAD results/${{ env.BASE_REF_SHA }}
pip3 install rich
./bench.sh compare ${{ env.BASE_REF_SHA }} ${{ env.HEAD_REF_SHA }}
cat > message.md <<EOF
# Benchmark results
<details>
<summary>Benchmarks comparing ${{ github.event.pull_request.base.sha }} and ${{ github.sha }}</summary>
\`\`\`
$(./bench.sh compare ${{ env.BASE_REF_SHA }} ${{ env.HEAD_REF_SHA }})
\`\`\`
</details>
EOF
cat message.md
- name: Upload benchmark comparison message
uses: actions/upload-artifact@v4
with:
name: message
path: benchmarks/message.md

comment:
name: Post benchmarks in PR comment
runs-on: ubuntu-latest
needs: [benchmark]
permissions:
pull-requests: write
steps:
- name: Download comment message
uses: actions/download-artifact@v4
with:
name: message
path: benchmarks

- name: Print benchmarks
run: |
cat benchmarks/message.md
- name: Post a comment
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const fs = require('fs');
const content = fs.readFileSync('benchmarks/message.md', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: content,
})

0 comments on commit b92732e

Please sign in to comment.