-
-
Notifications
You must be signed in to change notification settings - Fork 125
100 lines (82 loc) · 3.13 KB
/
rustbench.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
on:
pull_request:
paths:
- '**.rs'
- '**/Cargo.toml'
workflow_dispatch:
name: Benchmark
permissions:
pull-requests: write
jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Install Critcmp
uses: baptiste0928/cargo-install@v3
with:
crate: critcmp
version: latest
- name: Run Benchmarks on changes
run: |
cargo bench --workspace --bench bench -- --save-baseline default_changes
cargo bench --workspace --bench bench --features forbid_unsafe -- --save-baseline forbid_unsafe_changes
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
clean: false
- name: Run Benchmarks before changes
run: |
cargo bench --workspace --bench bench -- --save-baseline default_before
# Skip benchmarking for forbid_unsafe feature if the PR base commit doesn't have the feature
if [[ "$(grep forbid_unsafe Cargo.toml)" ]]; then
cargo bench --workspace --bench bench --features forbid_unsafe -- --save-baseline forbid_unsafe_before
fi
- name: Compare benchmarks
run: |
echo 'results<<EOF' >> $GITHUB_OUTPUT
critcmp default_before default_changes >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
id: compare
- name: Compare benchmarks for forbid-unsafe
run: |
echo 'results<<EOF' >> $GITHUB_OUTPUT
if [[ "$(grep forbid_unsafe Cargo.toml)" ]]; then
critcmp forbid_unsafe_before forbid_unsafe_changes >> $GITHUB_OUTPUT
else
echo 'NOTE: PR base commit does not support the "forbid_unsafe" feature;' >> $GITHUB_OUTPUT
echo 'comparing forbid_unsafe against the default features on base instead.' >> $GITHUB_OUTPUT
critcmp default_before forbid_unsafe_changes >> $GITHUB_OUTPUT
fi
echo 'EOF' >> $GITHUB_OUTPUT
id: compare-forbid-unsafe
- name: Comment PR with benchmarks
uses: thollander/actions-comment-pull-request@v2
continue-on-error: true
with:
message: |
Benchmark results with default features:
```
${{ steps.compare.outputs.results }}
```
Benchmark results with feature "forbid_unsafe":
```
${{ steps.compare-forbid-unsafe.outputs.results }}
```
comment_tag: benchmarks
id: comment
- name: If PR comment failed, write to PR summary
if: steps.comment.outcome != 'success'
run: |
echo '### Benchmark results' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo '${{ steps.compare.outputs.results }}' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo '### Benchmark results with forbid-unsafe' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo '${{ steps.compare-forbid-unsafe.outputs.results }}' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY