-
Notifications
You must be signed in to change notification settings - Fork 170
77 lines (66 loc) · 2.31 KB
/
benchmark.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Benchmark
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip bm]')"
name: Benchmark
steps:
# Setup the main branch to run benchmarks there as a baseline for comparison
- name: Checkout to main
uses: actions/checkout@v3
with:
ref: main
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
bundler-cache: true
- name: Main benchmark
id: main-benchmark
run: |
bin/benchmark
# Setup the PR's branch to run benchmarks and compare with main results
- name: Checkout to branch
uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
bundler-cache: true
- name: Branch benchmark
id: benchmark
run: |
result=$(bin/benchmark) || true
echo "REPORT=$(echo "$result" | tr '\n' '#')" >> $GITHUB_OUTPUT
# Post the results as a comment on the PR
- name: Comment report
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
const BODY_COMMENT = '```#${{ steps.benchmark.outputs.REPORT }}#```'.split("#").join("\n")
const { data: issueComments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
commentToUpdate = issueComments.find((comment) =>
comment.body.includes("Benchmark results in seconds (slowest at top)")
);
if (commentToUpdate) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: commentToUpdate.id,
body: BODY_COMMENT,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: BODY_COMMENT,
});
}