Runtime performance comment #113
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: Runtime performance comment | |
| on: | |
| workflow_run: | |
| workflows: [Runtime performance] | |
| types: [completed] | |
| concurrency: | |
| group: runtime-performance-comment-${{ github.event.workflow_run.head_repository.id }}-${{ github.event.workflow_run.head_branch }} | |
| cancel-in-progress: true | |
| permissions: | |
| actions: read | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| jobs: | |
| comment: | |
| if: >- | |
| github.event.workflow_run.event == 'pull_request' && | |
| github.event.workflow_run.conclusion != 'cancelled' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out trusted reporting code | |
| uses: actions/checkout@v7 | |
| - name: Download performance report | |
| id: download | |
| continue-on-error: true | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: runtime-performance-report | |
| path: report | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - name: Render report from validated benchmark data | |
| if: steps.download.outcome == 'success' | |
| run: >- | |
| node scripts/compare-runtime-performance.mjs | |
| report/base | |
| report/head | |
| > "$RUNNER_TEMP/report.md" | |
| - name: Create or update pull request comment | |
| if: steps.download.outcome == 'success' | |
| uses: actions/github-script@v9 | |
| env: | |
| REPORT_PATH: ${{ runner.temp }}/report.md | |
| with: | |
| script: | | |
| const fs = require("node:fs") | |
| const marker = "<!-- effect-machine-runtime-performance -->" | |
| const report = fs.readFileSync(process.env.REPORT_PATH, "utf8") | |
| if (Buffer.byteLength(report, "utf8") > 60_000) { | |
| core.setFailed("Runtime-performance report exceeds the safe comment size") | |
| return | |
| } | |
| const run = context.payload.workflow_run | |
| let pull = run.pull_requests?.[0] | |
| if (pull === undefined) { | |
| try { | |
| const associated = await github.rest.repos.listPullRequestsAssociatedWithCommit({ | |
| ...context.repo, | |
| commit_sha: run.head_sha | |
| }) | |
| pull = associated.data.find((candidate) => | |
| candidate.base.repo.full_name === `${context.repo.owner}/${context.repo.repo}` | |
| ) | |
| } catch (error) { | |
| core.warning(`Unable to look up a pull request for ${run.head_sha}: ${error.message}`) | |
| } | |
| } | |
| if (pull === undefined) { | |
| core.notice("No pull request is associated with this workflow run") | |
| return | |
| } | |
| const body = `${marker}\n${report}` | |
| const comments = await github.paginate(github.rest.issues.listComments, { | |
| ...context.repo, | |
| issue_number: pull.number, | |
| per_page: 100 | |
| }) | |
| const previous = comments.find((comment) => | |
| comment.user?.type === "Bot" && comment.body?.startsWith(marker) | |
| ) | |
| if (previous === undefined) { | |
| await github.rest.issues.createComment({ | |
| ...context.repo, | |
| issue_number: pull.number, | |
| body | |
| }) | |
| } else { | |
| await github.rest.issues.updateComment({ | |
| ...context.repo, | |
| comment_id: previous.id, | |
| body | |
| }) | |
| } |