Skip to content

Commit 3e4b3e6

Browse files
committed
Add Java native library CI
1 parent 5a9e7ac commit 3e4b3e6

3 files changed

Lines changed: 123 additions & 7 deletions

File tree

.github/workflows/java.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Java
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
workflow_dispatch:
9+
inputs:
10+
nativeRunId:
11+
description: "Optional LadybugDB/ladybug Java native library workflow run ID"
12+
required: false
13+
type: string
14+
15+
jobs:
16+
build-and-test:
17+
name: Build and test
18+
strategy:
19+
matrix:
20+
runner: [ubuntu-24.04, ubuntu-24.04-arm, macos-14]
21+
runs-on: ${{ matrix.runner }}
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- uses: actions/setup-java@v4
26+
with:
27+
distribution: temurin
28+
java-version: "21"
29+
30+
- name: Download native libraries
31+
env:
32+
GH_TOKEN: ${{ github.token }}
33+
LBUG_JAVA_NATIVE_RUN_ID: ${{ inputs.nativeRunId }}
34+
run: ./download-native-libs.sh
35+
36+
- name: Prepare test datasets
37+
run: |
38+
git clone --depth 1 https://github.com/LadybugDB/go-ladybug ../go-ladybug
39+
mkdir -p ../../dataset/tinysnb ../../dataset/tinysnb-serial
40+
cp -R ../go-ladybug/dataset/tinysnb/. ../../dataset/tinysnb/
41+
cp ../go-ladybug/dataset/tinysnb/vMoviesSerial.csv ../../dataset/tinysnb-serial/vMovies.csv
42+
43+
- name: Build
44+
env:
45+
SKIP_CMAKE_BUILD: "true"
46+
run: ./gradlew build -x test
47+
48+
- name: Test
49+
env:
50+
SKIP_CMAKE_BUILD: "true"
51+
run: ./gradlew test

build.gradle

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@ java {
1111

1212
group = 'com.ladybugdb'
1313
def projectRoot = projectDir.parentFile.parentFile
14-
def cmakeFile = new File(projectRoot, 'CMakeLists.txt').text
15-
def versionLine = cmakeFile.readLines().find { it.startsWith('project(Lbug VERSION ') }
16-
def cmakeVersion = versionLine.split(' ')[2]
17-
def versionParts = cmakeVersion.split('\\.')
18-
if (versionParts.length > 3) {
19-
version = versionParts[0] + '.' + versionParts[1] + '.' + versionParts[2] + '-SNAPSHOT'
14+
def cmakeFileRef = new File(projectRoot, 'CMakeLists.txt')
15+
if (!cmakeFileRef.exists()) {
16+
cmakeFileRef = new File(projectDir.parentFile, 'ladybug/CMakeLists.txt')
17+
}
18+
if (cmakeFileRef.exists()) {
19+
def cmakeFile = cmakeFileRef.text
20+
def versionLine = cmakeFile.readLines().find { it.startsWith('project(Lbug VERSION ') }
21+
def cmakeVersion = versionLine.split(' ')[2]
22+
def versionParts = cmakeVersion.split('\\.')
23+
if (versionParts.length > 3) {
24+
version = versionParts[0] + '.' + versionParts[1] + '.' + versionParts[2] + '-SNAPSHOT'
25+
} else {
26+
version = cmakeVersion
27+
}
2028
} else {
21-
version = cmakeVersion
29+
version = providers.environmentVariable('LBUG_JAVA_VERSION').orElse('0.0.0-SNAPSHOT').get()
2230
}
2331

2432
println "Project version: $version"

download-native-libs.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
REPOSITORY="${LBUG_GITHUB_REPOSITORY:-LadybugDB/ladybug}"
5+
RUN_ID="${LBUG_JAVA_NATIVE_RUN_ID:-}"
6+
TARGET_DIR="${LBUG_JAVA_NATIVE_TARGET_DIR:-src/main/resources}"
7+
8+
OS="$(uname -s)"
9+
ARCH="$(uname -m)"
10+
11+
case "$OS:$ARCH" in
12+
Linux:x86_64)
13+
ARTIFACT_NAME="java-lib-linux-x86_64"
14+
;;
15+
Linux:aarch64|Linux:arm64)
16+
ARTIFACT_NAME="java-lib-linux-aarch64"
17+
;;
18+
Darwin:arm64)
19+
ARTIFACT_NAME="java-lib-osx-arm64"
20+
;;
21+
MINGW*:x86_64|MSYS*:x86_64|CYGWIN*:x86_64)
22+
ARTIFACT_NAME="java-lib-win-x86_64"
23+
;;
24+
*)
25+
echo "Unsupported platform for Java native libraries: $OS $ARCH" >&2
26+
exit 1
27+
;;
28+
esac
29+
30+
if [ -z "$RUN_ID" ]; then
31+
if ! command -v gh >/dev/null 2>&1; then
32+
echo "gh CLI is required when LBUG_JAVA_NATIVE_RUN_ID is not set" >&2
33+
exit 1
34+
fi
35+
while IFS= read -r candidate_run_id; do
36+
if gh api "/repos/${REPOSITORY}/actions/runs/${candidate_run_id}/artifacts" \
37+
--jq '.artifacts[].name' | grep -qx "$ARTIFACT_NAME"; then
38+
RUN_ID="$candidate_run_id"
39+
break
40+
fi
41+
done < <(gh run list --repo "$REPOSITORY" --workflow "Build and Deploy" --status success \
42+
--limit 20 --json databaseId --jq '.[].databaseId')
43+
fi
44+
45+
if [ -z "$RUN_ID" ]; then
46+
echo "Unable to resolve a workflow run with artifact $ARTIFACT_NAME" >&2
47+
exit 1
48+
fi
49+
50+
TMPDIR="$(mktemp -d)"
51+
trap 'rm -rf "$TMPDIR"' EXIT
52+
53+
mkdir -p "$TARGET_DIR"
54+
gh run download "$RUN_ID" --repo "$REPOSITORY" --name "$ARTIFACT_NAME" --dir "$TMPDIR"
55+
find "$TMPDIR" -type f -name 'liblbug_java_native*' -exec cp {} "$TARGET_DIR/" \;
56+
57+
echo "Installed $ARTIFACT_NAME from $REPOSITORY run $RUN_ID into $TARGET_DIR"

0 commit comments

Comments
 (0)