e4fe497fa3b6d3d8307d6392f6c2847751bdd6d2
[rust-lightning] / .github / workflows / build.yml
1 name: Continuous Integration Checks
2
3 on: [push, pull_request]
4
5 jobs:
6   build:
7     strategy:
8       matrix:
9         platform: [ ubuntu-latest ]
10         toolchain: [ stable,
11                      beta,
12                      # 1.30.0 is MSRV for Rust-Lightning
13                      1.30.0,
14                      # 1.34.2 is Debian stable
15                      1.34.2,
16                      # 1.45.2 is MSRV for lightning-net-tokio, lightning-block-sync, and coverage generation
17                      1.45.2]
18         include:
19           - toolchain: stable
20             build-net-tokio: true
21           - toolchain: stable
22             platform: macos-latest
23             build-net-tokio: true
24           - toolchain: stable
25             platform: windows-latest
26             build-net-tokio: true
27           - toolchain: beta
28             build-net-tokio: true
29           - toolchain: 1.45.2
30             build-net-tokio: true
31             coverage: true
32     runs-on: ${{ matrix.platform }}
33     steps:
34       - name: Checkout source code
35         uses: actions/checkout@v2
36       - name: Install Rust ${{ matrix.toolchain }} toolchain
37         uses: actions-rs/toolchain@v1
38         with:
39           toolchain: ${{ matrix.toolchain }}
40           override: true
41           profile: minimal
42       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio
43         if: "matrix.build-net-tokio && !matrix.coverage"
44         run: cargo build --verbose --color always
45       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
46         if: matrix.coverage
47         run: RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always
48       - name: Build on Rust ${{ matrix.toolchain }}
49         if: "! matrix.build-net-tokio"
50         run: cargo build --verbose  --color always -p lightning
51       - name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features
52         if: "matrix.build-net-tokio && !matrix.coverage"
53         run: |
54           cd lightning-block-sync
55           cargo build --verbose --color always --features rest-client
56           cargo build --verbose --color always --features rpc-client
57           cargo build --verbose --color always --features rpc-client,rest-client
58           cargo build --verbose --color always --features rpc-client,rest-client,tokio
59           cd ..
60       - name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
61         if: matrix.coverage
62         run: |
63           cd lightning-block-sync
64           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rest-client
65           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client
66           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client
67           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client,tokio
68           cd ..
69       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio
70         if: "matrix.build-net-tokio && !matrix.coverage"
71         run: cargo test --verbose --color always
72       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
73         if: matrix.coverage
74         run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
75       - name: Test on Rust ${{ matrix.toolchain }}
76         if: "! matrix.build-net-tokio"
77         run: cargo test --verbose --color always  -p lightning
78       - name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features
79         if: "matrix.build-net-tokio && !matrix.coverage"
80         run: |
81           cd lightning-block-sync
82           cargo test --verbose --color always --features rest-client
83           cargo test --verbose --color always --features rpc-client
84           cargo test --verbose --color always --features rpc-client,rest-client
85           cargo test --verbose --color always --features rpc-client,rest-client,tokio
86           cd ..
87       - name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
88         if: matrix.coverage
89         run: |
90           cd lightning-block-sync
91           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rest-client
92           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client
93           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client
94           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client,tokio
95           cd ..
96       - name: Install deps for kcov
97         if: matrix.coverage
98         run: |
99           sudo apt-get update
100           sudo apt-get -y install binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev
101       - name: Install kcov
102         if: matrix.coverage
103         run: |
104           wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
105           tar xzf master.tar.gz
106           cd kcov-master && mkdir build && cd build
107           cmake ..
108           make
109           make install DESTDIR=../../kcov-build
110           cd ../.. && rm -rf kcov-master master.tar.gz
111       - name: Generate coverage report
112         if: matrix.coverage
113         run: |
114           for file in target/debug/deps/lightning*; do
115             [ -x "${file}" ] || continue;
116             mkdir -p "target/cov/$(basename $file)";
117             ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file";
118           done
119       - name: Upload coverage
120         if: matrix.coverage
121         uses: codecov/codecov-action@v1
122         with:
123           # Could you use this to fake the coverage report for your PR? Sure.
124           # Will anyone be impressed by your amazing coverage? No
125           # Maybe if codecov wasn't broken we wouldn't need to do this...
126           token: f421b687-4dc2-4387-ac3d-dc3b2528af57
127           fail_ci_if_error: true
128
129   benchmark:
130     runs-on: ubuntu-latest
131     env:
132       TOOLCHAIN: nightly
133     steps:
134       - name: Checkout source code
135         uses: actions/checkout@v2
136       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
137         uses: actions-rs/toolchain@v1
138         with:
139           toolchain: ${{ env.TOOLCHAIN }}
140           override: true
141           profile: minimal
142       - name: Cache routing graph snapshot
143         id: cache-graph
144         uses: actions/cache@v2
145         with:
146           path: lightning/net_graph-2021-02-12.bin
147           key: net_graph-2021-02-12
148       - name: Fetch routing graph snapshot
149         if: steps.cache-graph.outputs.cache-hit != 'true'
150         run: |
151           wget -O lightning/net_graph-2021-02-12.bin https://bitcoin.ninja/ldk-net_graph-879e309c128-2020-02-12.bin
152           if [ "$(sha256sum lightning/net_graph-2021-02-12.bin | awk '{ print $1 }')" != "890a1f80dfb6ef674a1e4ff0f23cd73d740731c395f99d85abbede0cfbb701ab" ]; then
153             echo "Bad hash"
154             exit 1
155           fi
156       - name: Run benchmarks on Rust ${{ matrix.toolchain }}
157         run: |
158           cd lightning
159           cargo bench --features unstable
160           cd ..
161
162   check_commits:
163     runs-on: ubuntu-latest
164     env:
165       TOOLCHAIN: stable
166     steps:
167       - name: Checkout source code
168         uses: actions/checkout@v2
169         with:
170           fetch-depth: 0
171       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
172         uses: actions-rs/toolchain@v1
173         with:
174           toolchain: ${{ env.TOOLCHAIN }}
175           override: true
176           profile: minimal
177       - name: Fetch full tree and rebase on upstream
178         run: |
179           git remote add upstream https://github.com/rust-bitcoin/rust-lightning
180           git fetch upstream
181           export GIT_COMMITTER_EMAIL="rl-ci@example.com"
182           export GIT_COMMITTER_NAME="RL CI"
183           git rebase upstream/main
184       - name: For each commit, run cargo check (including in fuzz)
185         run: ci/check-each-commit.sh upstream/main
186
187   fuzz:
188     runs-on: ubuntu-latest
189     env:
190       TOOLCHAIN: stable
191     steps:
192       - name: Checkout source code
193         uses: actions/checkout@v2
194       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
195         uses: actions-rs/toolchain@v1
196         with:
197           toolchain: ${{ env.TOOLCHAIN }}
198           override: true
199           profile: minimal
200       - name: Install dependencies for honggfuzz
201         run: |
202           sudo apt-get update
203           sudo apt-get -y install build-essential binutils-dev libunwind-dev
204       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
205         run: cd fuzz && cargo test --verbose --color always
206       - name: Run fuzzers
207         run: cd fuzz && ./ci-fuzz.sh
208
209   check_bindings:
210     runs-on: ubuntu-latest
211     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
212     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
213     # We further (temporarily) use Debian experimental since testing links rustc against the
214     # brand-new llvm-10, but clang/llvm still default to LLVM 9.
215     container: debian:experimental
216     env:
217       TOOLCHAIN: stable
218     steps:
219       - name: Install native Rust toolchain, Valgrind, and build utilitis
220         run: |
221           echo 'Package: llvm llvm-runtime clang lld' > /etc/apt/preferences.d/99-llvm10
222           echo 'Pin: release n=experimental' >> /etc/apt/preferences.d/99-llvm10
223           echo 'Pin-Priority: 995' >> /etc/apt/preferences.d/99-llvm10
224           apt-get update
225           apt-get -y dist-upgrade
226           apt-get -y install cargo valgrind lld git g++ clang
227       - name: Checkout source code
228         uses: actions/checkout@v2
229       - name: Sanity test bindings
230         working-directory: lightning-c-bindings
231         run: cargo check
232       - name: Install cbindgen
233         run: cargo install --force cbindgen
234       - name: Rebuild bindings, and check the sample app builds + links
235         run: ./genbindings.sh
236       - name: Check that the latest bindings are in git
237         run: |
238           if [ "$(git diff)" != "" ]; then
239             # cbindgen's bindings output order can be FS-dependant, so check that the lines are all the same:
240             mv lightning-c-bindings/include/lightning.h lightning-c-bindings/include/lightning.h.new
241             git checkout lightning-c-bindings/include/lightning.h
242             cat lightning-c-bindings/include/lightning.h | grep -v "Generated with cbindgen:[0-9\.]*" | sort > lightning-c-bindings/include/lightning.h.sorted
243             cat lightning-c-bindings/include/lightning.h.new | grep -v "Generated with cbindgen:[0-9\.]*" | sort > lightning-c-bindings/include/lightning.h.new.sorted
244             diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted
245             [ "$(diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted)" != "" ] && exit 2
246             git diff --exit-code
247           fi
248
249   linting:
250     runs-on: ubuntu-latest
251     env:
252       TOOLCHAIN: 1.45.2
253     steps:
254       - name: Checkout source code
255         uses: actions/checkout@v2
256       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
257         uses: actions-rs/toolchain@v1
258         with:
259           toolchain: ${{ env.TOOLCHAIN }}
260           override: true
261           profile: minimal
262       - name: Install clippy
263         run: |
264           rustup component add clippy
265       - name: Run default clippy linting
266         run: |
267           cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else