-
Notifications
You must be signed in to change notification settings - Fork 59
141 lines (128 loc) · 4.51 KB
/
benchmark.yml
File metadata and controls
141 lines (128 loc) · 4.51 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Benchmark
on:
workflow_dispatch:
push:
branches:
- "master"
- "main"
paths:
- "**/*.go"
- "**/go.mod"
- ".github/workflows/benchmark.yml"
pull_request:
paths:
- "**/*.go"
- "**/go.mod"
- ".github/workflows/benchmark.yml"
permissions:
deployments: write
contents: write
pull-requests: write
jobs:
compare:
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v6
with:
# NOTE: Keep this in sync with the version from go.mod
go-version: "1.25.x"
cache: false
- name: Run Benchmarks
shell: bash
run: |
set -euo pipefail
: > output.txt
for d in */ ; do
if [[ ! -f "${d}go.mod" ]]; then
continue
fi
(
cd "$d"
go test ./... -benchmem -run=^$ -bench .
) | tee -a output.txt
done
- name: Get GitHub Runner System Information
uses: kenchan0130/actions-system-info@v1.4.0
id: system-info
- name: Get Default branch SHA
id: get-default-branch-sha
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
shell: bash
run: |
set -euo pipefail
SHA="$(git ls-remote origin "${DEFAULT_BRANCH}" | awk 'NR==1 {print $1}')"
if [[ -z "${SHA}" ]]; then
echo "Failed to resolve SHA for default branch '${DEFAULT_BRANCH}'" >&2
exit 1
fi
echo "sha=${SHA}" >> "$GITHUB_OUTPUT"
- name: Build normalized cache key
id: cache-key
env:
CPU_MODEL: ${{ steps.system-info.outputs.cpu-model }}
BASE_SHA: ${{ steps.get-default-branch-sha.outputs.sha }}
shell: bash
run: |
set -euo pipefail
SAFE_CPU_MODEL="$(printf '%s' "$CPU_MODEL" | tr -cs '[:alnum:]._-' '-')"
SAFE_CPU_MODEL="${SAFE_CPU_MODEL#-}"
SAFE_CPU_MODEL="${SAFE_CPU_MODEL%-}"
echo "key=${BASE_SHA}-${{ runner.os }}-${SAFE_CPU_MODEL}-benchmark" >> "$GITHUB_OUTPUT"
- name: Get Benchmark Results from default branch
id: cache
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ./cache
key: ${{ steps.cache-key.outputs.key }}
- name: Compare PR Benchmark Results with default branch
if: ${{ github.event_name == 'pull_request' && steps.cache.outputs.cache-hit == 'true' }}
uses: benchmark-action/github-action-benchmark@v1.20.7
with:
tool: "go"
output-file-path: output.txt
external-data-json-path: ./cache/benchmark-data.json
save-data-file: false
fail-on-alert: true
comment-on-alert: ${{ github.event.pull_request.head.repo.fork == false }}
github-token: ${{ secrets.GITHUB_TOKEN }}
summary-always: true
alert-threshold: "150%"
- name: Store Benchmark Results for default branch
if: ${{ github.ref_name == github.event.repository.default_branch }}
uses: benchmark-action/github-action-benchmark@v1.20.7
with:
tool: "go"
output-file-path: output.txt
external-data-json-path: ./cache/benchmark-data.json
save-data-file: true
fail-on-alert: false
github-token: ${{ secrets.GITHUB_TOKEN }}
summary-always: true
alert-threshold: "150%"
auto-push: false
- name: Publish Benchmark Results to GitHub Pages
if: ${{ github.ref_name == github.event.repository.default_branch }}
uses: benchmark-action/github-action-benchmark@v1.20.7
with:
tool: "go"
output-file-path: output.txt
benchmark-data-dir-path: "benchmarks"
fail-on-alert: false
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-on-alert: false
summary-always: true
save-data-file: true
alert-threshold: "150%"
auto-push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
- name: Update Benchmark Results cache
if: ${{ github.ref_name == github.event.repository.default_branch }}
uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ./cache
key: ${{ steps.cache-key.outputs.key }}