-
Notifications
You must be signed in to change notification settings - Fork 41
201 lines (165 loc) · 7.43 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Benchmark weights
on:
workflow_dispatch:
pull_request:
types: [ labeled ]
env:
CARGO_TERM_COLOR: always
jobs:
benchmark:
name: Benchmark weights
if: (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 's:benchmark-required')) || github.event_name == 'workflow_dispatch'
runs-on: [self-hosted, runtime-benchmark]
defaults:
run:
shell: bash
steps:
# Ensure that at most one benchmark worklow runs across all workflows
- name: Turnstyle
uses: softprops/turnstyle@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout repository (PR)
uses: actions/checkout@v2
if: (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 's:benchmark-required'))
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout repository (branch)
uses: actions/checkout@v2
if: github.event_name == 'workflow_dispatch'
- name: Install build tools
run: ./scripts/init.sh
- name: Cache dependencies
uses: Swatinem/rust-cache@v1
- name: Test runtime-benchmarks
run: cargo test --release --features runtime-benchmarks
- name: Build Zeitgeist chain with runtime-benchmarks feature
run: cargo build --release --features runtime-benchmarks --bin zeitgeist
- name: Run benchmarks
id: run_benchmarks
run: |
# define benchmark commands
source ./scripts/benchmarks/configuration.sh
echo "Fetching commit hash of HEAD"
zg_cmt=`git log -n 1 --format="%H"`
echo "Commit hash: ${zg_cmt}"
# Takes variable name as parameter $1
prepare_output() {
# Add result box that contains contents of parameter $1
local txt_proc="<details>
<summary>
Results
</summary>
${!1}
</details>"
# Prepare output for github output format
txt_proc="${txt_proc//'%'/'%25'}"
txt_proc="${txt_proc//$'\n'/'%0A'}"
txt_proc="${txt_proc//$'\r'/'%0D'}"
eval "$1=\"${txt_proc//\"/\'}\""
}
check_if_new_commits() {
echo "Fetching latest repository state"
git fetch
if [ $? -ne 0 ]; then
ERROR="ERROR: git fetch failed. Aborting benchmarks."
prepare_output ERROR
echo "::set-output name=ERROR::$ERROR"
exit 0
fi
echo "Determining if the branch contains new updates."
if [ ${{ github.event_name }} == 'pull_request' ]; then
local zg_cur_cmt=`git log -n 1 --format="%H" origin/${{ github.event.pull_request.head.ref }}`
else
local zg_cur_cmt=`git log -n 1 --format="%H" origin/${GITHUB_REF##*/}`
fi
if [ "$zg_cmt" != "$zg_cur_cmt" ]; then
echo "${zg_cmt} != ${zg_cur_cmt}"
ERROR="ERROR: Branch contains new commits. Aborting benchmarks."
prepare_output ERROR
echo "::set-output name=ERROR::$ERROR"
exit 0
fi
}
check_if_new_commits
# Execute benchmark. Note: It's not possible to use a matrix here in
# combination with GitHub AE hosted runner (one instance per job)
for pallet in "${ZEITGEIST_PALLETS[@]}"; do
# Execute benchmark
pallet_folder_name=${pallet//zrml_/}
pallet_folder_name=${pallet_folder_name//_/-}
command="./target/release/zeitgeist benchmark --chain=dev "
command+="--steps=$ZEITGEIST_PALLETS_STEPS --repeat=$ZEITGEIST_PALLETS_RUNS "
command+="--pallet=$pallet --extrinsic=* --execution=wasm --wasm-execution=compiled "
command+="--heap-pages=4096 --template=./misc/weight_template.hbs "
command+="--output=./zrml/$pallet_folder_name/src/weights.rs"
echo "Executing: $command"
# use temporary log to display contents in github workflow
$command > _temp.log 2> benchmark_errors.txt
if [ $? -ne 0 ]; then
# Prepare error for github output format
cat _temp.log
ERROR=$(<benchmark_errors.txt)
prepare_output ERROR
echo "::set-output name=ERROR::$ERROR"
exit 0
fi
cat _temp.log | tee --append benchmark_log.txt
check_if_new_commits
done
BENCHMARK_LOG=$(sed -E "s/(Writes\s=\s[0-9]+)/\1\n/g" benchmark_log.txt | sed "s/========/--------/g")
prepare_output BENCHMARK_LOG
echo "::set-output name=RESULT::$BENCHMARK_LOG"
- name: Format code
if: steps.run_benchmarks.outputs.ERROR == ''
run: cargo fmt
- name: Commit updated weights
uses: stefanzweifel/git-auto-commit-action@v4
if: steps.run_benchmarks.outputs.ERROR == ''
with:
commit_message: Update weights
commit_options: '--no-verify'
file_pattern: zrml/*/src/weights.rs
commit_user_name: Zeitgeist Benchmark Bot
commit_user_email: [email protected]
status_options: '--untracked-files=no'
- name: Remove label s:benchmark-required
if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 's:benchmark-required')
uses: buildsville/add-remove-label@v1
with:
token: ${{secrets.GITHUB_TOKEN}}
label: s:benchmark-required
type: remove
- name: Add label s:benchmark-done
if: (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 's:benchmark-required')) && steps.run_benchmarks.outputs.ERROR == ''
uses: buildsville/add-remove-label@v1
with:
token: ${{secrets.GITHUB_TOKEN}}
label: s:benchmark-done
type: add
- name: Add label s:benchmark-aborted
if: (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 's:benchmark-required')) && steps.run_benchmarks.outputs.ERROR != ''
uses: buildsville/add-remove-label@v1
with:
token: ${{secrets.GITHUB_TOKEN}}
label: s:benchmark-aborted
type: add
- name: Comment PR (on success)
uses: thollander/[email protected]
if: (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 's:benchmark-required')) && steps.run_benchmarks.outputs.ERROR == ''
with:
message: 'Benchmark completed successfully.
${{ steps.run_benchmarks.outputs.RESULT }}'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Comment PR (on failure)
uses: thollander/[email protected]
if: (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 's:benchmark-required')) && steps.run_benchmarks.outputs.ERROR != ''
with:
message: 'Benchmark aborted due to an error.
${{ steps.run_benchmarks.outputs.ERROR }}'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Exit with error message
if: steps.run_benchmarks.outputs.ERROR != ''
run: |
echo "${{ steps.run_benchmarks.outputs.ERROR }}"
exit 1