9
9
paths-ignore :
10
10
- " **/*.md"
11
11
12
+ permissions :
13
+ # deployments permission to deploy GitHub pages website
14
+ deployments : write
15
+ # contents permission to update benchmark contents in gh-pages branch
16
+ contents : write
17
+
12
18
name : Benchmark
13
19
jobs :
14
20
Compare :
15
21
runs-on : ubuntu-latest
16
22
steps :
17
23
- name : Fetch Repository
18
24
uses : actions/checkout@v4
25
+ with :
26
+ fetch-depth : 0 # to be able to retrieve the last commit in main
19
27
20
28
- name : Install Go
21
29
uses : actions/setup-go@v5
@@ -26,24 +34,75 @@ jobs:
26
34
- name : Run Benchmark
27
35
run : set -o pipefail; go test ./... -benchmem -run=^$ -bench . | tee output.txt
28
36
29
- - name : Get Previous Benchmark Results
30
- uses : actions/cache@v4
37
+ # NOTE: Benchmarks could change with different CPU types
38
+ - name : Get GitHub Runner System Information
39
+ uses :
kenchan0130/[email protected]
40
+ id : system-info
41
+
42
+ - name : Get Main branch SHA
43
+ id : get-main-branch-sha
44
+ run : |
45
+ SHA=$(git rev-parse origin/main)
46
+ echo "sha=$SHA" >> $GITHUB_OUTPUT
47
+
48
+ - name : Get Benchmark Results from main branch
49
+ id : cache
50
+ uses : actions/cache/restore@v4
31
51
with :
32
52
path : ./cache
33
- key : ${{ runner.os }}-benchmark
53
+ key : ${{ steps.get-main-branch-sha.outputs.sha }}-${{ runner.os }}-${{ steps.system-info.outputs.cpu-model }}-benchmark
54
+
55
+ # This will only run if we have Benchmark Results from main branch
56
+ - name : Compare PR Benchmark Results with main branch
57
+ uses :
benchmark-action/[email protected]
58
+ if : steps.cache.outputs.cache-hit == 'true'
59
+ with :
60
+ tool : ' go'
61
+ output-file-path : output.txt
62
+ external-data-json-path : ./cache/benchmark-data.json
63
+ # Do not save the data (This allows comparing benchmarks)
64
+ save-data-file : false
65
+ fail-on-alert : true
66
+ comment-on-alert : true
67
+ github-token : ${{ secrets.GITHUB_TOKEN }}
68
+ summary-always : true
69
+ alert-threshold : " 150%"
34
70
35
- - name : Save Benchmark Results
71
+ - name : Store Benchmark Results for main branch
36
72
uses :
benchmark-action/[email protected]
73
+ if : ${{ github.ref_name == 'main' }}
37
74
with :
38
- tool : " go"
75
+ tool : ' go'
76
+ output-file-path : output.txt
77
+ external-data-json-path : ./cache/benchmark-data.json
78
+ # Save the data to external file (cache)
79
+ save-data-file : true
80
+ fail-on-alert : true
81
+ github-token : ${{ secrets.GITHUB_TOKEN }}
82
+ summary-always : true
83
+ alert-threshold : " 150%"
84
+
85
+ - name : Publish Benchmark Results to GitHub Pages
86
+ uses :
benchmark-action/[email protected]
87
+ if : ${{ github.ref_name == 'main' }}
88
+ with :
89
+ tool : ' go'
39
90
output-file-path : output.txt
40
- github-token : ${{ secrets.BENCHMARK_TOKEN }}
41
91
benchmark-data-dir-path : " benchmarks"
42
92
fail-on-alert : true
43
- comment-on-alert : ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
44
- # Enable Job Summary for PRs - deactivated because of issues
45
- # summary-always: ${{ github.event_name != 'push' && github.event_name != 'workflow_dispatch' }}
93
+ github-token : ${{ secrets.GITHUB_TOKEN }}
94
+ comment-on-alert : true
95
+ summary-always : true
96
+ # Save the data to external file (GitHub Pages)
97
+ save-data-file : true
98
+ alert-threshold : " 150%"
46
99
# TODO: reactivate it later -> when v3 is the stable one
47
100
# auto-push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
48
101
auto-push : false
49
- save-data-file : ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
102
+
103
+ - name : Update Benchmark Results cache
104
+ uses : actions/cache/save@v4
105
+ if : ${{ github.ref_name == 'main' }}
106
+ with :
107
+ path : ./cache
108
+ key : ${{ steps.get-main-branch-sha.outputs.sha }}-${{ runner.os }}-${{ steps.system-info.outputs.cpu-model }}-benchmark
0 commit comments