Update CI to run build and tests on Macos and Windows in addition to Ubuntu.
[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.39.0 is MSRV for lightning-net-tokio and generates coverage
17                      1.39.0]
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.39.0
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: Test on Rust ${{ matrix.toolchain }} with net-tokio
52         if: "matrix.build-net-tokio && !matrix.coverage"
53         run: cargo test --verbose --color always
54       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
55         if: matrix.coverage
56         run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
57       - name: Test on Rust ${{ matrix.toolchain }}
58         if: "! matrix.build-net-tokio"
59         run: cargo test --verbose --color always  -p lightning
60       - name: Install deps for kcov
61         if: matrix.coverage
62         run: |
63           sudo apt-get update
64           sudo apt-get -y install binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev
65       - name: Install kcov
66         if: matrix.coverage
67         run: |
68           wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
69           tar xzf master.tar.gz
70           cd kcov-master && mkdir build && cd build
71           cmake ..
72           make
73           make install DESTDIR=../../kcov-build
74           cd ../.. && rm -rf kcov-master master.tar.gz
75       - name: Generate coverage report
76         if: matrix.coverage
77         run: |
78           for file in target/debug/lightning-*; do
79             [ -x "${file}" ] || continue;
80             mkdir -p "target/cov/$(basename $file)";
81             ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file";
82           done
83       - name: Upload coverage
84         if: matrix.coverage
85         uses: codecov/codecov-action@v1
86         with:
87           # Could you use this to fake the coverage report for your PR? Sure.
88           # Will anyone be impressed by your amazing coverage? No
89           # Maybe if codecov wasn't broken we wouldn't need to do this...
90           token: f421b687-4dc2-4387-ac3d-dc3b2528af57
91           fail_ci_if_error: true
92
93   check_commits:
94     runs-on: ubuntu-latest
95     env:
96       TOOLCHAIN: stable
97     steps:
98       - name: Checkout source code
99         uses: actions/checkout@v2
100         with:
101           fetch-depth: 0
102       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
103         uses: actions-rs/toolchain@v1
104         with:
105           toolchain: ${{ env.TOOLCHAIN }}
106           override: true
107           profile: minimal
108       - name: Fetch full tree and rebase on upstream
109         run: |
110           git remote add upstream https://github.com/rust-bitcoin/rust-lightning
111           git fetch upstream
112           git rebase upstream/main
113       - name: For each commit, run cargo check (including in fuzz)
114         run: ci/check-each-commit.sh upstream/main
115
116   fuzz:
117     runs-on: ubuntu-latest
118     env:
119       TOOLCHAIN: stable
120     steps:
121       - name: Checkout source code
122         uses: actions/checkout@v2
123       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
124         uses: actions-rs/toolchain@v1
125         with:
126           toolchain: ${{ env.TOOLCHAIN }}
127           override: true
128           profile: minimal
129       - name: Install dependencies for honggfuzz
130         run: |
131           sudo apt-get update
132           sudo apt-get -y install build-essential binutils-dev libunwind-dev
133       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
134         run: cd fuzz && cargo test --verbose --color always
135       - name: Run fuzzers
136         run: cd fuzz && ./ci-fuzz.sh
137
138   check_bindings:
139     runs-on: ubuntu-latest
140     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
141     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
142     # We further (temporarily) use Debian experimental since testing links rustc against the
143     # brand-new llvm-10, but clang/llvm still default to LLVM 9.
144     container: debian:experimental
145     env:
146       TOOLCHAIN: stable
147     steps:
148       - name: Install native Rust toolchain, Valgrind, and build utilitis
149         run: |
150           echo 'Package: llvm llvm-runtime clang lld' > /etc/apt/preferences.d/99-llvm10
151           echo 'Pin: release n=experimental' >> /etc/apt/preferences.d/99-llvm10
152           echo 'Pin-Priority: 995' >> /etc/apt/preferences.d/99-llvm10
153           apt-get update
154           apt-get -y dist-upgrade
155           apt-get -y install cargo valgrind lld git g++ clang
156       - name: Checkout source code
157         uses: actions/checkout@v2
158       - name: Sanity test bindings
159         working-directory: lightning-c-bindings
160         run: cargo check
161       - name: Install cbindgen
162         run: cargo install --force cbindgen
163       - name: Rebuild bindings, and check the sample app builds + links
164         run: ./genbindings.sh
165       - name: Check that the latest bindings are in git
166         run: |
167           if [ "$(git diff)" != "" ]; then
168             # cbindgen's bindings output order can be FS-dependant, so check that the lines are all the same:
169             mv lightning-c-bindings/include/lightning.h lightning-c-bindings/include/lightning.h.new
170             git checkout lightning-c-bindings/include/lightning.h
171             cat lightning-c-bindings/include/lightning.h | sort > lightning-c-bindings/include/lightning.h.sorted
172             cat lightning-c-bindings/include/lightning.h.new | sort > lightning-c-bindings/include/lightning.h.new.sorted
173             diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted
174             #
175             mv lightning-c-bindings/include/lightningpp.hpp lightning-c-bindings/include/lightningpp.hpp.new
176             git checkout lightning-c-bindings/include/lightningpp.hpp
177             cat lightning-c-bindings/include/lightningpp.hpp | sort > lightning-c-bindings/include/lightningpp.hpp.sorted
178             cat lightning-c-bindings/include/lightningpp.hpp.new | sort > lightning-c-bindings/include/lightningpp.hpp.new.sorted
179             diff lightning-c-bindings/include/lightningpp.hpp.sorted lightning-c-bindings/include/lightningpp.hpp.new.sorted
180             #
181             [ "$(diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted)" != "" ] && exit 2
182             [ "$(diff lightning-c-bindings/include/lightningpp.hpp.sorted lightning-c-bindings/include/lightningpp.hpp.new.sorted)" != "" ] && exit 3
183             git diff --exit-code
184           fi