-
-
Notifications
You must be signed in to change notification settings - Fork 125
201 lines (180 loc) · 7.38 KB
/
Copy pathbinary-size.yml
File metadata and controls
201 lines (180 loc) · 7.38 KB
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
permissions:
contents: read
name: Binary Size
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
concurrency:
# head_ref alone could collide across forks; the PR number is unique.
group: binary-size-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
PROTOC_VERSION: "3.25.3"
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
# The target dir is restored fresh each run (Swatinem cache), so incremental
# state is always cold and only bloats artifacts; worse, sccache refuses to
# cache incremental compilations, so leaving it on excludes the workspace
# crates from caching entirely.
CARGO_INCREMENTAL: "0"
CARGO_BLOAT_VERSION: "0.12.1"
CARGO_LLVM_LINES_VERSION: "0.4.46"
jobs:
binary-size-pr:
if: github.event_name == 'pull_request'
name: Binary Size (PR)
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
pull-requests: write
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2026-06-16
- name: Install tools (protoc, cargo-binstall)
uses: taiki-e/install-action@v2
with:
tool: protoc@${{ env.PROTOC_VERSION }},cargo-binstall
- name: Install cargo-bloat and cargo-llvm-lines
env:
# binstall can fall back to compilation before sccache is installed.
RUSTC_WRAPPER: ""
run: >
cargo binstall --no-confirm
cargo-bloat@${{ env.CARGO_BLOAT_VERSION }}
cargo-llvm-lines@${{ env.CARGO_LLVM_LINES_VERSION }}
- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.11
# Cache the target dir too: sccache can't cache proc-macros, build scripts
# or bins (linker-output crate types), and those recompile every run.
# Swatinem restores them; sccache still fills in after a Cargo.lock change.
- name: Cache Rust build (registry + target)
uses: Swatinem/rust-cache@v2
with:
prefix-key: ${{ runner.os }}-cargo-binary-size
cache-targets: "true"
# measure_binary_size builds an example, which pulls the cpal dev-dependency (alsa-sys).
- name: Install ALSA dev headers
run: sudo apt-get update && sudo apt-get install -y libasound2-dev
- name: Measure binary size
run: cargo xt ci measure-binary-size --out-dir size-out
- name: Upload size artifacts
uses: actions/upload-artifact@v7
with:
name: size-metrics
path: size-out/
retention-days: 90
- name: Download baseline from latest main run
id: baseline
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: cargo xt ci workflow size-baseline
# Informational (job summary); the real gate is the report script below.
# Tolerates the window before the first push run creates the series.
- name: Compare against gh-pages series
continue-on-error: true
uses: benchmark-action/github-action-benchmark@v1
with:
name: "whatsapp-rust binary size"
tool: "customSmallerIsBetter"
output-file-path: size-out/size-metrics.json
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: false
save-data-file: false
benchmark-data-dir-path: dev/binary-size
summary-always: true
# The event payload freezes the labels at trigger time; query them
# live so adding size-increase-ok + re-running the job works.
- name: Check size-increase-ok label
id: override
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: cargo xt ci workflow size-override
# No GH_TOKEN here: the report script is PR-controlled code.
- name: Generate report and evaluate gate
env:
BASE_DIR: ${{ steps.baseline.outputs.dir }}
ALLOW_SIZE_INCREASE: ${{ steps.override.outputs.allow }}
run: |
cargo xt ci binary-size-report --head size-out --out-dir size-out
cargo xt ci workflow append-summary size-out/report.md
# Fork PRs run with a read-only token, so they only get the job summary.
- name: Post sticky PR comment
if: github.event.pull_request.head.repo.full_name == github.repository
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: cargo xt ci workflow size-comment
- name: Enforce size budget
run: cargo xt ci workflow size-gate
binary-size-push:
# Dispatch only publishes from main so stray branches can't pollute the series.
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')
name: Binary Size (push)
runs-on: ubuntu-latest
permissions:
contents: write
# github-action-benchmark deploys the gh-pages site after auto-push.
deployments: write
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2026-06-16
- name: Install tools (protoc, cargo-binstall)
uses: taiki-e/install-action@v2
with:
tool: protoc@${{ env.PROTOC_VERSION }},cargo-binstall
- name: Install cargo-bloat and cargo-llvm-lines
env:
# binstall can fall back to compilation before sccache is installed.
RUSTC_WRAPPER: ""
run: >
cargo binstall --no-confirm
cargo-bloat@${{ env.CARGO_BLOAT_VERSION }}
cargo-llvm-lines@${{ env.CARGO_LLVM_LINES_VERSION }}
- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.11
# Cache the target dir too: sccache can't cache proc-macros, build scripts
# or bins (linker-output crate types), and those recompile every run.
# Swatinem restores them; sccache still fills in after a Cargo.lock change.
- name: Cache Rust build (registry + target)
uses: Swatinem/rust-cache@v2
with:
prefix-key: ${{ runner.os }}-cargo-binary-size
cache-targets: "true"
# measure_binary_size builds an example, which pulls the cpal dev-dependency (alsa-sys).
- name: Install ALSA dev headers
run: sudo apt-get update && sudo apt-get install -y libasound2-dev
- name: Measure binary size
run: cargo xt ci measure-binary-size --out-dir size-out
# This artifact is the comparison baseline for PR runs.
- name: Upload size artifacts
uses: actions/upload-artifact@v7
with:
name: size-metrics
path: size-out/
retention-days: 90
# Post-merge safety net: alerts on the commit when a regression landed
# despite (or around) the PR gate, e.g. via the size-increase-ok label.
- name: Store series on gh-pages
uses: benchmark-action/github-action-benchmark@v1
with:
name: "whatsapp-rust binary size"
tool: "customSmallerIsBetter"
output-file-path: size-out/size-metrics.json
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
benchmark-data-dir-path: dev/binary-size
max-items-in-chart: 200
alert-threshold: "102%"
comment-on-alert: true
fail-on-alert: false
summary-always: true