Move coverage generation to llvm-cov in the hopes its more stable
[rust-lightning] / .github / workflows / build.yml
1 name: Continuous Integration Checks
2
3 on:
4   push:
5     branches-ignore:
6       - master
7   pull_request:
8     branches-ignore:
9       - master
10
11 concurrency:
12   group: ${{ github.workflow }}-${{ github.ref }}
13   cancel-in-progress: true
14
15 jobs:
16   build:
17     strategy:
18       fail-fast: false
19       matrix:
20         platform: [ ubuntu-latest, windows-latest, macos-latest ]
21         toolchain: [ stable, beta ]
22         include:
23           - toolchain: stable
24             platform: ubuntu-latest
25           # 1.48.0 is the MSRV for all crates except lightning-transaction-sync and Win/Mac
26           - toolchain: 1.48.0
27             platform: ubuntu-latest
28           # Windows requires 1.49.0 because that's the MSRV for supported Tokio
29           - toolchain: 1.49.0
30             platform: windows-latest
31           # MacOS-latest requires 1.54.0 because that's what's required for linking to work properly
32           - toolchain: 1.54.0
33             platform: macos-latest
34     runs-on: ${{ matrix.platform }}
35     steps:
36       - name: Checkout source code
37         uses: actions/checkout@v3
38       - name: Install Rust ${{ matrix.toolchain }} toolchain
39         run: |
40           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ matrix.toolchain }}
41           rustup override set ${{ matrix.toolchain }}
42       - name: Install no-std-check dependencies for ARM Embedded
43         if: "matrix.platform == 'ubuntu-latest'"
44         run: |
45           rustup target add thumbv7m-none-eabi
46           sudo apt-get -y install gcc-arm-none-eabi
47       - name: shellcheck the CI script
48         if: "matrix.platform == 'ubuntu-latest'"
49         run: |
50           sudo apt-get -y install shellcheck
51           shellcheck ci/ci-tests.sh
52       - name: Run CI script
53         shell: bash # Default on Winblows is powershell
54         run: ./ci/ci-tests.sh
55
56   coverage:
57     strategy:
58       fail-fast: false
59     runs-on: ubuntu-latest
60     steps:
61       - name: Checkout source code
62         uses: actions/checkout@v3
63         with:
64           fetch-depth: 0
65       - name: Install Rust stable toolchain
66         run: |
67           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal
68       - name: Run tests with coverage generation
69         run: |
70           cargo install cargo-llvm-cov
71           export RUSTFLAGS="-Clink-dead-code -Coverflow-checks=off"
72           cargo llvm-cov --features rest-client,rpc-client,tokio,futures,serde --codecov --hide-instantiations --output-path=target/codecov.json
73           # Could you use this to fake the coverage report for your PR? Sure.
74           # Will anyone be impressed by your amazing coverage? No
75           # Maybe if codecov wasn't broken we wouldn't need to do this...
76           bash <(curl -s https://codecov.io/bash) -f target/codecov.json -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
77
78   benchmark:
79     runs-on: ubuntu-latest
80     env:
81       TOOLCHAIN: stable
82     steps:
83       - name: Checkout source code
84         uses: actions/checkout@v3
85       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
86         run: |
87           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
88           rustup override set ${{ env.TOOLCHAIN }}
89       - name: Cache routing graph snapshot
90         id: cache-graph
91         uses: actions/cache@v3
92         with:
93           path: lightning/net_graph-2023-01-18.bin
94           key: ldk-net_graph-v0.0.113-2023-01-18.bin
95       - name: Fetch routing graph snapshot
96         if: steps.cache-graph.outputs.cache-hit != 'true'
97         run: |
98           curl --verbose -L -o lightning/net_graph-2023-01-18.bin https://bitcoin.ninja/ldk-net_graph-v0.0.113-2023-01-18.bin
99           echo "Sha sum: $(sha256sum lightning/net_graph-2023-01-18.bin | awk '{ print $1 }')"
100           if [ "$(sha256sum lightning/net_graph-2023-01-18.bin | awk '{ print $1 }')" != "${EXPECTED_ROUTING_GRAPH_SNAPSHOT_SHASUM}" ]; then
101             echo "Bad hash"
102             exit 1
103           fi
104         env:
105           EXPECTED_ROUTING_GRAPH_SNAPSHOT_SHASUM: da6066f2bddcddbe7d8a6debbd53545697137b310bbb8c4911bc8c81fc5ff48c
106       - name: Fetch rapid graph sync reference input
107         run: |
108           curl --verbose -L -o lightning-rapid-gossip-sync/res/full_graph.lngossip https://bitcoin.ninja/ldk-compressed_graph-285cb27df79-2022-07-21.bin
109           echo "Sha sum: $(sha256sum lightning-rapid-gossip-sync/res/full_graph.lngossip | awk '{ print $1 }')"
110           if [ "$(sha256sum lightning-rapid-gossip-sync/res/full_graph.lngossip | awk '{ print $1 }')" != "${EXPECTED_RAPID_GOSSIP_SHASUM}" ]; then
111             echo "Bad hash"
112             exit 1
113           fi
114         env:
115           EXPECTED_RAPID_GOSSIP_SHASUM: e0f5d11641c11896d7af3a2246d3d6c3f1720b7d2d17aab321ecce82e6b7deb8
116       - name: Test with Network Graph on Rust ${{ matrix.toolchain }}
117         run: |
118           cd lightning
119           RUSTFLAGS="--cfg=require_route_graph_test" cargo test
120           RUSTFLAGS="--cfg=require_route_graph_test" cargo test --features hashbrown
121           cd ..
122       - name: Run benchmarks on Rust ${{ matrix.toolchain }}
123         run: |
124           cd bench
125           RUSTFLAGS="--cfg=ldk_bench --cfg=require_route_graph_test" cargo bench
126       - name: Run benchmarks with hashbrown on Rust ${{ matrix.toolchain }}
127         run: |
128           cd bench
129           RUSTFLAGS="--cfg=ldk_bench --cfg=require_route_graph_test" cargo bench --features hashbrown
130
131   check_commits:
132     runs-on: ubuntu-latest
133     env:
134       TOOLCHAIN: stable
135     steps:
136       - name: Checkout source code
137         uses: actions/checkout@v3
138         with:
139           fetch-depth: 0
140       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
141         run: |
142           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
143           rustup override set ${{ env.TOOLCHAIN }}
144       - name: Fetch full tree and rebase on upstream
145         run: |
146           git remote add upstream https://github.com/lightningdevkit/rust-lightning
147           git fetch upstream
148           export GIT_COMMITTER_EMAIL="rl-ci@example.com"
149           export GIT_COMMITTER_NAME="RL CI"
150           git rebase upstream/main
151       - name: For each commit, run cargo check (including in fuzz)
152         run: ci/check-each-commit.sh upstream/main
153
154   check_release:
155     runs-on: ubuntu-latest
156     env:
157       TOOLCHAIN: stable
158     steps:
159       - name: Checkout source code
160         uses: actions/checkout@v3
161         with:
162           fetch-depth: 0
163       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
164         run: |
165           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
166           rustup override set ${{ env.TOOLCHAIN }}
167       - name: Run cargo check for release build.
168         run: |
169           cargo check --release
170           cargo check --no-default-features --features=no-std --release
171           cargo check --no-default-features --features=futures --release
172           cargo doc --release
173       - name: Run cargo check for Taproot build.
174         run: |
175           cargo check --release
176           cargo check --no-default-features --features=no-std --release
177           cargo check --no-default-features --features=futures --release
178           cargo doc --release
179         env:
180           RUSTFLAGS: '--cfg=taproot'
181           RUSTDOCFLAGS: '--cfg=taproot'
182
183   fuzz:
184     runs-on: ubuntu-latest
185     env:
186       TOOLCHAIN: 1.58
187     steps:
188       - name: Checkout source code
189         uses: actions/checkout@v3
190       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
191         run: |
192           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
193           rustup override set ${{ env.TOOLCHAIN }}
194       - name: Install dependencies for honggfuzz
195         run: |
196           sudo apt-get update
197           sudo apt-get -y install build-essential binutils-dev libunwind-dev
198       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
199         run: cd fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose --color always
200       - name: Run fuzzers
201         run: cd fuzz && ./ci-fuzz.sh && cd ..
202       - name: Run lightning-invoice fuzzers
203         run: cd lightning-invoice/fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose && ./ci-fuzz.sh
204
205   linting:
206     runs-on: ubuntu-latest
207     env:
208       TOOLCHAIN: stable
209     steps:
210       - name: Checkout source code
211         uses: actions/checkout@v3
212       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
213         run: |
214           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
215           rustup override set ${{ env.TOOLCHAIN }}
216       - name: Install clippy
217         run: |
218           rustup component add clippy
219       - name: Run default clippy linting
220         run: |
221           cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else -Dclippy::try_err