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