Skip to content

Commit

Permalink
Run github actions in the correct context and compare main vs PR
Browse files Browse the repository at this point in the history
  • Loading branch information
dwmunster committed Jun 4, 2024
1 parent 3429907 commit dd8e457
Showing 1 changed file with 56 additions and 6 deletions.
62 changes: 56 additions & 6 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,70 @@
name: Benchmarks
on:
pull_request_target:
pull_request:
branches:
- main

permissions:
issues: write

jobs:
benchmark:
name: Run benchmarks
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Checkout main branch
uses: actions/checkout@v2
with:
ref: main
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: echo \`\`\` > results.txt && cargo bench -- solvers --exact | tail -n +6 >> results.txt && echo \`\`\` >> results.txt
- uses: thollander/actions-comment-pull-request@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:
filepath: results.txt
comment_tag: "Benchmark Results"
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,
});
}

0 comments on commit dd8e457

Please sign in to comment.