Cancel in-progress jobs on updated push
[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           RUSTC_BOOTSTRAP=1 cargo bench --features _bench_unstable
145
146   check_commits:
147     runs-on: ubuntu-latest
148     env:
149       TOOLCHAIN: 1.57.0
150     steps:
151       - name: Checkout source code
152         uses: actions/checkout@v3
153         with:
154           fetch-depth: 0
155       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
156         uses: actions-rs/toolchain@v1
157         with:
158           toolchain: ${{ env.TOOLCHAIN }}
159           override: true
160           profile: minimal
161       - name: Fetch full tree and rebase on upstream
162         run: |
163           git remote add upstream https://github.com/lightningdevkit/rust-lightning
164           git fetch upstream
165           export GIT_COMMITTER_EMAIL="rl-ci@example.com"
166           export GIT_COMMITTER_NAME="RL CI"
167           git rebase upstream/main
168       - name: For each commit, run cargo check (including in fuzz)
169         run: ci/check-each-commit.sh upstream/main
170
171   check_release:
172     runs-on: ubuntu-latest
173     env:
174       TOOLCHAIN: stable
175     steps:
176       - name: Checkout source code
177         uses: actions/checkout@v3
178         with:
179           fetch-depth: 0
180       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
181         uses: actions-rs/toolchain@v1
182         with:
183           toolchain: ${{ env.TOOLCHAIN }}
184           override: true
185           profile: minimal
186       - name: Run cargo check for release build.
187         run: |
188           cargo check --release
189           cargo check --no-default-features --features=no-std --release
190           cargo check --no-default-features --features=futures --release
191           cargo doc --release
192           RUSTDOCFLAGS="--cfg=anchors" cargo doc --release
193       - name: Run cargo check for Taproot build.
194         run: |
195           cargo check --release
196           cargo check --no-default-features --features=no-std --release
197           cargo check --no-default-features --features=futures --release
198           cargo doc --release
199         env:
200           RUSTFLAGS: '--cfg=anchors --cfg=taproot'
201           RUSTDOCFLAGS: '--cfg=anchors --cfg=taproot'
202
203   fuzz:
204     runs-on: ubuntu-latest
205     env:
206       TOOLCHAIN: stable
207     steps:
208       - name: Checkout source code
209         uses: actions/checkout@v3
210       - name: Install Rust 1.58 toolchain
211         uses: actions-rs/toolchain@v1
212         with:
213           toolchain: 1.58
214           override: true
215           profile: minimal
216       - name: Install dependencies for honggfuzz
217         run: |
218           sudo apt-get update
219           sudo apt-get -y install build-essential binutils-dev libunwind-dev
220       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
221         run: cd fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose --color always
222       - name: Run fuzzers
223         run: cd fuzz && ./ci-fuzz.sh && cd ..
224       - name: Run lightning-invoice fuzzers
225         run: cd lightning-invoice/fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose && ./ci-fuzz.sh
226
227   linting:
228     runs-on: ubuntu-latest
229     env:
230       TOOLCHAIN: stable
231     steps:
232       - name: Checkout source code
233         uses: actions/checkout@v3
234       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
235         uses: actions-rs/toolchain@v1
236         with:
237           toolchain: ${{ env.TOOLCHAIN }}
238           override: true
239           profile: minimal
240       - name: Install clippy
241         run: |
242           rustup component add clippy
243       - name: Run default clippy linting
244         run: |
245           cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else -Dclippy::try_err