-
Notifications
You must be signed in to change notification settings - Fork 109
197 lines (171 loc) · 6.83 KB
/
benchmarks.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
on:
push:
branches:
- master
workflow_dispatch:
inputs:
pr_number:
description: 'Pull Request Number'
required: false
default: ''
# note: the "benchmarks please" comments aren't dispatched here,
# there's a script running on one of our internal servers that reads those and then
# dispatches to this workflow using the workflow_dispatch there.
name: Benchmarks
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
benchmark:
name: run benchmarks
runs-on: benchmarks-runner
steps:
- name: Enable CPU boost
run: echo "1" | sudo tee /sys/devices/system/cpu/cpufreq/boost
- name: Checkout sources for a PR
if: ${{ github.event.inputs.ref }}
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.ref }}
fetch-depth: 0
- name: Checkout sources
if: github.event.inputs.ref == ''
uses: actions/checkout@v3
with:
fetch-depth: 10
- name: Set up for PR context
if: github.event.inputs.pr_number
run: |
echo "PR_NUMBER=${{ github.event.inputs.pr_number }}" >> $GITHUB_ENV
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: wasm32-unknown-unknown
override: true
- name: Build
working-directory: crates/bench/
run: |
cargo build --release
- name: Install clippy for module build
run: |
rustup component add clippy
- name: Disable CPU boost
run: echo "0" | sudo tee /sys/devices/system/cpu/cpufreq/boost
- name: Extract branch name
if: "! github.event.inputs.pr_number"
shell: bash
run: |
BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
echo "NORMALIZED_BRANCH_NAME=${BRANCH_NAME//\//-}" >> $GITHUB_ENV
- name: Branch; run bench
if: "! github.event.inputs.pr_number"
run: |
echo "Running benchmarks with sqlite"
pushd crates/bench
cargo bench --bench generic --bench special -- --save-baseline $NORMALIZED_BRANCH_NAME
cargo run --bin summarize pack $NORMALIZED_BRANCH_NAME
popd
mkdir criterion-results
cp target/criterion/$NORMALIZED_BRANCH_NAME.json criterion-results/
cp target/criterion/$NORMALIZED_BRANCH_NAME.json criterion-results/$GITHUB_SHA.json
# TODO: can we optionally download if it only might fail?
#- name: PR; download bench results for compare
# if: github.event.inputs.pr_number
# uses: actions/github-script@v6
# with:
# github-token: ${{secrets.GITHUB_TOKEN}}
# script: |
# try {
# let artifact = github.rest.actions.getArtifact({
# owner: "clockwork",
# repo: "SpacetimeDB",
#
# })
# }
- name: PR; run bench
if: github.event.inputs.pr_number
run: |
echo "Running benchmarks without sqlite"
# have to pass explicit names, otherwise it will try to run the tests and fail for some reason...
pushd crates/bench
cargo bench --bench generic --bench special -- --save-baseline branch '(special|stdb_module|stdb_raw)'
cargo run --bin summarize pack branch
popd
mkdir criterion-results
cp target/criterion/branch.json criterion-results/pr-$PR_NUMBER.json
- name: PR; compare benchmarks
if: github.event.inputs.pr_number
working-directory: crates/bench/
run: |
if [ -e target/criterion/$NORMALIZED_BRANCH_NAME.json ]; then
cargo run --bin summarize markdown-report branch.json $NORMALIZED_BRANCH_NAME.json --report-name report
else
cargo run --bin summarize markdown-report branch.json --report-name report
fi
# this will work for both PR and master
- name: Upload criterion results to DO spaces
uses: shallwefootball/s3-upload-action@master
with:
aws_key_id: ${{ secrets.AWS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
aws_bucket: "spacetimedb-ci-benchmarks"
source_dir: criterion-results
endpoint: https://nyc3.digitaloceanspaces.com
destination_dir: benchmarks
- name: Fetch markdown summary PR
if: github.event.inputs.pr_number
run: |
curl -sS https://benchmarks.spacetimedb.com/compare/master/pr-$PR_NUMBER > report.md
- name: Fetch markdown summary PR
if: "! github.event.inputs.pr_number"
run: |
git fetch
old=$(git rev-parse HEAD~1)
curl -sS https://benchmarks.spacetimedb.com/compare/$old/$GITHUB_SHA > report.md
# https://stackoverflow.com/questions/58066966/commenting-a-pull-request-in-a-github-action
# https://github.com/boa-dev/criterion-compare-action/blob/main/main.js
- name: test comment
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
let stuff = require('fs').readFileSync('report.md', 'utf8');
let body = `<details><summary>Benchmark results</summary>\n\n${stuff}\n\n</details>`;
try {
if (process.env.PR_NUMBER) {
let number = parseInt(process.env.PR_NUMBER);
core.info("context: issue number: "+number)
const { data: comment } = await github.rest.issues.createComment({
owner: "clockworklabs",
repo: "SpacetimeDB",
issue_number: number,
body: body,
});
core.info(
`Created comment id '${comment.id}' on issue '${number}' in 'clockworklabs/SpacetimeDB'.`
);
core.setOutput("comment-id", comment.id);
} else {
const { data: comment } = github.rest.repos.createCommitComment({
commit_sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})
core.info(
`Created comment id '${comment.id}' on commit '${context.sha}' in 'clockworklabs/SpacetimeDB'.`
);
core.setOutput("comment-id", comment.id);
}
} catch (err) {
core.warning(`Failed to comment: ${err}`);
core.info("Commenting is not possible from forks.");
core.info("Logging here instead.");
console.log(body);
}
- name: Clean up
if: always()
run: |
rm -fr /stdb/*