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