Merge pull request #2782 from TheBlueMatt/2023-12-check-cfg-tags
[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: Run CI script
43         shell: bash # Default on Winblows is powershell
44         run: CI_MINIMIZE_DISK_USAGE=1 ./ci/ci-tests.sh
45
46   coverage:
47     strategy:
48       fail-fast: false
49     runs-on: ubuntu-latest
50     steps:
51       - name: Checkout source code
52         uses: actions/checkout@v3
53         with:
54           fetch-depth: 0
55       - name: Install Rust stable toolchain
56         run: |
57           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal
58       - name: Run tests with coverage generation
59         run: |
60           cargo install cargo-llvm-cov
61           export RUSTFLAGS="-Clink-dead-code -Coverflow-checks=off"
62           cargo llvm-cov --features rest-client,rpc-client,tokio,futures,serde --codecov --hide-instantiations --output-path=target/codecov.json
63           # Could you use this to fake the coverage report for your PR? Sure.
64           # Will anyone be impressed by your amazing coverage? No
65           # Maybe if codecov wasn't broken we wouldn't need to do this...
66           bash <(curl -s https://codecov.io/bash) -f target/codecov.json -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
67
68   benchmark:
69     runs-on: ubuntu-latest
70     env:
71       TOOLCHAIN: stable
72     steps:
73       - name: Checkout source code
74         uses: actions/checkout@v3
75       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
76         run: |
77           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
78           rustup override set ${{ env.TOOLCHAIN }}
79       - name: Cache routing graph snapshot
80         id: cache-graph
81         uses: actions/cache@v3
82         with:
83           path: lightning/net_graph-2023-01-18.bin
84           key: ldk-net_graph-v0.0.113-2023-01-18.bin
85       - name: Fetch routing graph snapshot
86         if: steps.cache-graph.outputs.cache-hit != 'true'
87         run: |
88           curl --verbose -L -o lightning/net_graph-2023-01-18.bin https://bitcoin.ninja/ldk-net_graph-v0.0.113-2023-01-18.bin
89           echo "Sha sum: $(sha256sum lightning/net_graph-2023-01-18.bin | awk '{ print $1 }')"
90           if [ "$(sha256sum lightning/net_graph-2023-01-18.bin | awk '{ print $1 }')" != "${EXPECTED_ROUTING_GRAPH_SNAPSHOT_SHASUM}" ]; then
91             echo "Bad hash"
92             exit 1
93           fi
94         env:
95           EXPECTED_ROUTING_GRAPH_SNAPSHOT_SHASUM: da6066f2bddcddbe7d8a6debbd53545697137b310bbb8c4911bc8c81fc5ff48c
96       - name: Fetch rapid graph sync reference input
97         run: |
98           curl --verbose -L -o lightning-rapid-gossip-sync/res/full_graph.lngossip https://bitcoin.ninja/ldk-compressed_graph-285cb27df79-2022-07-21.bin
99           echo "Sha sum: $(sha256sum lightning-rapid-gossip-sync/res/full_graph.lngossip | awk '{ print $1 }')"
100           if [ "$(sha256sum lightning-rapid-gossip-sync/res/full_graph.lngossip | awk '{ print $1 }')" != "${EXPECTED_RAPID_GOSSIP_SHASUM}" ]; then
101             echo "Bad hash"
102             exit 1
103           fi
104         env:
105           EXPECTED_RAPID_GOSSIP_SHASUM: e0f5d11641c11896d7af3a2246d3d6c3f1720b7d2d17aab321ecce82e6b7deb8
106       - name: Test with Network Graph on Rust ${{ matrix.toolchain }}
107         run: |
108           cd lightning
109           RUSTFLAGS="--cfg=require_route_graph_test" cargo test
110           RUSTFLAGS="--cfg=require_route_graph_test" cargo test --features hashbrown
111           cd ..
112       - name: Run benchmarks on Rust ${{ matrix.toolchain }}
113         run: |
114           cd bench
115           RUSTFLAGS="--cfg=ldk_bench --cfg=require_route_graph_test" cargo bench
116       - name: Run benchmarks with hashbrown on Rust ${{ matrix.toolchain }}
117         run: |
118           cd bench
119           RUSTFLAGS="--cfg=ldk_bench --cfg=require_route_graph_test" cargo bench --features hashbrown
120
121   check_commits:
122     runs-on: ubuntu-latest
123     env:
124       TOOLCHAIN: stable
125     steps:
126       - name: Checkout source code
127         uses: actions/checkout@v3
128         with:
129           fetch-depth: 0
130       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
131         run: |
132           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
133           rustup override set ${{ env.TOOLCHAIN }}
134       - name: Fetch full tree and rebase on upstream
135         run: |
136           git remote add upstream https://github.com/lightningdevkit/rust-lightning
137           git fetch upstream
138           export GIT_COMMITTER_EMAIL="rl-ci@example.com"
139           export GIT_COMMITTER_NAME="RL CI"
140           git rebase upstream/main
141       - name: For each commit, run cargo check (including in fuzz)
142         run: ci/check-each-commit.sh upstream/main
143
144   check_release:
145     runs-on: ubuntu-latest
146     env:
147       TOOLCHAIN: stable
148     steps:
149       - name: Checkout source code
150         uses: actions/checkout@v3
151         with:
152           fetch-depth: 0
153       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
154         run: |
155           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
156           rustup override set ${{ env.TOOLCHAIN }}
157       - name: Run cargo check for release build.
158         run: |
159           cargo check --release
160           cargo check --no-default-features --features=no-std --release
161           cargo check --no-default-features --features=futures,std --release
162           cargo doc --release
163       - name: Run cargo check for Taproot build.
164         run: |
165           cargo check --release
166           cargo check --no-default-features --features=no-std --release
167           cargo check --no-default-features --features=futures,std --release
168           cargo doc --release
169         env:
170           RUSTFLAGS: '--cfg=taproot'
171           RUSTDOCFLAGS: '--cfg=taproot'
172
173   fuzz:
174     runs-on: ubuntu-latest
175     env:
176       TOOLCHAIN: 1.58
177     steps:
178       - name: Checkout source code
179         uses: actions/checkout@v3
180       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
181         run: |
182           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
183           rustup override set ${{ env.TOOLCHAIN }}
184       - name: Install dependencies for honggfuzz
185         run: |
186           sudo apt-get update
187           sudo apt-get -y install build-essential binutils-dev libunwind-dev
188       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
189         run: cd fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose --color always
190       - name: Run fuzzers
191         run: cd fuzz && ./ci-fuzz.sh && cd ..
192       - name: Run lightning-invoice fuzzers
193         run: cd lightning-invoice/fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose && ./ci-fuzz.sh
194
195   linting:
196     runs-on: ubuntu-latest
197     env:
198       TOOLCHAIN: stable
199     steps:
200       - name: Checkout source code
201         uses: actions/checkout@v3
202       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
203         run: |
204           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
205           rustup override set ${{ env.TOOLCHAIN }}
206       - name: Install clippy
207         run: |
208           rustup component add clippy
209       - name: Run default clippy linting
210         run: |
211           cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else -Dclippy::try_err