95372d729273d6731102ce17450c7e400e057360
[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         toolchain: [ stable,
10                      beta,
11                      # 1.30.0 is MSRV for Rust-Lightning
12                      1.30.0,
13                      # 1.34.2 is Debian stable
14                      1.34.2,
15                      # 1.39.0 is MSRV for lightning-net-tokio and generates coverage
16                      1.39.0]
17         include:
18           - toolchain: stable
19             build-net-tokio: true
20           - toolchain: beta
21             build-net-tokio: true
22           - toolchain: 1.39.0
23             build-net-tokio: true
24             coverage: true
25           - toolchain: 1.34.2
26     runs-on: ubuntu-latest
27     steps:
28       - name: Checkout source code
29         uses: actions/checkout@v2
30       - name: Install Rust ${{ matrix.toolchain }} toolchain
31         uses: actions-rs/toolchain@v1
32         with:
33           toolchain: ${{ matrix.toolchain }}
34           override: true
35           profile: minimal
36       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio
37         if: matrix.build-net-tokio
38         run: RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always
39       - name: Build on Rust ${{ matrix.toolchain }}
40         if: "! matrix.build-net-tokio"
41         run: RUSTFLAGS="-C link-dead-code" cargo build --verbose  --color always -p lightning
42       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio
43         if: matrix.build-net-tokio
44         run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
45       - name: Test on Rust ${{ matrix.toolchain }}
46         if: "! matrix.build-net-tokio"
47         run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always  -p lightning
48       - name: Install deps for kcov
49         if: matrix.coverage
50         run: |
51           sudo apt-get update
52           sudo apt-get -y install binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev
53       - name: Install kcov
54         if: matrix.coverage
55         run: |
56           wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
57           tar xzf master.tar.gz
58           cd kcov-master && mkdir build && cd build
59           cmake ..
60           make
61           make install DESTDIR=../../kcov-build
62           cd ../.. && rm -rf kcov-master master.tar.gz
63       - name: Generate coverage report
64         if: matrix.coverage
65         run: |
66           for file in target/debug/lightning-*; do
67             [ -x "${file}" ] || continue;
68             mkdir -p "target/cov/$(basename $file)";
69             ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file";
70           done
71       - name: Upload coverage
72         if: matrix.coverage
73         uses: codecov/codecov-action@v1
74         with:
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           token: f421b687-4dc2-4387-ac3d-dc3b2528af57
79           fail_ci_if_error: true
80
81   fuzz:
82     runs-on: ubuntu-latest
83     env:
84       TOOLCHAIN: stable
85     steps:
86       - name: Checkout source code
87         uses: actions/checkout@v2
88       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
89         uses: actions-rs/toolchain@v1
90         with:
91           toolchain: ${{ env.TOOLCHAIN }}
92           override: true
93           profile: minimal
94       - name: Install dependencies for honggfuzz
95         run: |
96           sudo apt-get update
97           sudo apt-get -y install build-essential binutils-dev libunwind-dev
98       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
99         run: cd fuzz && cargo test --verbose --color always
100       - name: Run fuzzers
101         run: cd fuzz && ./ci-fuzz.sh
102
103   check_bindings:
104     runs-on: ubuntu-latest
105     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
106     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
107     # We further (temporarily) use Debian experimental since testing links rustc against the
108     # brand-new llvm-10, but clang/llvm still default to LLVM 9.
109     container: debian:experimental
110     env:
111       TOOLCHAIN: stable
112     steps:
113       - name: Install native Rust toolchain, Valgrind, and build utilitis
114         run: |
115           echo 'Package: llvm llvm-runtime clang lld' > /etc/apt/preferences.d/99-llvm10
116           echo 'Pin: release n=experimental' >> /etc/apt/preferences.d/99-llvm10
117           echo 'Pin-Priority: 995' >> /etc/apt/preferences.d/99-llvm10
118           apt-get update
119           apt-get -y dist-upgrade
120           apt-get -y install cargo valgrind lld git g++ clang
121       - name: Checkout source code
122         uses: actions/checkout@v2
123       - name: Sanity test bindings
124         working-directory: lightning-c-bindings
125         run: cargo check
126       - name: Install cbindgen
127         run: cargo install --force cbindgen
128       - name: Rebuild bindings, and check the sample app builds + links
129         run: ./genbindings.sh
130       - name: Check that the latest bindings are in git
131         run: |
132           if [ "$(git diff)" != "" ]; then
133             # cbindgen's bindings output order can be FS-dependant, so check that the lines are all the same:
134             mv lightning-c-bindings/include/lightning.h lightning-c-bindings/include/lightning.h.new
135             git checkout lightning-c-bindings/include/lightning.h
136             cat lightning-c-bindings/include/lightning.h | sort > lightning-c-bindings/include/lightning.h.sorted
137             cat lightning-c-bindings/include/lightning.h.new | sort > lightning-c-bindings/include/lightning.h.new.sorted
138             diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted
139             #
140             mv lightning-c-bindings/include/lightningpp.hpp lightning-c-bindings/include/lightningpp.hpp.new
141             git checkout lightning-c-bindings/include/lightningpp.hpp
142             cat lightning-c-bindings/include/lightningpp.hpp | sort > lightning-c-bindings/include/lightningpp.hpp.sorted
143             cat lightning-c-bindings/include/lightningpp.hpp.new | sort > lightning-c-bindings/include/lightningpp.hpp.new.sorted
144             diff lightning-c-bindings/include/lightningpp.hpp.sorted lightning-c-bindings/include/lightningpp.hpp.new.sorted
145             #
146             [ "$(diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted)" != "" ] && exit 2
147             [ "$(diff lightning-c-bindings/include/lightningpp.hpp.sorted lightning-c-bindings/include/lightningpp.hpp.new.sorted)" != "" ] && exit 3
148             git diff --exit-code
149           fi