Don't let CI fail to check commits b/c git isn't configured in CI
[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           export GIT_COMMITTER_EMAIL="rl-ci@example.com"
113           export GIT_COMMITTER_NAME="RL CI"
114           git rebase upstream/main
115       - name: For each commit, run cargo check (including in fuzz)
116         run: ci/check-each-commit.sh upstream/main
117
118   fuzz:
119     runs-on: ubuntu-latest
120     env:
121       TOOLCHAIN: stable
122     steps:
123       - name: Checkout source code
124         uses: actions/checkout@v2
125       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
126         uses: actions-rs/toolchain@v1
127         with:
128           toolchain: ${{ env.TOOLCHAIN }}
129           override: true
130           profile: minimal
131       - name: Install dependencies for honggfuzz
132         run: |
133           sudo apt-get update
134           sudo apt-get -y install build-essential binutils-dev libunwind-dev
135       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
136         run: cd fuzz && cargo test --verbose --color always
137       - name: Run fuzzers
138         run: cd fuzz && ./ci-fuzz.sh
139
140   check_bindings:
141     runs-on: ubuntu-latest
142     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
143     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
144     # We further (temporarily) use Debian experimental since testing links rustc against the
145     # brand-new llvm-10, but clang/llvm still default to LLVM 9.
146     container: debian:experimental
147     env:
148       TOOLCHAIN: stable
149     steps:
150       - name: Install native Rust toolchain, Valgrind, and build utilitis
151         run: |
152           echo 'Package: llvm llvm-runtime clang lld' > /etc/apt/preferences.d/99-llvm10
153           echo 'Pin: release n=experimental' >> /etc/apt/preferences.d/99-llvm10
154           echo 'Pin-Priority: 995' >> /etc/apt/preferences.d/99-llvm10
155           apt-get update
156           apt-get -y dist-upgrade
157           apt-get -y install cargo valgrind lld git g++ clang
158       - name: Checkout source code
159         uses: actions/checkout@v2
160       - name: Sanity test bindings
161         working-directory: lightning-c-bindings
162         run: cargo check
163       - name: Install cbindgen
164         run: cargo install --force cbindgen
165       - name: Rebuild bindings, and check the sample app builds + links
166         run: ./genbindings.sh
167       - name: Check that the latest bindings are in git
168         run: |
169           if [ "$(git diff)" != "" ]; then
170             # cbindgen's bindings output order can be FS-dependant, so check that the lines are all the same:
171             mv lightning-c-bindings/include/lightning.h lightning-c-bindings/include/lightning.h.new
172             git checkout lightning-c-bindings/include/lightning.h
173             cat lightning-c-bindings/include/lightning.h | sort > lightning-c-bindings/include/lightning.h.sorted
174             cat lightning-c-bindings/include/lightning.h.new | sort > lightning-c-bindings/include/lightning.h.new.sorted
175             diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted
176             #
177             mv lightning-c-bindings/include/lightningpp.hpp lightning-c-bindings/include/lightningpp.hpp.new
178             git checkout lightning-c-bindings/include/lightningpp.hpp
179             cat lightning-c-bindings/include/lightningpp.hpp | sort > lightning-c-bindings/include/lightningpp.hpp.sorted
180             cat lightning-c-bindings/include/lightningpp.hpp.new | sort > lightning-c-bindings/include/lightningpp.hpp.new.sorted
181             diff lightning-c-bindings/include/lightningpp.hpp.sorted lightning-c-bindings/include/lightningpp.hpp.new.sorted
182             #
183             [ "$(diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted)" != "" ] && exit 2
184             [ "$(diff lightning-c-bindings/include/lightningpp.hpp.sorted lightning-c-bindings/include/lightningpp.hpp.new.sorted)" != "" ] && exit 3
185             git diff --exit-code
186           fi