Skip to content

Run benchmarks in the correct context and compare main vs PR #6

Run benchmarks in the correct context and compare main vs PR

Run benchmarks in the correct context and compare main vs PR #6

Workflow file for this run

name: Benchmarks
on:
pull_request:
branches:
- main
permissions:
issues: write
jobs:
benchmark:
name: Run benchmarks
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v2
with:
ref: main
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run benchmarks on main - solvers
run: cargo bench -- solvers --exact | tail -n +6 > results_main.txt
- name: Checkout PR branch
uses: actions/checkout@v2
- name: Run benchmarks on PR branch
run: cargo bench -- solvers --exact | tail -n +6 > results_pr.txt
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Benchmark Results - Solvers
- name: Create or update comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const issue_number = context.issue.number;
const comment_id = '${{ steps.fc.outputs.comment-id }}';
let results_main = 'Benchmarks did not run successfully on main.';
let results_pr = 'Benchmarks did not run successfully on PR.';
if (fs.existsSync('results_main.txt')) {
results_main = fs.readFileSync('results_main.txt', 'utf8');
}
if (fs.existsSync('results_pr.txt')) {
results_pr = fs.readFileSync('results_pr.txt', 'utf8');
}
const body = `Benchmark Results - Solvers\n\n<details><summary>Main</summary>\n\n\`\`\`\n${results_main}\n\`\`\`\n</details>\n<details><summary>PR</summary>\n\n\`\`\`\n${results_pr}\n\`\`\`\n</details>`;
if (comment_id) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment_id,
body: body,
});
} else {
github.rest.issues.createComment({
issue_number: issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body,
});
}