-
Notifications
You must be signed in to change notification settings - Fork 14
87 lines (75 loc) · 3.25 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
78
79
80
81
82
83
84
85
86
87
name: Benchmarks
on:
pull_request_target:
branches:
- master
concurrency:
group: ${{ format('{0}-{1}', github.workflow_ref, github.head_ref) }}
cancel-in-progress: true
jobs:
benchmarks:
if: ${{ github.repository == 'Breus/json-masker' }}
permissions:
contents: read
pull-requests: write # for benchmark comment
runs-on: ubuntu-latest
env:
COMMENT_FILE: ${{ github.workspace }}/benchmark-comment.md
steps:
- id: get-master-sha
run: |
# getting exact master sha at the moment to reference it in the comment
echo "sha=$( curl -u "u:${{ github.token }}" https://api.github.com/repos/${{ github.repository }}/git/ref/heads/${{ github.base_ref }} | jq .object.sha | tr -d '"' )" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
ref: ${{ steps.get-master-sha.outputs.sha }}
path: benchmark-master
- uses: actions/checkout@v4
with:
# https://github.com/actions/checkout/issues/518#issuecomment-890401887
# When the up-to-date branch check is enabled, for some reason
# the GitHub resolves "${{ github.event.pull_request.merge_commit_sha }}"
# to the master commit, which is wrong
# Also for the force-pushes it sometimes references the older commit, but in the branch ¯\_(ツ)_/¯
ref: "${{ github.event.pull_request.head.sha }}"
path: benchmark-pull-request
- name: Setup JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Run benchmarks (pull-request)
working-directory: benchmark-pull-request
run: ./gradlew jmh -PjmhShort
- name: Run benchmarks (master)
working-directory: benchmark-master
run: ./gradlew jmh -PjmhShort
- name: Compose comment content
run: |
cat <<EOF >> ${{ env.COMMENT_FILE }}
> [!NOTE]
> These results are affected by shared workloads on GitHub runners. Use the results only to detect possible regressions, but always rerun on more stable machine before making any conclusions!
### Benchmark results (pull-request, ${{ github.event.pull_request.head.sha }})
\`\`\`text
$(grep -vE ':gc.(alloc.rate|count|time)\s' benchmark-pull-request/build/results/jmh/results.txt)
\`\`\`
### Benchmark results (${{ github.base_ref }}, ${{ steps.get-master-sha.outputs.sha }})
\`\`\`text
$(grep -vE ':gc.(alloc.rate|count|time)\s' benchmark-master/build/results/jmh/results.txt)
\`\`\`
EOF
- name: Find benchmark results comment
uses: peter-evans/find-comment@v3
id: benchmark-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Benchmark results
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.benchmark-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-path: ${{ env.COMMENT_FILE }}
edit-mode: replace