-
Notifications
You must be signed in to change notification settings - Fork 73
133 lines (127 loc) · 4.3 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
name: Benchmark
on:
workflow_dispatch:
inputs:
pallet:
description: provided a list of pallet to run benchmark on
default: 'automation_time,automation_price,vesting,valve'
required: true
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
gen-params:
runs-on: ubuntu-latest
outputs:
pallet: ${{ steps.set-matrix.outputs.pallet }}
steps:
- id: set-matrix
run: |
# Matrix only take a list so we use fromJSON to convert raw json string data to list
# The input is from Github action input, which doesn't support list so we take raw string separate by ','
# Convert the string a,b,c -> a json array ["a", "b", "c"] with bracket and double quote properly
echo "pallet=$(echo -n ${{ inputs.pallet }} | jq --raw-input --slurp 'split(",")' -c)" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
build-binary:
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.tag }}
- name: Setup Rust
run: rustup show
- name: Build
run: |
cargo build --release --features runtime-benchmarks,turing-node,oak-node
mkdir -p artifacts/
cp target/release/oak-collator artifacts/
- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: oak-collator
path: artifacts/
retention-days: 1
run-benchmarks:
name: Run Benchmarks
runs-on: self-hosted
needs: [gen-params, build-binary]
strategy:
matrix:
pallet: ${{ fromJSON(needs.gen-params.outputs.pallet) }}
steps:
- name: Download binary
uses: actions/download-artifact@v2
with:
name: oak-collator
- name: Execute pallet benchmark
run: |
chmod +x oak-collator
./oak-collator \
benchmark \
pallet \
--header ./.maintain/HEADER-GPL3 \
--chain turing-dev \
--execution wasm \
--wasm-execution compiled \
--pallet pallet_${{ matrix.pallet }} \
--extrinsic '*' \
--repeat 20 \
--steps 50 \
--output ./${{ matrix.pallet }}-raw-weights.rs \
--template ./.maintain/frame-weight-template.hbs
- name: Upload raw weights
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.pallet }}
path: ${{ matrix.pallet }}-raw-weights.rs
generate-pull-request:
name: Generate pull request
needs: run-benchmarks
runs-on: ubuntu-latest
steps:
- name: Delete binary artifact
uses: geekyeggo/delete-artifact@v1
with:
name: oak-collator
- name: Checkout
uses: actions/checkout@v2
- name: Download benchmark files
uses: actions/download-artifact@v3
with:
path: weight-artifacts
- name: Generate PR body
id: body
run: |
echo > body.md
for file in $(find ./weight-artifacts -type f); do
pallet=$(basename $file | cut -d '-' -f 1 | tr '_' '-')
echo "## $pallet" >> body.md
echo "\`\`\`" >> body.md
join -o auto -e "-" -a 1 -a 2 \
<(echo "$(grep '//:' pallets/$pallet/src/weights.rs | cut -c 4- | sort)") \
<(echo "$(grep '//:' $file | cut -c 4- | sort)") \
| column -t >> body.md
echo "\`\`\`" >> body.md
done
body=$(cat body.md)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "::set-output name=md::$body"
- name: Move benchmark files to correct place
run: |
for file in $(find ./weight-artifacts -type f); do
pallet=$(basename $file | cut -d '-' -f 1 | tr '_' '-')
mv $file pallets/$pallet/src/weights.rs
done
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
title: Update pallet weights
draft: true
base: master
branch: update-weights
branch-suffix: short-commit-hash
body: ${{ steps.body.outputs.md }}
add-paths: pallets/**/weights.rs