Skip to content

Prepare Release v0.9.1 #57

Prepare Release v0.9.1

Prepare Release v0.9.1 #57

Workflow file for this run

name: Benchmark Comparison
on:
pull_request:
# `labeled` so adding the `run-bench` label after opening starts a run;
# the job's `if:` skips unlabeled pull requests.
types: [opened, synchronize, reopened, labeled]
workflow_dispatch:
concurrency:
group: bench-${{ github.head_ref }}
cancel-in-progress: true
jobs:
bench-compare:
name: 'Benchmark Comparison'
runs-on: ubuntu-latest
# Runs only for pull requests with the `run-bench` label, or by hand from
# the Actions tab.
if: >-
github.event_name == 'workflow_dispatch' ||
contains(github.event.pull_request.labels.*.name, 'run-bench')
permissions:
pull-requests: write
contents: read
steps:
- uses: actions/checkout@v4
id: checkout
with:
# Full history so the script can git-archive the base branch.
fetch-depth: 0
# The PR head SHA resolves for fork PRs too.
ref: ${{ github.event.pull_request.head.sha }}
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: '24'
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm build
- name: Run benchmark comparison
env:
BENCH_JSON_OUTPUT: ${{ runner.temp }}/bench-results.json
run: |
set -o pipefail
pnpm bench:compare --base ${{ github.event.pull_request.base.ref || 'main' }} | sed 's/\x1b\[[0-9;]*m//g' > "$RUNNER_TEMP/bench-output.txt"
- name: Format PR comment
if: always() && steps.checkout.outcome == 'success'
env:
BENCH_OUTPUT_FILE: ${{ runner.temp }}/bench-output.txt
BENCH_JSON_OUTPUT: ${{ runner.temp }}/bench-results.json
BENCH_JOB_SUCCESS: ${{ job.status == 'success' }}
run: node scripts/format-bench-comment.mjs > "$RUNNER_TEMP/bench-comment.md"
- name: Write job summary
if: always() && steps.checkout.outcome == 'success'
run: cat "$RUNNER_TEMP/bench-comment.md" >> "$GITHUB_STEP_SUMMARY"
- name: Post PR comment
if: always() && steps.checkout.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const marker = '<!-- bench-compare -->';
const body = fs.readFileSync(process.env.RUNNER_TEMP + '/bench-comment.md', 'utf8');
const headFullName = context.payload.pull_request?.head?.repo?.full_name;
const isFork = !headFullName || headFullName !== context.repo.owner + '/' + context.repo.repo;
if (isFork) {
core.info('PR is from a fork — results are in the job summary only.');
return;
}
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
per_page: 100,
});
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,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}