-
Notifications
You must be signed in to change notification settings - Fork 535
124 lines (121 loc) · 4.46 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
name: Benchmark
on:
issue_comment:
types: [created]
permissions:
pull-requests: write
contents: write
jobs:
benchmark:
name: Benchmark
if: ${{ github.event.issue.pull_request && contains(fromJson('["MEMBER", "OWNER"]'), github.event.comment.author_association) && startsWith(github.event.comment.body, '/bench ') }}
runs-on: [self-hosted, linux]
steps:
- uses: actions/github-script@v6
name: Get PR branch
id: issue
with:
script: |
const pr = context.payload.issue.number
const data = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr
})
return {
ref: data.data.head.ref,
sha: data.data.head.sha,
}
- uses: actions/checkout@v4
with:
submodules: recursive
ref: ${{ fromJson(steps.issue.outputs.result).sha }}
- uses: actions/github-script@v6
name: Prepare command
id: command
with:
result-encoding: string
script: |
const [, , cmd, ...args] = context.payload.comment.body.split(/\W+/)
switch (cmd) {
case 'runtime': {
const [runtime, pallet] = args
if (!['acala', 'karura', 'mandala'].includes(runtime)) throw new Error('Invalid runtime')
return `make benchmark-${runtime} options="--quiet --color=never" pallet=${pallet ?? "*"}`
}
case 'module':
const [pallet] = args
// pallet folder should be just the name of the pallet, without the leading
// "pallet_" or "frame_", then separated with "-"
const palletFolder = pallet.split('_').slice(1).join('-').trim()
return `make benchmark-module options="--quiet --color=never" pallet=${pallet} pallet_folder=${palletFolder}`
case 'evm':
return 'make bench-evm'
default:
throw new Error('Invalid command')
}
- uses: actions/github-script@v6
name: Post comment
id: comment
with:
script: |
const data = await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `
**Request**: \`${context.payload.comment.body}\`
**Command**: \`${{steps.command.outputs.result}}\`
Running...
`
})
return data.data.id
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly
- name: Install weight-gen
run: cargo install --git https://github.com/open-web3-stack/wasm-bencher.git --bin weight-gen --force
- name: Setup cmake
uses: jwlawson/[email protected]
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
- name: Run benchmarks
run: ${{steps.command.outputs.result}} > ${{runner.temp}}/out.txt
- name: Commit
run: |
git config user.email "[email protected]"
git config user.name "Acala Github Action Bot"
git add .
git commit -m '${{github.event.comment.body}}' --allow-empty
git push origin HEAD:${{ fromJson(steps.issue.outputs.result).ref }}
- uses: actions/github-script@v6
name: Update comment
with:
script: |
const fs = require('fs')
const id = `${{steps.comment.outputs.result}}`
const body = fs.readFileSync('${{runner.temp}}/out.txt').toString()
github.rest.issues.updateComment({
comment_id: id,
owner: context.repo.owner,
repo: context.repo.repo,
body: `
**Request**: \`${context.payload.comment.body}\`
**Command**: \`${{steps.command.outputs.result}}\`
<details>
<summary>Results</summary>
\`\`\`
${body.trim()}
\`\`\`
</details>
`
})