-
Notifications
You must be signed in to change notification settings - Fork 26
236 lines (188 loc) · 6.79 KB
/
rust.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
name: Rust
on:
push:
branches:
- main
tags:
- "**"
pull_request:
branches:
- "**"
concurrency:
# SHA is added to the end if on `main` to let all main workflows run
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/heads/long_lived/')) && github.sha || '' }}
cancel-in-progress: true
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: cargo-bins/cargo-binstall@main
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- name: Rustfmt
run: cargo fmt --all -- --files-with-diff --check
- name: Clippy
run: cargo clippy --workspace --all-targets --all-features
- name: Audit
run: cargo audit --ignore RUSTSEC-2023-0071
- name: Install cargo-machete
run: cargo binstall cargo-machete
- name: Unused dependencies
run: cargo machete
- name: Display sccache stats
run: sccache --show-stats
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
steps:
# The test files are read verbatim, making it problematic if git is
# allowed to insert \r when checking out files.
- name: Disable git autocrlf
run: git config --global core.autocrlf false
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- uses: cargo-bins/cargo-binstall@main
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- name: Prepare for coverage
if: matrix.os == 'ubuntu-latest'
run: |
cargo binstall grcov
echo "RUSTFLAGS=-Cinstrument-coverage" >> "$GITHUB_ENV"
echo "LLVM_PROFILE_FILE=$(pwd)/target/chia_rs-%p-%m.profraw" >> "$GITHUB_ENV"
echo "CARGO_TARGET_DIR=$(pwd)/target" >> "$GITHUB_ENV"
- name: Run tests
run: cargo test --workspace --all-features --release
- name: Continue with coverage
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install lcov -y
rustup component add llvm-tools-preview
grcov . --binary-path target -s . --branch --ignore-not-existing --ignore='*/.cargo/*' --ignore='tests/*' --ignore='venv/*' -o rust_cov.info
python -c 'with open("rust_cov.info") as f: lines = [l for l in f if not (l.startswith("DA:") and int(l.split(",")[1].strip()) >= 2**63)]; open("lcov.info", "w").writelines(lines)'
- name: Upload to Coveralls
uses: coverallsapp/github-action@v2
if: matrix.os == 'ubuntu-latest'
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
with:
path-to-lcov: "./lcov.info"
- name: Display sccache stats
run: sccache --show-stats
publish:
name: Publish
needs: [lint, test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- uses: cargo-bins/cargo-binstall@main
- name: Build
run: cargo build --release
- name: Upload crate artifacts
uses: actions/upload-artifact@v4
with:
name: crate
path: ./target/package/*-*.crate
- name: Install wasm-pack
run: cargo binstall wasm-pack
- name: Build and pack wasm
run: |
cd wasm
wasm-pack build
wasm-pack pack
- name: Upload NPM artifacts
uses: actions/upload-artifact@v4
with:
name: npm-pkg
path: ./wasm/pkg/*-*.tgz
- name: Install cargo-workspaces
run: cargo binstall cargo-workspaces
- name: Publish to crates.io if tagged
if: startsWith(github.event.ref, 'refs/tags')
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.cargo_registry_token }}
run: cargo ws publish --publish-as-is
- name: Publish to npmjs.com if tagged
if: startsWith(github.event.ref, 'refs/tags')
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.node_auth_token }}
package: wasm/pkg/package.json
benchmark:
name: Benchmark
runs-on: benchmark
env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- name: Run benchmarks
run: cargo bench --workspace --exclude chia_rs
- name: Display sccache stats
run: sccache --show-stats
fuzz:
name: Fuzz
runs-on: ubuntu-latest
env:
CARGO_PROFILE_RELEASE_LTO: false
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- name: Install cargo-fuzz
run: cargo +nightly install cargo-fuzz
- name: Fuzz chia-consensus
run: |
cd crates/chia-consensus
cargo fuzz list | xargs -I "%" sh -c "cargo +nightly fuzz run % -- -max_total_time=20 || exit 255"
- name: Fuzz chia-bls
env:
# We disable leak reports here because blspy appears to be allocating
# memory that's not freed. It might be a false positive since python is
# not unloaded before exiting.
LSAN_OPTIONS: detect_leaks=0
run: |
cd crates/chia-bls
python -m pip install blspy
cargo fuzz list | xargs -I "%" sh -c "cargo +nightly fuzz run % -- -max_total_time=10 || exit 255"
- name: Fuzz clvm-utils
run: |
cd crates/clvm-utils
cargo fuzz list | xargs -I "%" sh -c "cargo +nightly fuzz run % -- -max_total_time=20 || exit 255"
- name: Fuzz chia-protocol
run: |
cd crates/chia-protocol
cargo +nightly fuzz build
cargo fuzz list | xargs -I "%" sh -c "cargo +nightly fuzz run % -- -max_total_time=20 || exit 255"
- name: Fuzz chia-puzzles
run: |
cd crates/chia-puzzles
cargo +nightly fuzz build
cargo fuzz list | xargs -I "%" sh -c "cargo +nightly fuzz run % -- -max_total_time=20 || exit 255"
- name: Display sccache stats
run: sccache --show-stats