forked from domo-iot/libp2p-rust-dht
-
Notifications
You must be signed in to change notification settings - Fork 0
483 lines (377 loc) · 12 KB
/
libp2p-rust-dht.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
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
name: libp2p-rust-dht
on:
push:
branches:
- master
paths:
- 'src/**'
- 'crates/**'
- 'fuzz/**'
- '.github/**'
- 'Cargo.toml'
- 'Cargo.lock'
pull_request:
branches:
- master
paths:
- 'src/**'
- 'crates/**'
- 'fuzz/**'
- '.github/**'
- 'Cargo.toml'
- 'Cargo.lock'
jobs:
################################## LEGAL AND FORMAT LAYER ######################
reuse:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: REUSE Compliance Check
uses: fsfe/reuse-action@v1
clippy-rustfmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: clippy, rustfmt
- name: Run rustfmt
run:
cargo fmt --all -- --check --verbose
- name: Run cargo clippy
uses: giraffate/clippy-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
clippy_flags: --all-targets -- -D warnings
reporter: github-pr-review
static-code-analysis:
env:
RCA_LINK: https://github.com/mozilla/rust-code-analysis/releases/download
RCA_VERSION: v0.0.25
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install rust-code-analysis
run: |
mkdir -p $HOME/.local/bin
curl -L "$RCA_LINK/$RCA_VERSION/rust-code-analysis-linux-cli-x86_64.tar.gz" |
tar xz -C $HOME/.local/bin
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Run rust-code-analysis
run: |
mkdir $HOME/rca-json
rust-code-analysis-cli --metrics -O json --pr -o "$HOME/rca-json" -p $PWD
- name: Upload rust-code-analysis json
uses: actions/upload-artifact@v3
with:
name: rca-json
path: ~/rca-json
################################## BUILD AND DOCS LAYER ########################
build:
needs: [reuse, clippy-rustfmt, static-code-analysis]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install protobuf compiler
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Build
run: cargo build --verbose
docs:
needs: [reuse, clippy-rustfmt, static-code-analysis]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install protobuf compiler
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Generate docs
run: cargo doc --verbose --no-deps
################################## CODE COVERAGE LAYER ##################################
code-coverage:
needs: [build, docs]
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: mysecretpassword
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- name: Install protobuf compiler
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Install grcov
env:
GRCOV_LINK: https://github.com/mozilla/grcov/releases/download
GRCOV_VERSION: v0.8.13
run: |
curl -L "$GRCOV_LINK/$GRCOV_VERSION/grcov-x86_64-unknown-linux-musl.tar.bz2" |
tar xj -C $HOME/.cargo/bin
- name: Install llvm-tools-preview
run: |
rustup component add llvm-tools-preview
# Not necessary on a newly created image, but strictly advised
- name: Run cargo clean
run: |
cargo clean
- name: Run tests
env:
RUSTFLAGS: "-Cinstrument-coverage"
LLVM_PROFILE_FILE: "libp2p-rust-dht-%p-%m.profraw"
run: |
cargo test --verbose --all
- name: Get coverage data for codecov
run: |
grcov . --binary-path ./target/debug/ -s . -t lcov --branch \
--ignore-not-existing --ignore "/*" --ignore "../*" -o lcov.info
- name: Codecov upload
uses: codecov/codecov-action@v3
with:
files: lcov.info
- name: Get total coverage
run: |
# Remove lcov.info file to avoid function duplications
rm -rf lcov.info
grcov . --binary-path ./target/debug/ -s . -t covdir --branch \
--token YOUR_COVDIR_TOKEN --ignore-not-existing --ignore "/*" \
--ignore "../*" -o covdir.json
- name: Evaluate code coverage value
shell: bash
run: |
# Retrieve code coverage associated to the repository
FLOAT_COVERAGE=$(jq '.coveragePercent' covdir.json)
# Round the float value to the nearest value
COVERAGE_OUTPUT=$(printf "%.0f" $FLOAT_COVERAGE)
# If code coverage >= 80, green traffic light
if [ $COVERAGE_OUTPUT -ge 80 ]
then
echo "$COVERAGE_OUTPUT > 80 --> Green"
# If code coverage is >=60 but < 80, orange traffic light
elif [ $COVERAGE_OUTPUT -ge 60 ]
then
echo "60 <= $COVERAGE_OUTPUT < 80 --> Orange"
# Otherwise, red traffic light
else
echo "$COVERAGE_OUTPUT < 60 --> Red"
exit 1
fi
- name: Install weighted-code-coverage
env:
WCC_LINK: https://github.com/SoftengPoliTo/weighted-code-coverage/releases/download
WCC_VERSION: v0.2.0
WCC_BINARY: weighted-code-coverage-0.2.0-x86_64-unknown-linux-gnu.tar.gz
run: |
curl -L "$WCC_LINK/$WCC_VERSION/$WCC_BINARY" |
tar xz -C $HOME/.cargo/bin
- name: Run grcov to produce a coveralls json
run: |
grcov . --binary-path ./target/debug/ -t coveralls -s . --token YOUR_COVERALLS_TOKEN > coveralls.json
- name: Run weighted-code-coverage
run: |
mkdir $HOME/wcc-output
weighted-code-coverage -p src/ -j coveralls.json -c cyclomatic --json $HOME/wcc-output/out.json
- name: Upload weighted-code-coverage data
uses: actions/upload-artifact@v3
with:
name: weighted-code-coverage-ubuntu
path: ~/wcc-output/out.json
################################## DEPENDENCY LAYER ###########################
audit:
needs: [code-coverage]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check dependencies changes
uses: dorny/paths-filter@v2
id: changes
with:
filters: |
cargo:
- 'Cargo.toml'
- 'Cargo.lock'
- name: Install protobuf compiler
if: steps.changes.outputs.cargo == 'true'
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- name: Run cargo-audit
if: steps.changes.outputs.cargo == 'true'
uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
deny:
needs: [code-coverage]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check dependencies changes
uses: dorny/paths-filter@v2
id: changes
with:
filters: |
cargo:
- 'Cargo.toml'
- 'Cargo.lock'
- name: Install protobuf compiler
if: steps.changes.outputs.cargo == 'true'
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- name: Install Rust stable
if: steps.changes.outputs.cargo == 'true'
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Install cargo-deny
if: steps.changes.outputs.cargo == 'true'
env:
DENY_LINK: https://github.com/EmbarkStudios/cargo-deny/releases/download
DENY_VERSION: 0.13.7
run: |
curl -L "$DENY_LINK/$DENY_VERSION/cargo-deny-$DENY_VERSION-x86_64-unknown-linux-musl.tar.gz" |
tar xz -C $HOME/.cargo/bin --strip-components 1
- name: Run cargo-deny
if: steps.changes.outputs.cargo == 'true'
run: |
cargo deny init
cargo deny check bans
# cargo deny check licenses
udeps:
needs: [code-coverage]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check dependencies changes
uses: dorny/paths-filter@v2
id: changes
with:
filters: |
cargo:
- 'Cargo.toml'
- 'Cargo.lock'
- name: Install protobuf compiler
if: steps.changes.outputs.cargo == 'true'
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- name: Install Rust nightly
if: steps.changes.outputs.cargo == 'true'
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
- name: Install cargo-udeps
if: steps.changes.outputs.cargo == 'true'
env:
UDEPS_LINK: https://github.com/est31/cargo-udeps/releases/download
UDEPS_VERSION: v0.1.35
run: |
curl -L "$UDEPS_LINK/$UDEPS_VERSION/cargo-udeps-$UDEPS_VERSION-x86_64-unknown-linux-gnu.tar.gz" |
tar xz -C $HOME/.cargo/bin --strip-components 2
- name: Run cargo-udeps
if: steps.changes.outputs.cargo == 'true'
run: |
cargo +nightly udeps --all-targets
################################## CACHE LEVEL #################################
cache-level:
needs: [audit, deny, udeps]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Rust nightly
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
components: rust-src
- name: Cache produced data
id: cache-data
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-ci-${{ hashFiles('**/Cargo.toml') }}
- name: Install cargo-careful
if: steps.cache-data.outputs.cache-hit != 'true'
run: |
cargo install cargo-careful
################################## UNSAFE CHECKS LEVEL #########################
careful:
needs: cache-level
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install protobuf compiler
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- name: Install Rust nightly
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
components: rust-src
- name: Cache produced data
id: cache-data
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-ci-${{ hashFiles('**/Cargo.toml') }}
- name: Run cargo-careful
run: |
cargo +nightly careful test
# cargo +nightly careful run
address-sanitizer:
needs: cache-level
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install protobuf compiler
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- name: Install Rust nightly
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
components: rust-src
- name: Run AddressSanitizer
env:
RUSTFLAGS: -Zsanitizer=address -Copt-level=3
RUSTDOCFLAGS: -Zsanitizer=address
run: cargo test -Zbuild-std --target x86_64-unknown-linux-gnu
# Use `cargo run` for the analysis of a binary.
# Usage of the `help` command as base command, please replace it
# with the effective command that AddressSanitizer has to analyze
# run: cargo run -Zbuild-std --target x86_64-unknown-linux-gnu -- --help