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