How to Post a Benchmark Comment on PRs in GitHub Actions
Benchmark numbers buried in logs get ignored; surfacing them as a PR comment makes regressions impossible to miss.
Run the benchmark, format the result into Markdown, and post it as a sticky comment that updates in place on each push.
Steps
- Trigger on
pull_request. - Run the benchmark and write a Markdown summary file.
- Post it with a sticky-comment action keyed by a header.
- Grant
pull-requests: writeso the comment can be created.
Workflow
.github/workflows/bench.yml
on: pull_request
permissions:
pull-requests: write
jobs:
bench:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: run
run: |
RESULT=$(./bench.sh)
{
echo "result<<EOF"
echo "### Benchmark"
echo "$RESULT"
echo "EOF"
} >> "${GITHUB_OUTPUT}"
- uses: marocchino/sticky-pull-request-comment@v2
with:
header: bench
message: ${{ steps.run.outputs.result }}Gotchas
- Shared CI runners are noisy; compare relative deltas, not absolute numbers, to avoid false alarms.
- A sticky header keeps one comment instead of a new one per push.
- Latchkey runs benchmarks on consistent, cheaper runners that retry on transient failures for steadier numbers.
Related guides
How to Fail the Build on a Coverage Drop in GitHub ActionsFail a GitHub Actions build when test coverage falls below a threshold, parsing the coverage percentage from…
How to Cancel Duplicate Runs on the Same Ref in GitHub ActionsCancel superseded GitHub Actions runs on the same branch or PR using a concurrency group keyed on the ref so…