Merge pull request #1223 from lightning-signer/2021-12-invoice-nostd
[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         shell: bash # Default on Winblows is powershell
113         run: |
114           cd lightning
115           cargo test --verbose --color always --no-default-features --features no-std
116           # check if there is a conflict between no-std and the default std feature
117           cargo test --verbose --color always --features no-std
118           # check if there is a conflict between no-std and the c_bindings cfg
119           RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always --no-default-features --features=no-std
120           cd ..
121           cd lightning-invoice
122           cargo test --verbose --color always --no-default-features --features no-std
123           # check if there is a conflict between no-std and the default std feature
124           cargo test --verbose --color always --features no-std
125           cd ..
126       - name: Test on no-std builds Rust ${{ matrix.toolchain }} and full code-linking for coverage generation
127         if: "matrix.build-no-std && matrix.coverage"
128         run: |
129           cd lightning
130           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --no-default-features --features no-std
131           cd ..
132       - name: Test on Rust ${{ matrix.toolchain }}
133         if: "! matrix.build-net-tokio"
134         run: |
135           cargo test --verbose --color always  -p lightning
136           cargo test --verbose --color always  -p lightning-invoice
137           cargo build --verbose  --color always -p lightning-persister
138           cargo build --verbose  --color always -p lightning-background-processor
139       - name: Test C Bindings Modifications on Rust ${{ matrix.toolchain }}
140         if: "! matrix.build-net-tokio"
141         run: |
142           RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always  -p lightning
143           RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always  -p lightning-invoice
144           RUSTFLAGS="--cfg=c_bindings" cargo build --verbose  --color always -p lightning-persister
145           RUSTFLAGS="--cfg=c_bindings" cargo build --verbose  --color always -p lightning-background-processor
146       - name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features
147         if: "matrix.build-net-tokio && !matrix.coverage"
148         run: |
149           cd lightning-block-sync
150           cargo test --verbose --color always --features rest-client
151           cargo test --verbose --color always --features rpc-client
152           cargo test --verbose --color always --features rpc-client,rest-client
153           cargo test --verbose --color always --features rpc-client,rest-client,tokio
154       - name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
155         if: matrix.coverage
156         run: |
157           cd lightning-block-sync
158           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rest-client
159           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client
160           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client
161           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client,tokio
162       - name: Install deps for kcov
163         if: matrix.coverage
164         run: |
165           sudo apt-get update
166           sudo apt-get -y install binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev
167       - name: Install kcov
168         if: matrix.coverage
169         run: |
170           wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
171           tar xzf master.tar.gz
172           cd kcov-master && mkdir build && cd build
173           cmake ..
174           make
175           make install DESTDIR=../../kcov-build
176           cd ../.. && rm -rf kcov-master master.tar.gz
177       - name: Generate coverage report
178         if: matrix.coverage
179         run: |
180           for file in target/debug/deps/lightning*; do
181             [ -x "${file}" ] || continue;
182             mkdir -p "target/cov/$(basename $file)";
183             ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file";
184           done
185       - name: Upload coverage
186         if: matrix.coverage
187         uses: codecov/codecov-action@v2
188         with:
189           # Could you use this to fake the coverage report for your PR? Sure.
190           # Will anyone be impressed by your amazing coverage? No
191           # Maybe if codecov wasn't broken we wouldn't need to do this...
192           token: f421b687-4dc2-4387-ac3d-dc3b2528af57
193           fail_ci_if_error: true
194
195   benchmark:
196     runs-on: ubuntu-latest
197     env:
198       TOOLCHAIN: nightly
199     steps:
200       - name: Checkout source code
201         uses: actions/checkout@v2
202       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
203         uses: actions-rs/toolchain@v1
204         with:
205           toolchain: ${{ env.TOOLCHAIN }}
206           override: true
207           profile: minimal
208       - name: Cache routing graph snapshot
209         id: cache-graph
210         uses: actions/cache@v2
211         with:
212           path: lightning/net_graph-2021-05-31.bin
213           key: ldk-net_graph-v0.0.15-2021-05-31.bin
214       - name: Fetch routing graph snapshot
215         if: steps.cache-graph.outputs.cache-hit != 'true'
216         run: |
217           wget -O lightning/net_graph-2021-05-31.bin https://bitcoin.ninja/ldk-net_graph-v0.0.15-2021-05-31.bin
218           if [ "$(sha256sum lightning/net_graph-2021-05-31.bin | awk '{ print $1 }')" != "05a5361278f68ee2afd086cc04a1f927a63924be451f3221d380533acfacc303" ]; then
219             echo "Bad hash"
220             exit 1
221           fi
222       - name: Test with Network Graph on Rust ${{ matrix.toolchain }}
223         run: |
224           cd lightning
225           RUSTFLAGS="--cfg=require_route_graph_test" cargo test
226           RUSTFLAGS="--cfg=require_route_graph_test" cargo test --features hashbrown
227           cd ..
228       - name: Run benchmarks on Rust ${{ matrix.toolchain }}
229         run: |
230           cargo bench --features unstable
231
232   check_commits:
233     runs-on: ubuntu-latest
234     env:
235       # rustc 1.53 regressed and panics when building our (perfectly fine) docs.
236       # See https://github.com/rust-lang/rust/issues/84738
237       TOOLCHAIN: 1.52.1
238     steps:
239       - name: Checkout source code
240         uses: actions/checkout@v2
241         with:
242           fetch-depth: 0
243       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
244         uses: actions-rs/toolchain@v1
245         with:
246           toolchain: ${{ env.TOOLCHAIN }}
247           override: true
248           profile: minimal
249       - name: Fetch full tree and rebase on upstream
250         run: |
251           git remote add upstream https://github.com/lightningdevkit/rust-lightning
252           git fetch upstream
253           export GIT_COMMITTER_EMAIL="rl-ci@example.com"
254           export GIT_COMMITTER_NAME="RL CI"
255           git rebase upstream/main
256       - name: For each commit, run cargo check (including in fuzz)
257         run: ci/check-each-commit.sh upstream/main
258
259   fuzz:
260     runs-on: ubuntu-latest
261     env:
262       TOOLCHAIN: stable
263     steps:
264       - name: Checkout source code
265         uses: actions/checkout@v2
266       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
267         uses: actions-rs/toolchain@v1
268         with:
269           toolchain: ${{ env.TOOLCHAIN }}
270           override: true
271           profile: minimal
272       - name: Install dependencies for honggfuzz
273         run: |
274           sudo apt-get update
275           sudo apt-get -y install build-essential binutils-dev libunwind-dev
276       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
277         run: cd fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose --color always
278       - name: Run fuzzers
279         run: cd fuzz && ./ci-fuzz.sh && cd ..
280       - name: Run lightning-invoice fuzzers
281         run: cd lightning-invoice/fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose && ./ci-fuzz.sh
282
283   linting:
284     runs-on: ubuntu-latest
285     env:
286       TOOLCHAIN: 1.47.0
287     steps:
288       - name: Checkout source code
289         uses: actions/checkout@v2
290       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
291         uses: actions-rs/toolchain@v1
292         with:
293           toolchain: ${{ env.TOOLCHAIN }}
294           override: true
295           profile: minimal
296       - name: Install clippy
297         run: |
298           rustup component add clippy
299       - name: Run default clippy linting
300         run: |
301           cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else -Dclippy::try_err