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