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