bdf4e06f46268fcdbbadc5c4b5814d5be02f837f
[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, 1.63.0 ] # 1.63.0 is the MSRV for all crates.
22     runs-on: ${{ matrix.platform }}
23     steps:
24       - name: Checkout source code
25         uses: actions/checkout@v3
26       - name: Install Rust ${{ matrix.toolchain }} toolchain
27         run: |
28           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ matrix.toolchain }}
29           rustup override set ${{ matrix.toolchain }}
30       - name: Install no-std-check dependencies for ARM Embedded
31         if: "matrix.platform == 'ubuntu-latest'"
32         run: |
33           rustup target add thumbv7m-none-eabi
34           sudo apt-get -y install gcc-arm-none-eabi
35       - name: Check for unknown cfg tags
36         run: ci/check-cfg-flags.py
37       - name: shellcheck the CI script
38         if: "matrix.platform == 'ubuntu-latest'"
39         run: |
40           sudo apt-get -y install shellcheck
41           shellcheck ci/ci-tests.sh
42       - name: Set RUSTFLAGS to deny warnings
43         if: "matrix.toolchain == '1.63.0'"
44         run: echo "RUSTFLAGS=-D warnings" >> "$GITHUB_ENV"
45       - name: Run CI script
46         shell: bash # Default on Winblows is powershell
47         run: CI_MINIMIZE_DISK_USAGE=1 ./ci/ci-tests.sh
48
49   coverage:
50     strategy:
51       fail-fast: false
52     runs-on: ubuntu-latest
53     steps:
54       - name: Checkout source code
55         uses: actions/checkout@v3
56         with:
57           fetch-depth: 0
58       - name: Install Rust stable toolchain
59         run: |
60           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal
61       - name: Run tests with coverage generation
62         run: |
63           cargo install cargo-llvm-cov
64           export RUSTFLAGS="-Clink-dead-code -Coverflow-checks=off"
65           cargo llvm-cov --features rest-client,rpc-client,tokio,futures,serde --codecov --hide-instantiations --output-path=target/codecov.json
66           # Could you use this to fake the coverage report for your PR? Sure.
67           # Will anyone be impressed by your amazing coverage? No
68           # Maybe if codecov wasn't broken we wouldn't need to do this...
69           bash <(curl -s https://codecov.io/bash) -f target/codecov.json -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
70
71   benchmark:
72     runs-on: ubuntu-latest
73     env:
74       TOOLCHAIN: stable
75     steps:
76       - name: Checkout source code
77         uses: actions/checkout@v3
78       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
79         run: |
80           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
81           rustup override set ${{ env.TOOLCHAIN }}
82       - name: Cache routing graph snapshot
83         id: cache-graph
84         uses: actions/cache@v3
85         with:
86           path: lightning/net_graph-2023-12-10.bin
87           key: ldk-net_graph-v0.0.118-2023-12-10.bin
88       - name: Fetch routing graph snapshot
89         if: steps.cache-graph.outputs.cache-hit != 'true'
90         run: |
91           curl --verbose -L -o lightning/net_graph-2023-12-10.bin https://bitcoin.ninja/ldk-net_graph-v0.0.118-2023-12-10.bin
92           echo "Sha sum: $(sha256sum lightning/net_graph-2023-12-10.bin | awk '{ print $1 }')"
93           if [ "$(sha256sum lightning/net_graph-2023-12-10.bin | awk '{ print $1 }')" != "${EXPECTED_ROUTING_GRAPH_SNAPSHOT_SHASUM}" ]; then
94             echo "Bad hash"
95             exit 1
96           fi
97         env:
98           EXPECTED_ROUTING_GRAPH_SNAPSHOT_SHASUM: e94b38ef4b3ce683893bf6a3ee28d60cb37c73b059403ff77b7e7458157968c2
99       - name: Cache scorer snapshot
100         id: cache-scorer
101         uses: actions/cache@v3
102         with:
103           path: lightning/scorer-2023-12-10.bin
104           key: ldk-scorer-v0.0.118-2023-12-10.bin
105       - name: Fetch scorer snapshot
106         if: steps.cache-scorer.outputs.cache-hit != 'true'
107         run: |
108           curl --verbose -L -o lightning/scorer-2023-12-10.bin https://bitcoin.ninja/ldk-scorer-v0.0.118-2023-12-10.bin
109           echo "Sha sum: $(sha256sum lightning/scorer-2023-12-10.bin | awk '{ print $1 }')"
110           if [ "$(sha256sum lightning/scorer-2023-12-10.bin | awk '{ print $1 }')" != "${EXPECTED_SCORER_SNAPSHOT_SHASUM}" ]; then
111             echo "Bad hash"
112             exit 1
113           fi
114         env:
115           EXPECTED_SCORER_SNAPSHOT_SHASUM: 570a26bb28870fe1da7e392cdec9fb794718826b04c43ca053d71a8a9bb9be69
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           cd bench
135           RUSTFLAGS="--cfg=ldk_bench --cfg=require_route_graph_test" cargo bench
136       - name: Run benchmarks with hashbrown on Rust ${{ matrix.toolchain }}
137         run: |
138           cd bench
139           RUSTFLAGS="--cfg=ldk_bench --cfg=require_route_graph_test" cargo bench --features hashbrown
140
141   check_commits:
142     runs-on: ubuntu-latest
143     env:
144       TOOLCHAIN: stable
145     steps:
146       - name: Checkout source code
147         uses: actions/checkout@v3
148         with:
149           fetch-depth: 0
150       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
151         run: |
152           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
153           rustup override set ${{ env.TOOLCHAIN }}
154       - name: Fetch full tree and rebase on upstream
155         run: |
156           git remote add upstream https://github.com/lightningdevkit/rust-lightning
157           git fetch upstream
158           export GIT_COMMITTER_EMAIL="rl-ci@example.com"
159           export GIT_COMMITTER_NAME="RL CI"
160           git rebase upstream/main
161       - name: For each commit, run cargo check (including in fuzz)
162         run: ci/check-each-commit.sh upstream/main
163
164   check_release:
165     runs-on: ubuntu-latest
166     env:
167       TOOLCHAIN: stable
168     steps:
169       - name: Checkout source code
170         uses: actions/checkout@v3
171         with:
172           fetch-depth: 0
173       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
174         run: |
175           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
176           rustup override set ${{ env.TOOLCHAIN }}
177       - name: Run cargo check for release build.
178         run: |
179           cargo check --release
180           cargo check --no-default-features --features=no-std --release
181           cargo check --no-default-features --features=futures,std --release
182           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,std --release
188           cargo doc --release
189         env:
190           RUSTFLAGS: '--cfg=taproot'
191           RUSTDOCFLAGS: '--cfg=taproot'
192
193   fuzz:
194     runs-on: ubuntu-latest
195     env:
196       TOOLCHAIN: 1.58
197     steps:
198       - name: Checkout source code
199         uses: actions/checkout@v3
200       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
201         run: |
202           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
203           rustup override set ${{ env.TOOLCHAIN }}
204       - name: Install dependencies for honggfuzz
205         run: |
206           sudo apt-get update
207           sudo apt-get -y install build-essential binutils-dev libunwind-dev
208       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
209         run: cd fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose --color always
210       - name: Run fuzzers
211         run: cd fuzz && ./ci-fuzz.sh && cd ..
212       - name: Run lightning-invoice fuzzers
213         run: cd lightning-invoice/fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose && ./ci-fuzz.sh
214
215   linting:
216     runs-on: ubuntu-latest
217     env:
218       TOOLCHAIN: stable
219     steps:
220       - name: Checkout source code
221         uses: actions/checkout@v3
222       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
223         run: |
224           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
225           rustup override set ${{ env.TOOLCHAIN }}
226       - name: Install clippy
227         run: |
228           rustup component add clippy
229       - name: Run default clippy linting
230         run: |
231           cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else -Dclippy::try_err