Skip to content

Commit 9c0cb9d

Browse files
authored
v3: Refactor Benchmark Results Workflow (#3082)
* Refactor benchmarks workflow * Use full semver tag * Add fetch depth
1 parent 0de6a2f commit 9c0cb9d

File tree

1 file changed

+69
-10
lines changed

1 file changed

+69
-10
lines changed

.github/workflows/benchmark.yml

+69-10
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,21 @@ on:
99
paths-ignore:
1010
- "**/*.md"
1111

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+
1218
name: Benchmark
1319
jobs:
1420
Compare:
1521
runs-on: ubuntu-latest
1622
steps:
1723
- name: Fetch Repository
1824
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0 # to be able to retrieve the last commit in main
1927

2028
- name: Install Go
2129
uses: actions/setup-go@v5
@@ -26,24 +34,75 @@ jobs:
2634
- name: Run Benchmark
2735
run: set -o pipefail; go test ./... -benchmem -run=^$ -bench . | tee output.txt
2836

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
3151
with:
3252
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%"
3470

35-
- name: Save Benchmark Results
71+
- name: Store Benchmark Results for main branch
3672
uses: benchmark-action/[email protected]
73+
if: ${{ github.ref_name == 'main' }}
3774
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'
3990
output-file-path: output.txt
40-
github-token: ${{ secrets.BENCHMARK_TOKEN }}
4191
benchmark-data-dir-path: "benchmarks"
4292
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%"
4699
# TODO: reactivate it later -> when v3 is the stable one
47100
#auto-push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
48101
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

Comments
 (0)