Add lightning-block-sync package and library
[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   check_commits:
130     runs-on: ubuntu-latest
131     env:
132       TOOLCHAIN: stable
133     steps:
134       - name: Checkout source code
135         uses: actions/checkout@v2
136         with:
137           fetch-depth: 0
138       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
139         uses: actions-rs/toolchain@v1
140         with:
141           toolchain: ${{ env.TOOLCHAIN }}
142           override: true
143           profile: minimal
144       - name: Fetch full tree and rebase on upstream
145         run: |
146           git remote add upstream https://github.com/rust-bitcoin/rust-lightning
147           git fetch upstream
148           export GIT_COMMITTER_EMAIL="rl-ci@example.com"
149           export GIT_COMMITTER_NAME="RL CI"
150           git rebase upstream/main
151       - name: For each commit, run cargo check (including in fuzz)
152         run: ci/check-each-commit.sh upstream/main
153
154   fuzz:
155     runs-on: ubuntu-latest
156     env:
157       TOOLCHAIN: stable
158     steps:
159       - name: Checkout source code
160         uses: actions/checkout@v2
161       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
162         uses: actions-rs/toolchain@v1
163         with:
164           toolchain: ${{ env.TOOLCHAIN }}
165           override: true
166           profile: minimal
167       - name: Install dependencies for honggfuzz
168         run: |
169           sudo apt-get update
170           sudo apt-get -y install build-essential binutils-dev libunwind-dev
171       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
172         run: cd fuzz && cargo test --verbose --color always
173       - name: Run fuzzers
174         run: cd fuzz && ./ci-fuzz.sh
175
176   check_bindings:
177     runs-on: ubuntu-latest
178     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
179     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
180     # We further (temporarily) use Debian experimental since testing links rustc against the
181     # brand-new llvm-10, but clang/llvm still default to LLVM 9.
182     container: debian:experimental
183     env:
184       TOOLCHAIN: stable
185     steps:
186       - name: Install native Rust toolchain, Valgrind, and build utilitis
187         run: |
188           echo 'Package: llvm llvm-runtime clang lld' > /etc/apt/preferences.d/99-llvm10
189           echo 'Pin: release n=experimental' >> /etc/apt/preferences.d/99-llvm10
190           echo 'Pin-Priority: 995' >> /etc/apt/preferences.d/99-llvm10
191           apt-get update
192           apt-get -y dist-upgrade
193           apt-get -y install cargo valgrind lld git g++ clang
194       - name: Checkout source code
195         uses: actions/checkout@v2
196       - name: Sanity test bindings
197         working-directory: lightning-c-bindings
198         run: cargo check
199       - name: Install cbindgen
200         run: cargo install --force cbindgen
201       - name: Rebuild bindings, and check the sample app builds + links
202         run: ./genbindings.sh
203       - name: Check that the latest bindings are in git
204         run: |
205           if [ "$(git diff)" != "" ]; then
206             # cbindgen's bindings output order can be FS-dependant, so check that the lines are all the same:
207             mv lightning-c-bindings/include/lightning.h lightning-c-bindings/include/lightning.h.new
208             git checkout lightning-c-bindings/include/lightning.h
209             cat lightning-c-bindings/include/lightning.h | grep -v "Generated with cbindgen:[0-9\.]*" | sort > lightning-c-bindings/include/lightning.h.sorted
210             cat lightning-c-bindings/include/lightning.h.new | grep -v "Generated with cbindgen:[0-9\.]*" | sort > lightning-c-bindings/include/lightning.h.new.sorted
211             diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted
212             [ "$(diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted)" != "" ] && exit 2
213             git diff --exit-code
214           fi
215
216   linting:
217     runs-on: ubuntu-latest
218     env:
219       TOOLCHAIN: 1.45.2
220     steps:
221       - name: Checkout source code
222         uses: actions/checkout@v2
223       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
224         uses: actions-rs/toolchain@v1
225         with:
226           toolchain: ${{ env.TOOLCHAIN }}
227           override: true
228           profile: minimal
229       - name: Install clippy
230         run: |
231           rustup component add clippy
232       - name: Run default clippy linting
233         run: |
234           cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else