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