Ignore workflow runs on master branch
[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 jobs:
12   build:
13     strategy:
14       fail-fast: false
15       matrix:
16         platform: [ ubuntu-latest, windows-latest, macos-latest ]
17         toolchain: [ stable, beta ]
18         include:
19           - toolchain: stable
20             platform: ubuntu-latest
21             coverage: true
22           # 1.48.0 is the MSRV for all crates except lightning-transaction-sync and Win/Mac
23           - toolchain: 1.48.0
24             platform: ubuntu-latest
25           # Windows requires 1.49.0 because that's the MSRV for supported Tokio
26           - toolchain: 1.49.0
27             platform: windows-latest
28           # MacOS-latest requires 1.54.0 because that's what's required for linking to work properly
29           - toolchain: 1.54.0
30             platform: macos-latest
31     runs-on: ${{ matrix.platform }}
32     steps:
33       - name: Checkout source code
34         uses: actions/checkout@v3
35       - name: Install Rust ${{ matrix.toolchain }} toolchain
36         uses: actions-rs/toolchain@v1
37         with:
38           toolchain: ${{ matrix.toolchain }}
39           override: true
40           profile: minimal
41       - name: Install no-std-check dependencies for ARM Embedded
42         if: "matrix.platform == 'ubuntu-latest'"
43         run: |
44           rustup target add thumbv7m-none-eabi
45           sudo apt-get -y install gcc-arm-none-eabi
46       - name: shellcheck the CI script
47         if: "matrix.platform == 'ubuntu-latest'"
48         run: |
49           sudo apt-get -y install shellcheck
50           shellcheck ci/ci-tests.sh
51       - name: Run CI script with coverage generation
52         if: matrix.coverage
53         shell: bash # Default on Winblows is powershell
54         run: LDK_COVERAGE_BUILD=true ./ci/ci-tests.sh
55       - name: Run CI script
56         if: "!matrix.coverage"
57         shell: bash # Default on Winblows is powershell
58         run: ./ci/ci-tests.sh
59       - name: Install deps for kcov
60         if: matrix.coverage
61         run: |
62           sudo apt-get update
63           sudo apt-get -y install binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev
64       - name: Install kcov
65         if: matrix.coverage
66         run: |
67           wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
68           tar xzf master.tar.gz
69           cd kcov-master && mkdir build && cd build
70           cmake ..
71           make
72           make install DESTDIR=../../kcov-build
73           cd ../.. && rm -rf kcov-master master.tar.gz
74       - name: Generate coverage report
75         if: matrix.coverage
76         run: |
77           for file in target/debug/deps/lightning*; do
78             [ -x "${file}" ] || continue;
79             mkdir -p "target/cov/$(basename $file)";
80             ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file";
81           done
82       - name: Upload coverage
83         if: matrix.coverage
84         uses: codecov/codecov-action@v3
85         with:
86           # Could you use this to fake the coverage report for your PR? Sure.
87           # Will anyone be impressed by your amazing coverage? No
88           # Maybe if codecov wasn't broken we wouldn't need to do this...
89           token: f421b687-4dc2-4387-ac3d-dc3b2528af57
90           fail_ci_if_error: true
91
92   benchmark:
93     runs-on: ubuntu-latest
94     env:
95       TOOLCHAIN: stable
96     steps:
97       - name: Checkout source code
98         uses: actions/checkout@v3
99       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
100         uses: actions-rs/toolchain@v1
101         with:
102           toolchain: ${{ env.TOOLCHAIN }}
103           override: true
104           profile: minimal
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           RUSTC_BOOTSTRAP=1 cargo bench --features _bench_unstable
141
142   check_commits:
143     runs-on: ubuntu-latest
144     env:
145       TOOLCHAIN: 1.57.0
146     steps:
147       - name: Checkout source code
148         uses: actions/checkout@v3
149         with:
150           fetch-depth: 0
151       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
152         uses: actions-rs/toolchain@v1
153         with:
154           toolchain: ${{ env.TOOLCHAIN }}
155           override: true
156           profile: minimal
157       - name: Fetch full tree and rebase on upstream
158         run: |
159           git remote add upstream https://github.com/lightningdevkit/rust-lightning
160           git fetch upstream
161           export GIT_COMMITTER_EMAIL="rl-ci@example.com"
162           export GIT_COMMITTER_NAME="RL CI"
163           git rebase upstream/main
164       - name: For each commit, run cargo check (including in fuzz)
165         run: ci/check-each-commit.sh upstream/main
166
167   check_release:
168     runs-on: ubuntu-latest
169     env:
170       TOOLCHAIN: stable
171     steps:
172       - name: Checkout source code
173         uses: actions/checkout@v3
174         with:
175           fetch-depth: 0
176       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
177         uses: actions-rs/toolchain@v1
178         with:
179           toolchain: ${{ env.TOOLCHAIN }}
180           override: true
181           profile: minimal
182       - name: Run cargo check for release build.
183         run: |
184           cargo check --release
185           cargo check --no-default-features --features=no-std --release
186           cargo check --no-default-features --features=futures --release
187           cargo doc --release
188           RUSTDOCFLAGS="--cfg=anchors" 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=anchors --cfg=taproot'
197           RUSTDOCFLAGS: '--cfg=anchors --cfg=taproot'
198
199   fuzz:
200     runs-on: ubuntu-latest
201     env:
202       TOOLCHAIN: stable
203     steps:
204       - name: Checkout source code
205         uses: actions/checkout@v3
206       - name: Install Rust 1.58 toolchain
207         uses: actions-rs/toolchain@v1
208         with:
209           toolchain: 1.58
210           override: true
211           profile: minimal
212       - name: Install dependencies for honggfuzz
213         run: |
214           sudo apt-get update
215           sudo apt-get -y install build-essential binutils-dev libunwind-dev
216       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
217         run: cd fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose --color always
218       - name: Run fuzzers
219         run: cd fuzz && ./ci-fuzz.sh && cd ..
220       - name: Run lightning-invoice fuzzers
221         run: cd lightning-invoice/fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose && ./ci-fuzz.sh
222
223   linting:
224     runs-on: ubuntu-latest
225     env:
226       TOOLCHAIN: stable
227     steps:
228       - name: Checkout source code
229         uses: actions/checkout@v3
230       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
231         uses: actions-rs/toolchain@v1
232         with:
233           toolchain: ${{ env.TOOLCHAIN }}
234           override: true
235           profile: minimal
236       - name: Install clippy
237         run: |
238           rustup component add clippy
239       - name: Run default clippy linting
240         run: |
241           cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else -Dclippy::try_err