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