-
Notifications
You must be signed in to change notification settings - Fork 1
405 lines (349 loc) · 12.4 KB
/
ci.yml
File metadata and controls
405 lines (349 loc) · 12.4 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
name: CI
on:
push:
branches: [main, 001-cipherbft-implementation]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
# Detect which files/crates have changed
changes:
name: Detect Changes
runs-on: ubuntu-latest
outputs:
rust: ${{ steps.filter.outputs.rust }}
rust_files: ${{ steps.filter.outputs.rust_files }}
types: ${{ steps.filter.outputs.types }}
crypto: ${{ steps.filter.outputs.crypto }}
data-chain: ${{ steps.filter.outputs.data-chain }}
storage: ${{ steps.filter.outputs.storage }}
consensus: ${{ steps.filter.outputs.consensus }}
execution: ${{ steps.filter.outputs.execution }}
mempool: ${{ steps.filter.outputs.mempool }}
rpc: ${{ steps.filter.outputs.rpc }}
node: ${{ steps.filter.outputs.node }}
metrics: ${{ steps.filter.outputs.metrics }}
cargo: ${{ steps.filter.outputs.cargo }}
ci: ${{ steps.filter.outputs.ci }}
# Derived: crates that need checking (including dependents)
affected_crates: ${{ steps.affected.outputs.crates }}
any_crate: ${{ steps.affected.outputs.any_crate }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Detect file changes
uses: dorny/paths-filter@v3
id: filter
with:
list-files: shell
filters: |
rust:
- '**/*.rs'
- 'Cargo.toml'
- 'Cargo.lock'
- 'crates/**/Cargo.toml'
types:
- 'crates/types/**'
crypto:
- 'crates/crypto/**'
data-chain:
- 'crates/data-chain/**'
storage:
- 'crates/storage/**'
consensus:
- 'crates/consensus/**'
execution:
- 'crates/execution/**'
mempool:
- 'crates/mempool/**'
rpc:
- 'crates/rpc/**'
node:
- 'crates/node/**'
metrics:
- 'crates/metrics/**'
cargo:
- 'Cargo.toml'
- 'Cargo.lock'
- 'crates/**/Cargo.toml'
ci:
- '.github/workflows/**'
- name: Compute affected crates
id: affected
run: |
# Crate dependency graph (simplified):
# types -> crypto, data-chain, storage, consensus, execution, mempool, rpc, node, metrics
# crypto -> data-chain, consensus, node
# data-chain -> consensus, node
# storage -> execution, node
# consensus -> node
# execution -> rpc, node
# mempool -> node
# rpc -> node
# metrics -> node
CRATES=""
# If root Cargo.toml or CI changed, check everything
if [[ "${{ steps.filter.outputs.cargo }}" == "true" ]] || [[ "${{ steps.filter.outputs.ci }}" == "true" ]]; then
CRATES="types crypto data-chain storage consensus execution mempool rpc node metrics"
else
# Build list of affected crates based on changes and dependencies
# types is a foundation - if it changes, most crates need rechecking
if [[ "${{ steps.filter.outputs.types }}" == "true" ]]; then
CRATES="types crypto data-chain storage consensus execution mempool rpc node metrics"
fi
# crypto affects data-chain, consensus, node
if [[ "${{ steps.filter.outputs.crypto }}" == "true" ]]; then
CRATES="$CRATES crypto data-chain consensus node"
fi
# data-chain affects consensus, node
if [[ "${{ steps.filter.outputs.data-chain }}" == "true" ]]; then
CRATES="$CRATES data-chain consensus node"
fi
# storage affects execution, node
if [[ "${{ steps.filter.outputs.storage }}" == "true" ]]; then
CRATES="$CRATES storage execution node"
fi
# consensus affects node
if [[ "${{ steps.filter.outputs.consensus }}" == "true" ]]; then
CRATES="$CRATES consensus node"
fi
# execution affects rpc, node
if [[ "${{ steps.filter.outputs.execution }}" == "true" ]]; then
CRATES="$CRATES execution rpc node"
fi
# mempool affects node
if [[ "${{ steps.filter.outputs.mempool }}" == "true" ]]; then
CRATES="$CRATES mempool node"
fi
# rpc affects node
if [[ "${{ steps.filter.outputs.rpc }}" == "true" ]]; then
CRATES="$CRATES rpc node"
fi
# node is the top-level binary
if [[ "${{ steps.filter.outputs.node }}" == "true" ]]; then
CRATES="$CRATES node"
fi
# metrics is utility, only affects itself and node
if [[ "${{ steps.filter.outputs.metrics }}" == "true" ]]; then
CRATES="$CRATES metrics node"
fi
fi
# Deduplicate and sort
CRATES=$(echo "$CRATES" | tr ' ' '\n' | sort -u | tr '\n' ' ' | xargs)
echo "Affected crates: $CRATES"
echo "crates=$CRATES" >> $GITHUB_OUTPUT
if [[ -n "$CRATES" ]]; then
echo "any_crate=true" >> $GITHUB_OUTPUT
else
echo "any_crate=false" >> $GITHUB_OUTPUT
fi
fmt:
name: Rustfmt
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.rust == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Check formatting (changed files only)
env:
CHANGED_FILES: ${{ needs.changes.outputs.rust_files }}
run: |
if [[ -n "$CHANGED_FILES" ]]; then
# Filter to only .rs files
RS_FILES=$(echo "$CHANGED_FILES" | tr ' ' '\n' | grep '\.rs$' || true)
if [[ -n "$RS_FILES" ]]; then
echo "Checking formatting for changed files:"
echo "$RS_FILES"
echo "$RS_FILES" | xargs rustfmt --check --edition 2021
else
echo "No .rs files changed, skipping format check"
fi
else
# Fallback: check all files if file list not available
cargo fmt --all -- --check
fi
check:
name: Check
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.any_crate == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Run cargo check (affected crates)
env:
AFFECTED_CRATES: ${{ needs.changes.outputs.affected_crates }}
run: |
if [[ -n "$AFFECTED_CRATES" ]]; then
echo "Checking crates: $AFFECTED_CRATES"
# Build package flags (node crate is named 'cipherd')
PKG_FLAGS=""
for crate in $AFFECTED_CRATES; do
if [[ "$crate" == "node" ]]; then
PKG_FLAGS="$PKG_FLAGS -p cipherd"
else
PKG_FLAGS="$PKG_FLAGS -p cipherbft-$crate"
fi
done
cargo check --all-targets --all-features $PKG_FLAGS
else
echo "No crates to check"
fi
clippy:
name: Clippy
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.any_crate == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Run clippy (affected crates)
env:
AFFECTED_CRATES: ${{ needs.changes.outputs.affected_crates }}
run: |
if [[ -n "$AFFECTED_CRATES" ]]; then
echo "Running clippy on crates: $AFFECTED_CRATES"
# Build package flags (node crate is named 'cipherd')
PKG_FLAGS=""
for crate in $AFFECTED_CRATES; do
if [[ "$crate" == "node" ]]; then
PKG_FLAGS="$PKG_FLAGS -p cipherd"
else
PKG_FLAGS="$PKG_FLAGS -p cipherbft-$crate"
fi
done
cargo clippy --all-targets --all-features $PKG_FLAGS -- -D warnings
else
echo "No crates to lint"
fi
test:
name: Test Suite
needs: changes
if: needs.changes.outputs.any_crate == 'true'
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
name: Linux x86_64
- os: macos-latest
target: aarch64-apple-darwin
name: macOS ARM64
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Run tests (affected crates)
env:
AFFECTED_CRATES: ${{ needs.changes.outputs.affected_crates }}
run: |
if [[ -n "$AFFECTED_CRATES" ]]; then
echo "Testing crates: $AFFECTED_CRATES"
# Build package flags (node crate is named 'cipherd')
PKG_FLAGS=""
for crate in $AFFECTED_CRATES; do
if [[ "$crate" == "node" ]]; then
PKG_FLAGS="$PKG_FLAGS -p cipherd"
else
PKG_FLAGS="$PKG_FLAGS -p cipherbft-$crate"
fi
done
cargo test --all-features --verbose $PKG_FLAGS
else
echo "No crates to test"
fi
coverage:
name: Code Coverage
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.rust == 'true'
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@v2
with:
tool: cargo-llvm-cov
- name: Generate coverage (affected crates)
env:
AFFECTED_CRATES: ${{ needs.changes.outputs.affected_crates }}
run: |
if [[ -n "$AFFECTED_CRATES" ]]; then
echo "Generating coverage for crates: $AFFECTED_CRATES"
# Build package flags (node crate is named 'cipherd')
PKG_FLAGS=""
for crate in $AFFECTED_CRATES; do
if [[ "$crate" == "node" ]]; then
PKG_FLAGS="$PKG_FLAGS -p cipherd"
else
PKG_FLAGS="$PKG_FLAGS -p cipherbft-$crate"
fi
done
cargo llvm-cov --all-features $PKG_FLAGS --lcov --output-path lcov.info
else
# If no specific crates, run on all (shouldn't happen given the if condition)
cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
fi
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./lcov.info
fail_ci_if_error: false
verbose: true
# SECURITY: Always run cargo-deny regardless of changes
# This ensures license compliance and security advisory checks
deny:
name: Cargo Deny (Security)
runs-on: ubuntu-latest
# No 'needs: changes' - always runs for security
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run cargo deny
uses: EmbarkStudios/cargo-deny-action@v2
with:
command: check
arguments: --all-features
build:
name: Build Release
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.rust == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Build release
run: cargo build --release --verbose