Drop binaries from the repo, they are now at https://git.bitcoin.ninja/index.cgi...
[ldk-java] / .github / workflows / build.yml
1 name: Continuous Integration Checks
2
3 on: [push, pull_request]
4
5 jobs:
6   check_bindings:
7     runs-on: ubuntu-latest
8     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
9     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
10     container: debian:bullseye
11     env:
12       TOOLCHAIN: stable
13     steps:
14       - name: Install native Rust toolchain, Valgrind, and build utilitis
15         run: |
16           apt-get update
17           apt-get -y dist-upgrade
18           apt-get -y install cargo libstd-rust-dev-wasm32 valgrind lld git g++ clang openjdk-11-jdk maven faketime llvm
19       - name: Checkout source code
20         uses: actions/checkout@v2
21         with:
22           fetch-depth: 0
23       - name: Install cbindgen
24         run: cargo install --force cbindgen
25       - name: Checkout Rust-Lightning and LDK-C-Bindings git
26         run: |
27           git config --global user.email "ldk-ci@example.com"
28           git config --global user.name "LDK CI"
29           # Note this is a different endpoint, as we need one non-upstream commit!
30           git clone https://git.bitcoin.ninja/rust-lightning
31           cd rust-lightning
32           git checkout origin/2021-03-java-bindings-base
33           cd ..
34           git clone https://github.com/lightningdevkit/ldk-c-bindings
35       - name: Rebuild C bindings without STD for WASM
36         run: |
37           cd ldk-c-bindings
38           ./genbindings.sh ../rust-lightning false
39           mv lightning-c-bindings/target/wasm32-wasi ./
40           cd ..
41       - name: Rebuild C bindings, and check the sample app builds + links
42         run: |
43           cd ldk-c-bindings
44           # Reset the Cargo.toml file so that git describe doesn't think we're "-dirty"
45           git checkout lightning-c-bindings/Cargo.toml
46           ./genbindings.sh ../rust-lightning true
47           mv wasm32-wasi lightning-c-bindings/target/
48           cd ..
49       - name: Build Java/TS Debug Bindings
50         run: ./genbindings.sh ./ldk-c-bindings/ "-I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/" true false
51       - name: Run Java Tests against Debug Bindings
52         run: |
53           mv liblightningjni_debug_Linux-amd64.so liblightningjni.so
54           export ASAN_OPTIONS=detect_leaks=0
55           LD_PRELOAD=/usr/lib/llvm-11/lib/clang/11.0.1/lib/linux/libclang_rt.asan-x86_64.so LD_LIBRARY_PATH=. mvn test
56       - name: Detect current git version
57         run: |
58           # We assume the top commit is just a bindings update commit, so we
59           # check out the previous commit to use as the commit we git describe.
60           # If the top commit is a merge commit, we need to get the last merge
61           # head and assume the latest bindings are built against its parent.
62           COMMIT_PARENTS=$(git show -s --pretty=format:%P HEAD)
63           if [ "${#COMMIT_PARENTS}" = 40 ]; then
64             export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD^1)"
65           else
66             MERGE_HEAD=$(git show --pretty=format:%P HEAD | ( for last in $(cat /dev/stdin); do true; done; echo $last ))
67             export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag $MERGE_HEAD^1)"
68           fi
69           echo "Using $LDK_GARBAGECOLLECTED_GIT_OVERRIDE as git version"
70           echo "$LDK_GARBAGECOLLECTED_GIT_OVERRIDE" > .git_ver
71       - name: Checkout latest MacOS binaries
72         run: |
73           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
74           git clone https://git.bitcoin.ninja/ldk-java-bins
75           mkdir -p src/main/resources/
76           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjni_MacOSX-"* src/main/resources/
77       - name: Build Java/TS Release Bindings
78         run: |
79           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
80           ./genbindings.sh ./ldk-c-bindings/ "-I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/" false false
81       - name: Run Java Tests against built release jar
82         run: |
83           faketime 2021-01-01 mvn -DskipTests=true package
84           mvn install:install-file -Dfile=target/ldk-java-1.0-SNAPSHOT.jar -DgroupId=org.ldk -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
85           cd javatester
86           mvn package
87           java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar
88           cd ..
89       - name: Check latest headers are in git
90         run: |
91           git diff --exit-code
92       - name: Check latest library and jars are in bins repo
93         run: |
94           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
95           cp src/main/resources/liblightningjni_Linux-amd64.nativelib "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"
96           cp target/ldk-java-1.0-SNAPSHOT.jar "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"
97           cp target/ldk-java-1.0-SNAPSHOT-sources.jar "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"
98           cd ldk-java-bins
99           git diff --exit-code
100
101   osx:
102     strategy:
103       matrix:
104         include:
105           - platform: macos-10.15
106           # MacOS 11 is currently in private preview, we've applied for access
107           # - platform: macos-11
108     runs-on: ${{ matrix.platform }}
109     env:
110       TOOLCHAIN: stable
111     steps:
112       - name: Install other Rust platforms
113         run: rustup target install aarch64-apple-darwin
114       - name: Fetch upstream LLVM/clang snapshot
115         run: |
116           wget -O clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz
117           if [ "$(shasum -a 256 clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz | awk '{ print $1 }')" != "7bc2259bf75c003f644882460fc8e844ddb23b27236fe43a2787870a4cd8ab50" ]; then
118             echo "Bad hash"
119             exit 1
120           fi
121       - name: Unpack upstream LLVM+clang and use it by default
122         run: |
123           tar xvvf clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz
124       - name: Checkout source code
125         uses: actions/checkout@v2
126         with:
127           fetch-depth: 0
128       - name: Install cbindgen
129         run: cargo install --force cbindgen
130       - name: Checkout Rust-Lightning and LDK-C-Bindings git
131         run: |
132           git config --global user.email "ldk-ci@example.com"
133           git config --global user.name "LDK CI"
134           git clone https://github.com/rust-bitcoin/rust-lightning
135           cd rust-lightning
136           git remote add matt https://git.bitcoin.ninja/rust-lightning
137           git fetch matt
138           git merge matt/2021-03-java-bindings-base
139           cd ..
140           git clone https://github.com/lightningdevkit/ldk-c-bindings
141       - name: Rebuild C bindings with upstream clang, and check the sample app builds + links
142         run: |
143           cd ldk-c-bindings
144           export PATH=`pwd`/clang+llvm-12.0.0-x86_64-apple-darwin/bin:$PATH
145           CC=clang ./genbindings.sh ../rust-lightning true
146           cd ..
147       - name: Fetch OpenJDK 16
148         run: |
149           wget -O openjdk-16.0.1_osx-x64_bin.tar.gz https://download.java.net/java/GA/jdk16.0.1/7147401fd7354114ac51ef3e1328291f/9/GPL/openjdk-16.0.1_osx-x64_bin.tar.gz
150           if [ "$(shasum -a 256 openjdk-16.0.1_osx-x64_bin.tar.gz | awk '{ print $1 }')" != "6098f839954439d4916444757c542c1b8778a32461706812d41cc8bbefce7f2f" ]; then
151             echo "Bad hash"
152             exit 1
153           fi
154           tar xvvf openjdk-16.0.1_osx-x64_bin.tar.gz
155           export JAVA_HOME=`pwd`/jdk-16.0.1.jdk/Contents/Home
156           export PATH=$JAVA_HOME/bin:$PATH
157       - name: Detect current git version
158         run: |
159           # We assume the top commit is just a bindings update commit, so we
160           # check out the previous commit to use as the commit we git describe.
161           # If the top commit is a merge commit, we need to get the last merge
162           # head and assume the latest bindings are built against its parent.
163           COMMIT_PARENTS=$(git show -s --pretty=format:%P HEAD)
164           if [ "${#COMMIT_PARENTS}" = 40 ]; then
165             export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD^1)"
166           else
167             MERGE_HEAD=$(git show --pretty=format:%P HEAD | ( for last in $(cat /dev/stdin); do true; done; echo $last ))
168             export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag $MERGE_HEAD^1)"
169           fi
170           echo "Using $LDK_GARBAGECOLLECTED_GIT_OVERRIDE as git version"
171           echo "$LDK_GARBAGECOLLECTED_GIT_OVERRIDE" > .git_ver
172       - name: Checkout latest Linux binaries
173         run: |
174           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
175           git clone https://git.bitcoin.ninja/ldk-java-bins
176           mkdir -p src/main/resources/
177           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjni_Linux-"* src/main/resources/
178       - name: Build Java/TS Release Bindings
179         run: |
180           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
181           # genbindings.sh always fails as there is no wasm32-wasi library
182           # available, so instead we check that the expected JNI library
183           # is created.
184           ./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$(xcrun --show-sdk-path)" false false || echo
185           cat src/main/resources/liblightningjni_MacOSX-x86_64.nativelib > /dev/null
186       - name: Fetch Maven 3.8.1
187         run: |
188           wget -O apache-maven-3.8.1-bin.tar.gz https://apache.osuosl.org/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
189           if [ "$(shasum -a 256 apache-maven-3.8.1-bin.tar.gz | awk '{ print $1 }')" != "b98a1905eb554d07427b2e5509ff09bd53e2f1dd7a0afa38384968b113abef02" ]; then
190             echo "Bad hash"
191             exit 1
192           fi
193           tar xvvf apache-maven-3.8.1-bin.tar.gz
194           export PATH=apache-maven-3.8.1/bin:$PATH
195       - name: Run Java Tests against built jar
196         run: |
197           mvn -DskipTests=true package
198           mvn install:install-file -Dfile=target/ldk-java-1.0-SNAPSHOT.jar -DgroupId=org.ldk -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
199           cd javatester
200           mvn package
201           java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar
202           cd ..
203       - name: Check latest release libs are in git
204         run: |
205           if [ "${{ matrix.platform }}" = "macos-11" ]; then
206             export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
207             cp src/main/resources/liblightningjni_MacOS-amd64.nativelib "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"
208             cd ldk-java-bins
209             git diff --exit-code
210           fi