799d22a64667ed3fd8de55e4fe4a5097da7e2dba
[rust-lightning] / .github / workflows / build.yml
1 name: Continuous Integration Checks
2
3 on: [push, pull_request]
4
5 jobs:
6   build:
7     strategy:
8       fail-fast: false
9       matrix:
10         platform: [ ubuntu-latest ]
11         toolchain: [ stable,
12                      beta,
13                      # 1.41.1 is MSRV for Rust-Lightning, lightning-invoice, and lightning-persister
14                      1.41.1,
15                      # 1.45.2 is MSRV for lightning-net-tokio, lightning-block-sync, and coverage generation
16                      1.45.2,
17                      # 1.47.0 will be the MSRV for no-std builds using hashbrown once core2 is updated
18                      1.47.0]
19         include:
20           - toolchain: stable
21             build-net-tokio: true
22             build-no-std: true
23           - toolchain: stable
24             platform: macos-latest
25             build-net-tokio: true
26             build-no-std: true
27           - toolchain: beta
28             platform: macos-latest
29             build-net-tokio: true
30             build-no-std: true
31           - toolchain: stable
32             platform: windows-latest
33             build-net-tokio: true
34             build-no-std: true
35           - toolchain: beta
36             platform: windows-latest
37             build-net-tokio: true
38             build-no-std: true
39           - toolchain: beta
40             build-net-tokio: true
41             build-no-std: true
42           - toolchain: 1.41.1
43             build-no-std: false
44             test-log-variants: true
45           - toolchain: 1.45.2
46             build-net-old-tokio: true
47             build-net-tokio: true
48             build-no-std: false
49             coverage: true
50           - toolchain: 1.47.0
51             build-no-std: true
52     runs-on: ${{ matrix.platform }}
53     steps:
54       - name: Checkout source code
55         uses: actions/checkout@v3
56       - name: Install Rust ${{ matrix.toolchain }} toolchain
57         uses: actions-rs/toolchain@v1
58         with:
59           toolchain: ${{ matrix.toolchain }}
60           override: true
61           profile: minimal
62       - name: Pin tokio to 1.14 for Rust 1.45
63         if: "matrix.build-net-old-tokio"
64         run: cargo update -p tokio --precise "1.14.0" --verbose
65         env:
66           CARGO_NET_GIT_FETCH_WITH_CLI: "true"
67       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio
68         if: "matrix.build-net-tokio && !matrix.coverage"
69         run: cargo build --verbose --color always
70       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
71         if: matrix.coverage
72         run: RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always
73       - name: Build on Rust ${{ matrix.toolchain }}
74         if: "! matrix.build-net-tokio"
75         run: |
76           cargo build --verbose  --color always -p lightning
77           cargo build --verbose  --color always -p lightning-invoice
78           cargo build --verbose  --color always -p lightning-persister
79       - name: Build on Rust ${{ matrix.toolchain }} with all Log-Limiting features
80         if: matrix.test-log-variants
81         run: |
82           cd lightning
83           for FEATURE in $(cat Cargo.toml | grep '^max_level_' | awk '{ print $1 }'); do
84             cargo build --verbose --color always --features $FEATURE
85           done
86       - name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features
87         if: "matrix.build-net-tokio && !matrix.coverage"
88         run: |
89           cd lightning-block-sync
90           cargo build --verbose --color always --features rest-client
91           cargo build --verbose --color always --features rpc-client
92           cargo build --verbose --color always --features rpc-client,rest-client
93           cargo build --verbose --color always --features rpc-client,rest-client,tokio
94       - name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
95         if: matrix.coverage
96         run: |
97           cd lightning-block-sync
98           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rest-client
99           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client
100           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client
101           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client,tokio
102       - name: Test backtrace-debug builds on Rust ${{ matrix.toolchain }}
103         if: "matrix.build-no-std"
104         run: |
105           cd lightning && cargo test --verbose --color always --features backtrace
106       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio
107         if: "matrix.build-net-tokio && !matrix.coverage"
108         run: cargo test --verbose --color always
109       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
110         if: matrix.coverage
111         run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
112       - name: Test on no-std bullds Rust ${{ matrix.toolchain }}
113         if: "matrix.build-no-std && !matrix.coverage"
114         shell: bash # Default on Winblows is powershell
115         run: |
116           for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
117           cd $DIR
118             cargo test --verbose --color always --no-default-features --features no-std
119             # check if there is a conflict between no-std and the default std feature
120             cargo test --verbose --color always --features no-std
121             # check that things still pass without grind_signatures
122             # note that outbound_commitment_test only runs in this mode, because of hardcoded signature values
123             cargo test --verbose --color always --no-default-features --features std
124             # check if there is a conflict between no-std and the c_bindings cfg
125             RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always --no-default-features --features=no-std
126             cd ..
127           done
128           # check no-std compatibility across dependencies
129           cd no-std-check
130           cargo check --verbose --color always
131       - name: Build no-std-check on Rust ${{ matrix.toolchain }} for ARM Embedded
132         if: "matrix.build-no-std && matrix.platform == 'ubuntu-latest'"
133         run: |
134           cd no-std-check
135           rustup target add thumbv7m-none-eabi
136           sudo apt-get -y install gcc-arm-none-eabi
137           cargo build --target=thumbv7m-none-eabi
138       - name: Test on no-std builds Rust ${{ matrix.toolchain }} and full code-linking for coverage generation
139         if: "matrix.build-no-std && matrix.coverage"
140         run: |
141           cd lightning
142           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --no-default-features --features no-std
143           cd ..
144       - name: Test on Rust ${{ matrix.toolchain }}
145         if: "! matrix.build-net-tokio"
146         run: |
147           cargo test --verbose --color always  -p lightning
148           cargo test --verbose --color always  -p lightning-invoice
149           cargo test --verbose --color always  -p lightning-rapid-gossip-sync
150           cargo build --verbose  --color always -p lightning-persister
151           cargo build --verbose  --color always -p lightning-background-processor
152       - name: Test C Bindings Modifications on Rust ${{ matrix.toolchain }}
153         if: "! matrix.build-net-tokio"
154         run: |
155           RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always  -p lightning
156           RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always  -p lightning-invoice
157           RUSTFLAGS="--cfg=c_bindings" cargo build --verbose  --color always -p lightning-persister
158           RUSTFLAGS="--cfg=c_bindings" cargo build --verbose  --color always -p lightning-background-processor
159       - name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features
160         if: "matrix.build-net-tokio && !matrix.coverage"
161         run: |
162           cd lightning-block-sync
163           cargo test --verbose --color always --features rest-client
164           cargo test --verbose --color always --features rpc-client
165           cargo test --verbose --color always --features rpc-client,rest-client
166           cargo test --verbose --color always --features rpc-client,rest-client,tokio
167       - name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
168         if: matrix.coverage
169         run: |
170           cd lightning-block-sync
171           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rest-client
172           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client
173           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client
174           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client,tokio
175       - name: Install deps for kcov
176         if: matrix.coverage
177         run: |
178           sudo apt-get update
179           sudo apt-get -y install binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev
180       - name: Install kcov
181         if: matrix.coverage
182         run: |
183           wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
184           tar xzf master.tar.gz
185           cd kcov-master && mkdir build && cd build
186           cmake ..
187           make
188           make install DESTDIR=../../kcov-build
189           cd ../.. && rm -rf kcov-master master.tar.gz
190       - name: Generate coverage report
191         if: matrix.coverage
192         run: |
193           for file in target/debug/deps/lightning*; do
194             [ -x "${file}" ] || continue;
195             mkdir -p "target/cov/$(basename $file)";
196             ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file";
197           done
198       - name: Upload coverage
199         if: matrix.coverage
200         uses: codecov/codecov-action@v3
201         with:
202           # Could you use this to fake the coverage report for your PR? Sure.
203           # Will anyone be impressed by your amazing coverage? No
204           # Maybe if codecov wasn't broken we wouldn't need to do this...
205           token: f421b687-4dc2-4387-ac3d-dc3b2528af57
206           fail_ci_if_error: true
207
208   benchmark:
209     runs-on: ubuntu-latest
210     env:
211       TOOLCHAIN: nightly
212     steps:
213       - name: Checkout source code
214         uses: actions/checkout@v3
215       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
216         uses: actions-rs/toolchain@v1
217         with:
218           toolchain: ${{ env.TOOLCHAIN }}
219           override: true
220           profile: minimal
221       - name: Cache routing graph snapshot
222         id: cache-graph
223         uses: actions/cache@v3
224         with:
225           path: lightning/net_graph-2021-05-31.bin
226           key: ldk-net_graph-v0.0.15-2021-05-31.bin
227       - name: Fetch routing graph snapshot
228         if: steps.cache-graph.outputs.cache-hit != 'true'
229         run: |
230           curl --verbose -L -o lightning/net_graph-2021-05-31.bin https://bitcoin.ninja/ldk-net_graph-v0.0.15-2021-05-31.bin
231           echo "Sha sum: $(sha256sum lightning/net_graph-2021-05-31.bin | awk '{ print $1 }')"
232           if [ "$(sha256sum lightning/net_graph-2021-05-31.bin | awk '{ print $1 }')" != "${EXPECTED_ROUTING_GRAPH_SNAPSHOT_SHASUM}" ]; then
233             echo "Bad hash"
234             exit 1
235           fi
236         env:
237           EXPECTED_ROUTING_GRAPH_SNAPSHOT_SHASUM: 05a5361278f68ee2afd086cc04a1f927a63924be451f3221d380533acfacc303
238       - name: Fetch rapid graph sync reference input
239         run: |
240           curl --verbose -L -o lightning-rapid-gossip-sync/res/full_graph.lngossip https://bitcoin.ninja/ldk-compressed_graph-285cb27df79-2022-07-21.bin
241           echo "Sha sum: $(sha256sum lightning-rapid-gossip-sync/res/full_graph.lngossip | awk '{ print $1 }')"
242           if [ "$(sha256sum lightning-rapid-gossip-sync/res/full_graph.lngossip | awk '{ print $1 }')" != "${EXPECTED_RAPID_GOSSIP_SHASUM}" ]; then
243             echo "Bad hash"
244             exit 1
245           fi
246         env:
247           EXPECTED_RAPID_GOSSIP_SHASUM: e0f5d11641c11896d7af3a2246d3d6c3f1720b7d2d17aab321ecce82e6b7deb8
248       - name: Test with Network Graph on Rust ${{ matrix.toolchain }}
249         run: |
250           cd lightning
251           RUSTFLAGS="--cfg=require_route_graph_test" cargo test
252           RUSTFLAGS="--cfg=require_route_graph_test" cargo test --features hashbrown
253           cd ..
254       - name: Run benchmarks on Rust ${{ matrix.toolchain }}
255         run: |
256           cargo bench --features _bench_unstable
257
258   check_commits:
259     runs-on: ubuntu-latest
260     env:
261       TOOLCHAIN: 1.57.0
262     steps:
263       - name: Checkout source code
264         uses: actions/checkout@v3
265         with:
266           fetch-depth: 0
267       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
268         uses: actions-rs/toolchain@v1
269         with:
270           toolchain: ${{ env.TOOLCHAIN }}
271           override: true
272           profile: minimal
273       - name: Fetch full tree and rebase on upstream
274         run: |
275           git remote add upstream https://github.com/lightningdevkit/rust-lightning
276           git fetch upstream
277           export GIT_COMMITTER_EMAIL="rl-ci@example.com"
278           export GIT_COMMITTER_NAME="RL CI"
279           git rebase upstream/main
280       - name: For each commit, run cargo check (including in fuzz)
281         run: ci/check-each-commit.sh upstream/main
282
283   check_release:
284     runs-on: ubuntu-latest
285     env:
286       TOOLCHAIN: stable
287     steps:
288       - name: Checkout source code
289         uses: actions/checkout@v3
290         with:
291           fetch-depth: 0
292       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
293         uses: actions-rs/toolchain@v1
294         with:
295           toolchain: ${{ env.TOOLCHAIN }}
296           override: true
297           profile: minimal
298       - name: Run cargo check for release build.
299         run: |
300           cargo check --release
301           cargo check --no-default-features --features=no-std --release
302           cargo doc --release
303
304   fuzz:
305     runs-on: ubuntu-latest
306     env:
307       TOOLCHAIN: stable
308     steps:
309       - name: Checkout source code
310         uses: actions/checkout@v3
311       - name: Install Rust 1.58 toolchain
312         uses: actions-rs/toolchain@v1
313         with:
314           toolchain: 1.58
315           override: true
316           profile: minimal
317       - name: Install dependencies for honggfuzz
318         run: |
319           sudo apt-get update
320           sudo apt-get -y install build-essential binutils-dev libunwind-dev
321       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
322         run: cd fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose --color always
323       - name: Run fuzzers
324         run: cd fuzz && ./ci-fuzz.sh && cd ..
325       - name: Run lightning-invoice fuzzers
326         run: cd lightning-invoice/fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose && ./ci-fuzz.sh
327
328   linting:
329     runs-on: ubuntu-latest
330     env:
331       TOOLCHAIN: 1.47.0
332     steps:
333       - name: Checkout source code
334         uses: actions/checkout@v3
335       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
336         uses: actions-rs/toolchain@v1
337         with:
338           toolchain: ${{ env.TOOLCHAIN }}
339           override: true
340           profile: minimal
341       - name: Install clippy
342         run: |
343           rustup component add clippy
344       - name: Run default clippy linting
345         run: |
346           cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else -Dclippy::try_err