Post Benchmark Comment #299
This file contains hidden or 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: Post Benchmark Comment | |
| on: | |
| workflow_run: | |
| workflows: [CI] | |
| types: [completed] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.workflow_run.pull_requests[0].number || github.run_id }} | |
| cancel-in-progress: true | |
| jobs: | |
| comment: | |
| runs-on: ubuntu-latest | |
| if: | | |
| github.event.workflow_run.event == 'pull_request' && | |
| github.event.workflow_run.conclusion == 'success' | |
| permissions: | |
| pull-requests: write | |
| actions: read | |
| steps: | |
| - name: Download benchmark artifact | |
| uses: actions/download-artifact@v5 | |
| with: | |
| name: benchmark-results | |
| path: benchmark-results | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Post or update benchmark comment | |
| uses: actions/github-script@v8 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const fs = require('fs'); | |
| const benchmarkContent = fs.readFileSync('benchmark-results/BENCHMARK.md', 'utf8'); | |
| const prNumber = context.payload.workflow_run.pull_requests?.[0]?.number; | |
| if (!prNumber) { | |
| core.info('No PR number found, skipping comment.'); | |
| return; | |
| } | |
| const body = `## 📊 Benchmark Results\n\n${benchmarkContent}\n\n<details>\n<summary>ℹ️ Benchmark Details</summary>\n\nMetrics:\n- CU Consumed: Compute Units used by each instruction\n- Binary Size: Size of the compiled program binary\n\n</details>\n\nBenchmarks run on commit \`${context.payload.workflow_run.head_sha.slice(0, 7)}\``; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| const botComment = comments.find(c => | |
| c.user.login === 'github-actions[bot]' && c.body.includes('📊 Benchmark Results') | |
| ); | |
| if (botComment) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body, | |
| }); | |
| } |