5dcbb677e6d8a6d6f88e62b20e7307c862807c0e
[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.36.0 is MSRV for Rust-Lightning, lightning-invoice, and lightning-persister
14                      1.36.0,
15                      # 1.41.0 is Debian stable
16                      1.41.0,
17                      # 1.45.2 is MSRV for lightning-net-tokio, lightning-block-sync, and coverage generation
18                      1.45.2,
19                      # 1.47.0 will be the MSRV for no-std builds using hashbrown once core2 is updated
20                      1.47.0]
21         include:
22           - toolchain: stable
23             build-net-tokio: true
24             build-no-std: true
25           - toolchain: stable
26             platform: macos-latest
27             build-net-tokio: true
28             build-no-std: true
29           - toolchain: beta
30             platform: macos-latest
31             build-net-tokio: true
32             build-no-std: true
33           - toolchain: stable
34             platform: windows-latest
35             build-net-tokio: true
36             build-no-std: true
37           - toolchain: beta
38             platform: windows-latest
39             build-net-tokio: true
40             build-no-std: true
41           - toolchain: beta
42             build-net-tokio: true
43             build-no-std: true
44           - toolchain: 1.36.0
45             build-no-std: false
46             test-log-variants: true
47           - toolchain: 1.41.0
48             build-no-std: false
49           - toolchain: 1.45.2
50             build-net-old-tokio: true
51             build-net-tokio: true
52             build-no-std: false
53             coverage: true
54           - toolchain: 1.47.0
55             build-no-std: true
56     runs-on: ${{ matrix.platform }}
57     steps:
58       - name: Checkout source code
59         uses: actions/checkout@v2
60       - name: Install Rust ${{ matrix.toolchain }} toolchain
61         uses: actions-rs/toolchain@v1
62         with:
63           toolchain: ${{ matrix.toolchain }}
64           override: true
65           profile: minimal
66       - name: Pin tokio to 1.14 for Rust 1.45
67         if: "matrix.build-net-old-tokio"
68         run: cargo update -p tokio --precise "1.14.0" --verbose
69       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio
70         if: "matrix.build-net-tokio && !matrix.coverage"
71         run: cargo build --verbose --color always
72       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
73         if: matrix.coverage
74         run: RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always
75       - name: Build on Rust ${{ matrix.toolchain }}
76         if: "! matrix.build-net-tokio"
77         run: |
78           cargo build --verbose  --color always -p lightning
79           cargo build --verbose  --color always -p lightning-invoice
80           cargo build --verbose  --color always -p lightning-persister
81       - name: Build on Rust ${{ matrix.toolchain }} with all Log-Limiting features
82         if: matrix.test-log-variants
83         run: |
84           cd lightning
85           for FEATURE in $(cat Cargo.toml | grep '^max_level_' | awk '{ print $1 }'); do
86             cargo build --verbose --color always --features $FEATURE
87           done
88       - name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features
89         if: "matrix.build-net-tokio && !matrix.coverage"
90         run: |
91           cd lightning-block-sync
92           cargo build --verbose --color always --features rest-client
93           cargo build --verbose --color always --features rpc-client
94           cargo build --verbose --color always --features rpc-client,rest-client
95           cargo build --verbose --color always --features rpc-client,rest-client,tokio
96       - name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
97         if: matrix.coverage
98         run: |
99           cd lightning-block-sync
100           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rest-client
101           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client
102           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client
103           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client,tokio
104       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio
105         if: "matrix.build-net-tokio && !matrix.coverage"
106         run: cargo test --verbose --color always
107       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
108         if: matrix.coverage
109         run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
110       - name: Test on no-std bullds Rust ${{ matrix.toolchain }}
111         if: "matrix.build-no-std && !matrix.coverage"
112         run: |
113           cd lightning
114           cargo test --verbose --color always --no-default-features --features no-std
115           # check if there is a conflict between no-std and the default std feature
116           cargo test --verbose --color always --features no-std
117           cd ..
118           cd lightning-invoice
119           cargo test --verbose --color always --no-default-features --features no-std
120           # check if there is a conflict between no-std and the default std feature
121           cargo test --verbose --color always --features no-std
122           cd ..
123       - name: Test on no-std builds Rust ${{ matrix.toolchain }} and full code-linking for coverage generation
124         if: "matrix.build-no-std && matrix.coverage"
125         run: |
126           cd lightning
127           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --no-default-features --features no-std
128           cd ..
129       - name: Test on Rust ${{ matrix.toolchain }}
130         if: "! matrix.build-net-tokio"
131         run: |
132           cargo test --verbose --color always  -p lightning
133           cargo test --verbose --color always  -p lightning-invoice
134           cargo build --verbose  --color always -p lightning-persister
135           cargo build --verbose  --color always -p lightning-background-processor
136       - name: Test C Bindings Modifications on Rust ${{ matrix.toolchain }}
137         if: "! matrix.build-net-tokio"
138         run: |
139           RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always  -p lightning
140           RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always  -p lightning-invoice
141           RUSTFLAGS="--cfg=c_bindings" cargo build --verbose  --color always -p lightning-persister
142           RUSTFLAGS="--cfg=c_bindings" cargo build --verbose  --color always -p lightning-background-processor
143       - name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features
144         if: "matrix.build-net-tokio && !matrix.coverage"
145         run: |
146           cd lightning-block-sync
147           cargo test --verbose --color always --features rest-client
148           cargo test --verbose --color always --features rpc-client
149           cargo test --verbose --color always --features rpc-client,rest-client
150           cargo test --verbose --color always --features rpc-client,rest-client,tokio
151       - name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
152         if: matrix.coverage
153         run: |
154           cd lightning-block-sync
155           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rest-client
156           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client
157           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client
158           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client,tokio
159       - name: Install deps for kcov
160         if: matrix.coverage
161         run: |
162           sudo apt-get update
163           sudo apt-get -y install binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev
164       - name: Install kcov
165         if: matrix.coverage
166         run: |
167           wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
168           tar xzf master.tar.gz
169           cd kcov-master && mkdir build && cd build
170           cmake ..
171           make
172           make install DESTDIR=../../kcov-build
173           cd ../.. && rm -rf kcov-master master.tar.gz
174       - name: Generate coverage report
175         if: matrix.coverage
176         run: |
177           for file in target/debug/deps/lightning*; do
178             [ -x "${file}" ] || continue;
179             mkdir -p "target/cov/$(basename $file)";
180             ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file";
181           done
182       - name: Upload coverage
183         if: matrix.coverage
184         uses: codecov/codecov-action@v2
185         with:
186           # Could you use this to fake the coverage report for your PR? Sure.
187           # Will anyone be impressed by your amazing coverage? No
188           # Maybe if codecov wasn't broken we wouldn't need to do this...
189           token: f421b687-4dc2-4387-ac3d-dc3b2528af57
190           fail_ci_if_error: true
191
192   benchmark:
193     runs-on: ubuntu-latest
194     env:
195       TOOLCHAIN: nightly
196     steps:
197       - name: Checkout source code
198         uses: actions/checkout@v2
199       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
200         uses: actions-rs/toolchain@v1
201         with:
202           toolchain: ${{ env.TOOLCHAIN }}
203           override: true
204           profile: minimal
205       - name: Cache routing graph snapshot
206         id: cache-graph
207         uses: actions/cache@v2
208         with:
209           path: lightning/net_graph-2021-05-31.bin
210           key: ldk-net_graph-v0.0.15-2021-05-31.bin
211       - name: Fetch routing graph snapshot
212         if: steps.cache-graph.outputs.cache-hit != 'true'
213         run: |
214           wget -O lightning/net_graph-2021-05-31.bin https://bitcoin.ninja/ldk-net_graph-v0.0.15-2021-05-31.bin
215           if [ "$(sha256sum lightning/net_graph-2021-05-31.bin | awk '{ print $1 }')" != "05a5361278f68ee2afd086cc04a1f927a63924be451f3221d380533acfacc303" ]; then
216             echo "Bad hash"
217             exit 1
218           fi
219       - name: Test with Network Graph on Rust ${{ matrix.toolchain }}
220         run: |
221           cd lightning
222           RUSTFLAGS="--cfg=require_route_graph_test" cargo test
223           RUSTFLAGS="--cfg=require_route_graph_test" cargo test --features hashbrown
224           cd ..
225       - name: Run benchmarks on Rust ${{ matrix.toolchain }}
226         run: |
227           cargo bench --features unstable
228
229   check_commits:
230     runs-on: ubuntu-latest
231     env:
232       # rustc 1.53 regressed and panics when building our (perfectly fine) docs.
233       # See https://github.com/rust-lang/rust/issues/84738
234       TOOLCHAIN: 1.52.1
235     steps:
236       - name: Checkout source code
237         uses: actions/checkout@v2
238         with:
239           fetch-depth: 0
240       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
241         uses: actions-rs/toolchain@v1
242         with:
243           toolchain: ${{ env.TOOLCHAIN }}
244           override: true
245           profile: minimal
246       - name: Fetch full tree and rebase on upstream
247         run: |
248           git remote add upstream https://github.com/rust-bitcoin/rust-lightning
249           git fetch upstream
250           export GIT_COMMITTER_EMAIL="rl-ci@example.com"
251           export GIT_COMMITTER_NAME="RL CI"
252           git rebase upstream/main
253       - name: For each commit, run cargo check (including in fuzz)
254         run: ci/check-each-commit.sh upstream/main
255
256   fuzz:
257     runs-on: ubuntu-latest
258     env:
259       TOOLCHAIN: stable
260     steps:
261       - name: Checkout source code
262         uses: actions/checkout@v2
263       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
264         uses: actions-rs/toolchain@v1
265         with:
266           toolchain: ${{ env.TOOLCHAIN }}
267           override: true
268           profile: minimal
269       - name: Install dependencies for honggfuzz
270         run: |
271           sudo apt-get update
272           sudo apt-get -y install build-essential binutils-dev libunwind-dev
273       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
274         run: cd fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose --color always
275       - name: Run fuzzers
276         run: cd fuzz && ./ci-fuzz.sh && cd ..
277       - name: Run lightning-invoice fuzzers
278         run: cd lightning-invoice/fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose && ./ci-fuzz.sh
279
280   linting:
281     runs-on: ubuntu-latest
282     env:
283       TOOLCHAIN: 1.47.0
284     steps:
285       - name: Checkout source code
286         uses: actions/checkout@v2
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: Install clippy
294         run: |
295           rustup component add clippy
296       - name: Run default clippy linting
297         run: |
298           cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else -Dclippy::try_err