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