-
Notifications
You must be signed in to change notification settings - Fork 381
157 lines (140 loc) · 5.07 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
name: Benchmarks
on:
issue_comment:
types: [created]
jobs:
check-permission:
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/bench')
runs-on: ubuntu-latest
steps:
- name: Check permission
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const response = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: context.actor
});
const actorPermissionLevel = response.data.permission;
console.log(actorPermissionLevel);
// <- lower higher ->
// ["none", "read", "write", "admin"]
if (!(actorPermissionLevel == "admin" || actorPermissionLevel == "write")) {
core.setFailed("Permission denied.");
}
benchmarks:
# run only when PR comments start with '/bench'.
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/bench')
needs: check-permission
runs-on: [self-hosted, Linux, X64]
steps:
- name: Validate and set inputs
id: bench-input
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const command = `${{ github.event.comment.body }}`.split(" ");
console.log(command);
// command should be '/bench chain_name pallets'
if (command.length != 3) {
core.setFailed("Invalid input. It should be '/bench [chain_name] [pallets]'");
}
core.setOutput("chain", command[1]);
core.setOutput("pallets", command[2]);
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
df -h
- name: Get branch and sha
id: get_branch_sha
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
const pull_request = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
})
core.setOutput("branch", pull_request.data.head.ref)
core.setOutput("sha", pull_request.data.head.sha)
- name: Post starting comment
uses: actions/github-script@v6
env:
MESSAGE: |
Benchmarks job is scheduled at ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}.
Please wait for a while.
Branch: ${{ steps.get_branch_sha.outputs.branch }}
SHA: ${{ steps.get_branch_sha.outputs.sha }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.MESSAGE
})
- name: Checkout the source code
uses: actions/checkout@v3
with:
ref: ${{ steps.get_branch_sha.outputs.sha }}
submodules: true
- name: Install deps
run: sudo apt -y install protobuf-compiler
- name: Install & display rust toolchain
run: rustup show
- name: Check targets are installed correctly
run: rustup target list --installed
- name: Execute benchmarking
run: |
mkdir -p ./benchmark-results
chmod +x ./scripts/run_benchmarks.sh
./scripts/run_benchmarks.sh -o ./benchmark-results -c ${{ steps.bench-input.outputs.chain }} -p ${{ steps.bench-input.outputs.pallets }}
- uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: ./benchmark-results
- name: Post success comment
if: ${{ success() }}
uses: actions/github-script@v6
env:
MESSAGE: |
Benchmarks have been finished.
You can download artifacts if exists ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}.
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.MESSAGE
})
- name: Post failure comment
if: ${{ failure() }}
uses: actions/github-script@v6
env:
MESSAGE: |
Benchmark job failed.
Please check ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}.
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.MESSAGE
})