-
Notifications
You must be signed in to change notification settings - Fork 15
276 lines (232 loc) · 9.55 KB
/
bench.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
---
name: BENCHMARK
# Controls when the action will run.
on:
pull_request:
branches: [testnet]
env:
RUNNER_VM_NAME: "github-runner-$GITHUB_RUN_ID-attempt-$GITHUB_RUN_ATTEMPT"
RESOURCE_GROUP: "github-runner-$GITHUB_RUN_ID-attempt-$GITHUB_RUN_ATTEMPT"
AZ_LOCATION: "westus3"
jobs:
check-if-needed:
# To avoid endless loop in CI skip this job on the commit which
# auto-updates the weights and is generated further below.
if: ${{ github.event_name == 'pull_request' && github.triggering_actor != 'notaturkey' }}
runs-on: ubuntu-22.04
outputs:
needs-bench: ${{ steps.version-check.outputs.needs_bench }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check versions
id: version-check
run: |
./scripts/check-spec-increase.sh "remotes/origin/$GITHUB_BASE_REF" "HEAD"
build-benchmarks:
runs-on: ubuntu-22.04
needs: check-if-needed
if: needs.check-if-needed.outputs.needs-bench == 1
steps:
- uses: actions/checkout@v3
- name: Inspect benchmark CI config
run: |
# WARNING: Command below may differ depending on which workflow config file
# your job is defined in !!! Don't copy&paste it blindly !!!
PALLETS_IN_CI_CONFIG=$(grep "PALLET:" .github/workflows/bench.yml | grep -v PALLETS_IN_CI_CONFIG | tr -d ' ' | cut -f2 -d: | sort | xargs)
PALLETS_IN_SOURCE=$(./scripts/check-parity-bw-extrinsics-benchmarks-weights.sh --show-pallets)
if [ "$PALLETS_IN_CI_CONFIG" != "$PALLETS_IN_SOURCE" ]; then
echo "FAIL: Pallet mismatch between source code and benchmark CI config"
echo "INFO: in source: '$PALLETS_IN_SOURCE'"
echo "INFO: CI config: '$PALLETS_IN_CI_CONFIG'"
exit 1
fi
- name: Set-Up
run: |
sudo apt-get update
sudo apt install -y cmake pkg-config libssl-dev git build-essential clang libclang-dev curl protobuf-compiler
- name: Configure rustc version
run: |
source ci/env
echo "RUSTC_VERSION=$RUSTC_VERSION" >> "$GITHUB_ENV"
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUSTC_VERSION }}
target: wasm32-unknown-unknown
profile: minimal
override: true
- uses: Swatinem/rust-cache@v2
- name: Build benchmarks
uses: actions-rs/cargo@v1
with:
command: build
args: --release --features runtime-benchmarks
- name: Upload benchmark binary
uses: actions/upload-artifact@v3
with:
name: creditcoin-node
path: target/release/creditcoin-node
deploy-github-runner:
runs-on: ubuntu-22.04
needs: build-benchmarks
outputs:
runner_vm_name: ${{ steps.get-env.outputs.runner_vm_name }}
resource_group: ${{ steps.get-env.outputs.resource_group }}
steps:
- uses: actions/checkout@v3
- name: Install azure-cli
run: |
sudo apt remove azure-cli -y && sudo apt autoremove -y
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
sudo apt install -y jq
az version
- name: Authorize hosted-runner
run: |
mkdir -p ~/.ssh/
ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> .github/authorized_keys
- name: Evaluate env vars
id: get-env
run: |
# WARNING: using env.RUNNER_VM_NAME directly in job outputs above
# doesn't evaluate the $GITHUB_RUN_ID reference
echo "runner_vm_name=${{ env.RUNNER_VM_NAME }}" >> "$GITHUB_OUTPUT"
echo "resource_group=${{ env.RESOURCE_GROUP }}" >> "$GITHUB_OUTPUT"
- name: Provision VM
if: env.LC_GITHUB_REPO_ADMIN_TOKEN
run: |
echo "INFO: From ENVs: RUNNER_VM_NAME=${{ env.RUNNER_VM_NAME }}"
echo "INFO: From Step: RUNNER_VM_NAME=${{ steps.get-env.outputs.runner_vm_name }}"
az login --service-principal --username "${{ secrets.AZURE_APP_ID }}" --password "${{ secrets.AZURE_APP_PASSWORD }}" --tenant "${{ secrets.AZURE_TENANT_ID }}"
az account set --subscription "Playground Subscription"
## az account set -s "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
# create resource group
echo "INFO: ${{ steps.get-env.outputs.resource_group }}"
az group create -n "${{ steps.get-env.outputs.resource_group }}" --location "${{ env.AZ_LOCATION }}"
# RG Creditcoin-Test is in WestUS and the CPU quota is already full
# that's why specify a different region here
az deployment group create -g "${{ steps.get-env.outputs.resource_group }}" -f .github/runner.bicep \
--parameters location="${{ env.AZ_LOCATION }}" \
--parameters vmName="${{ steps.get-env.outputs.runner_vm_name }}" \
--parameters adminPasswordOrKey="$(cat .github/authorized_keys)" > output.json
# provision the GitHub Runner binary on the VM
# passing additional ENV values
SSH_USER_AT_HOSTNAME=$(jq -r '.properties.outputs.sshUserAtHostname.value' < output.json)
echo "INFO: $SSH_USER_AT_HOSTNAME"
export LC_RUNNER_VM_NAME="${{ env.RUNNER_VM_NAME }}"
ssh -i ~/.ssh/id_rsa \
-o SendEnv=LC_GITHUB_REPO_ADMIN_TOKEN,LC_RUNNER_VM_NAME \
-o StrictHostKeyChecking=no "$SSH_USER_AT_HOSTNAME" < ./scripts/provision-github-runner.sh
env:
LC_GITHUB_REPO_ADMIN_TOKEN: ${{ secrets.GH_REPO_ADMIN_TOKEN }}
hardware-benchmarks:
# see https://gist.github.com/jonico/a94d03cac7a858e0613926d9f1bc7f2b
runs-on:
[self-hosted, "${{ needs.deploy-github-runner.outputs.runner_vm_name }}"]
# checkov:skip=CKV2_GHA_1:We need this for weights auto-update
permissions: write-all
needs:
- deploy-github-runner
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 10
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.CREDITCOIN_GITHUB_API_TOKEN }}
- name: Set env
run: |
echo "HOME=/home/actions" >> "$GITHUB_ENV"
- name: Download benchmark binary
uses: actions/download-artifact@v3
with:
name: creditcoin-node
path: target/release
- name: Restore executable permissions
run: |
chmod a+x ./target/release/creditcoin-node
- name: Check if runner machine meets chain's requirements
continue-on-error: true
run: |
./scripts/check-hardware.sh
# Run creditcoin pallet with lesser steps
- name: Creditcoin
shell: bash
continue-on-error: false
env:
STEPS: 8
REPEAT: 8
PALLET: creditcoin
run: |
./scripts/bench.sh -p "$PALLET" -b -r "$REPEAT" -s "$STEPS"
- name: Offchain Task Scheduler
shell: bash
continue-on-error: false
env:
PALLET: offchain_task_scheduler
run: |
./scripts/bench.sh -p "$PALLET" -b
- name: Rewards
shell: bash
continue-on-error: false
env:
PALLET: rewards
run: |
./scripts/bench.sh -p "$PALLET" -b
- name: Commit changes to current branch
uses: EndBug/add-and-commit@v9
with:
author_name: gluwa-bot
author_email: creditcoin@gluwa.com
message: "Auto-update pallet weights"
- name: Prepare commit for PR against dev
run: |
LAST_COMMIT=$(git rev-parse HEAD)
BRANCH_NAME=auto-update-weights-for-dev-${{ github.sha }}
git checkout -b "$BRANCH_NAME" origin/dev
git cherry-pick "$LAST_COMMIT"
git push origin "$BRANCH_NAME"
- name: Open PR against dev
id: open_pr
uses: rematocorp/open-pull-request-action@v1
with:
github-token: ${{ secrets.CREDITCOIN_GITHUB_API_TOKEN }}
from-branch: auto-update-weights-for-dev-${{ github.sha }}
to-branch: dev
repository-owner: gluwa
repository: creditcoin
- name: PR number against dev
run: echo ${{ steps.open_pr.outputs.pull_number }}
remove-github-runner:
runs-on: ubuntu-22.04
needs:
- deploy-github-runner
- hardware-benchmarks
if: ${{ always() && needs.deploy-github-runner.result != 'skipped' }}
steps:
- uses: actions/checkout@v3
- name: Evaluate env vars
id: get-env
run: |
# WARNING: using env.RUNNER_VM_NAME directly in job outputs above
# doesn't evaluate the $GITHUB_RUN_ID reference
echo "resource_group=${{ env.RESOURCE_GROUP }}" >> "$GITHUB_OUTPUT"
- name: Install azure-cli
run: |
sudo apt remove azure-cli -y && sudo apt autoremove -y
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
az version
- name: Remove VM
run: |
echo "INFO: RUNNER_VM_NAME=${{ env.RUNNER_VM_NAME }}"
az login --service-principal --username "${{ secrets.AZURE_APP_ID }}" --password "${{ secrets.AZURE_APP_PASSWORD }}" --tenant "${{ secrets.AZURE_TENANT_ID }}"
az account set --subscription "Playground Subscription"
az group delete --yes -n "${{ steps.get-env.outputs.resource_group }}"
- name: Upload logs
uses: actions/upload-artifact@v3
if: always()
with:
name: "Azure resources"
path: azure_resource_list.json