Comment benchmark results on a PR #750
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Comment benchmark results on a PR | |
on: | |
workflow_run: | |
workflows: ["benchmark"] | |
types: | |
- completed | |
jobs: | |
comment: | |
runs-on: ubuntu-latest | |
permissions: | |
# list and download artifact | |
actions: read | |
# post benchmark results | |
pull-requests: write | |
steps: | |
- uses: actions/github-script@v6 | |
with: | |
script: | | |
var artifacts = await github.rest.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 == "benchmark-comment" | |
})[0]; | |
var download = await github.rest.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}}/benchmark-comment.zip', Buffer.from(download.data)); | |
- id: unpack | |
run: | | |
mkdir -p benchmark-comment | |
unzip -d benchmark-comment benchmark-comment.zip | |
echo "pr-number=$(cat benchmark-comment/pr-number)" >> $GITHUB_OUTPUT | |
COMMENT=$(cat benchmark-comment/benchstat.txt) | |
COMMENT="${COMMENT//'%'/'%25'}" | |
COMMENT="${COMMENT//$'\n'/'%0A'}" | |
COMMENT="${COMMENT//$'\r'/'%0D'}" | |
echo "comment=$COMMENT" >> $GITHUB_OUTPUT | |
- name: post benchmark results | |
uses: marocchino/sticky-pull-request-comment@v2 | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
header: Benchmark Results | |
number: ${{ steps.unpack.outputs.pr-number }} | |
message: | | |
## Benchmark Result | |
<details><summary>Benchmark diff with base</summary> | |
``` | |
${{ steps.unpack.outputs.comment }} | |
``` | |
</details> |