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 e371175
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 2 deletions.
54 changes: 52 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,54 @@ 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

- 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,
})
62 changes: 62 additions & 0 deletions .github/workflows/pr_comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Comment on the pull request

# read-write repo token
# access to secrets
on:
workflow_run:
workflows: ["Run and Cache Benchmarks"]
types:
- completed

jobs:
upload:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"

- name: Download artifact
uses: actions/github-script@v7
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "message"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/message.zip', Buffer.from(download.data));
- name: Print benchmarks
run: |
unzip message.zip
cat message.md
# - name: Post the comment
# uses: actions/github-script@v7
# with:
# script: |
# const fs = require('fs');
# const content = fs.readFileSync('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 e371175

Please sign in to comment.