summaryrefslogtreecommitdiff
path: root/.github/workflows/benchmark-comment.yml
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2026-05-21 19:04:01 +1000
committerGitHub <noreply@github.com>2026-05-21 19:04:01 +1000
commit816332cbaf256c405a109d8cc16fec8f15df907e (patch)
treecb058fae973f81e86316657e5abba5d4fb8f7e29 /.github/workflows/benchmark-comment.yml
parent5b4b6bde235e47fcc7074578673dfea1077771a7 (diff)
Added benchmarking to the CI (#423)
* Added benchmarking to the CI * Updated writing access of benchmark.yml * Added benchmark-comment.yml that pushes the comment to the PR * Added read permission
Diffstat (limited to '.github/workflows/benchmark-comment.yml')
-rw-r--r--.github/workflows/benchmark-comment.yml90
1 files changed, 90 insertions, 0 deletions
diff --git a/.github/workflows/benchmark-comment.yml b/.github/workflows/benchmark-comment.yml
new file mode 100644
index 00000000..c095162e
--- /dev/null
+++ b/.github/workflows/benchmark-comment.yml
@@ -0,0 +1,90 @@
+name: Benchmark Comment
+
+on:
+ workflow_run:
+ workflows: [Benchmark]
+ types: [completed]
+
+jobs:
+ comment-pr:
+ name: Post benchmark comment
+ # Only run when triggered by a pull_request event and the benchmark succeeded.
+ if: >
+ github.event.workflow_run.conclusion == 'success' &&
+ github.event.workflow_run.event == 'pull_request'
+ runs-on: ubuntu-latest
+
+ permissions:
+ contents: read
+ actions: read
+ pull-requests: write
+ issues: write
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Download benchmark results
+ uses: actions/download-artifact@v4
+ with:
+ run-id: ${{ github.event.workflow_run.id }}
+ name: benchmark-results
+ path: current-results
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Download PR number
+ uses: actions/download-artifact@v4
+ with:
+ run-id: ${{ github.event.workflow_run.id }}
+ name: pr-number
+ path: .
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Read PR number
+ id: pr
+ run: echo "number=$(cat pr-number.txt)" >> "$GITHUB_OUTPUT"
+
+ - name: Fetch baseline from benchmark-data branch
+ run: |
+ git fetch origin benchmark-data 2>/dev/null || true
+ git show origin/benchmark-data:benchmark-history.json > baseline.json 2>/dev/null \
+ || echo "[]" > baseline.json
+
+ - name: Generate comparison comment
+ run: |
+ python .github/scripts/compare_benchmarks.py \
+ current-results/results.json \
+ baseline.json \
+ > comment.md
+
+ - name: Post or update PR comment
+ uses: actions/github-script@v7
+ with:
+ script: |
+ const fs = require('fs');
+ const body = fs.readFileSync('comment.md', 'utf8');
+ const marker = '<!-- opendc-benchmark-comment -->';
+ const fullBody = marker + '\n' + body;
+ const prNumber = parseInt(fs.readFileSync('pr-number.txt', 'utf8').trim());
+
+ const { data: comments } = await github.rest.issues.listComments({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: prNumber,
+ });
+
+ const existing = comments.find(c => c.body.includes(marker));
+ if (existing) {
+ await github.rest.issues.updateComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ comment_id: existing.id,
+ body: fullBody,
+ });
+ } else {
+ await github.rest.issues.createComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: prNumber,
+ body: fullBody,
+ });
+ }