From 3e4b3e69a58eee72be3faf73fd2d1b789254e068 Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Sat, 30 May 2026 10:08:07 -0700 Subject: [PATCH] Add Java native library CI --- .github/workflows/java.yml | 51 ++++++++++++++++++++++++++++++++++ build.gradle | 22 ++++++++++----- download-native-libs.sh | 57 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/java.yml create mode 100755 download-native-libs.sh diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml new file mode 100644 index 0000000..beb33df --- /dev/null +++ b/.github/workflows/java.yml @@ -0,0 +1,51 @@ +name: Java + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + workflow_dispatch: + inputs: + nativeRunId: + description: "Optional LadybugDB/ladybug Java native library workflow run ID" + required: false + type: string + +jobs: + build-and-test: + name: Build and test + strategy: + matrix: + runner: [ubuntu-24.04, ubuntu-24.04-arm, macos-14] + runs-on: ${{ matrix.runner }} + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "21" + + - name: Download native libraries + env: + GH_TOKEN: ${{ github.token }} + LBUG_JAVA_NATIVE_RUN_ID: ${{ inputs.nativeRunId }} + run: ./download-native-libs.sh + + - name: Prepare test datasets + run: | + git clone --depth 1 https://github.com/LadybugDB/go-ladybug ../go-ladybug + mkdir -p ../../dataset/tinysnb ../../dataset/tinysnb-serial + cp -R ../go-ladybug/dataset/tinysnb/. ../../dataset/tinysnb/ + cp ../go-ladybug/dataset/tinysnb/vMoviesSerial.csv ../../dataset/tinysnb-serial/vMovies.csv + + - name: Build + env: + SKIP_CMAKE_BUILD: "true" + run: ./gradlew build -x test + + - name: Test + env: + SKIP_CMAKE_BUILD: "true" + run: ./gradlew test diff --git a/build.gradle b/build.gradle index 3b6c5fb..4386ccd 100644 --- a/build.gradle +++ b/build.gradle @@ -11,14 +11,22 @@ java { group = 'com.ladybugdb' def projectRoot = projectDir.parentFile.parentFile -def cmakeFile = new File(projectRoot, 'CMakeLists.txt').text -def versionLine = cmakeFile.readLines().find { it.startsWith('project(Lbug VERSION ') } -def cmakeVersion = versionLine.split(' ')[2] -def versionParts = cmakeVersion.split('\\.') -if (versionParts.length > 3) { - version = versionParts[0] + '.' + versionParts[1] + '.' + versionParts[2] + '-SNAPSHOT' +def cmakeFileRef = new File(projectRoot, 'CMakeLists.txt') +if (!cmakeFileRef.exists()) { + cmakeFileRef = new File(projectDir.parentFile, 'ladybug/CMakeLists.txt') +} +if (cmakeFileRef.exists()) { + def cmakeFile = cmakeFileRef.text + def versionLine = cmakeFile.readLines().find { it.startsWith('project(Lbug VERSION ') } + def cmakeVersion = versionLine.split(' ')[2] + def versionParts = cmakeVersion.split('\\.') + if (versionParts.length > 3) { + version = versionParts[0] + '.' + versionParts[1] + '.' + versionParts[2] + '-SNAPSHOT' + } else { + version = cmakeVersion + } } else { - version = cmakeVersion + version = providers.environmentVariable('LBUG_JAVA_VERSION').orElse('0.0.0-SNAPSHOT').get() } println "Project version: $version" diff --git a/download-native-libs.sh b/download-native-libs.sh new file mode 100755 index 0000000..0d6d460 --- /dev/null +++ b/download-native-libs.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +set -euo pipefail + +REPOSITORY="${LBUG_GITHUB_REPOSITORY:-LadybugDB/ladybug}" +RUN_ID="${LBUG_JAVA_NATIVE_RUN_ID:-}" +TARGET_DIR="${LBUG_JAVA_NATIVE_TARGET_DIR:-src/main/resources}" + +OS="$(uname -s)" +ARCH="$(uname -m)" + +case "$OS:$ARCH" in + Linux:x86_64) + ARTIFACT_NAME="java-lib-linux-x86_64" + ;; + Linux:aarch64|Linux:arm64) + ARTIFACT_NAME="java-lib-linux-aarch64" + ;; + Darwin:arm64) + ARTIFACT_NAME="java-lib-osx-arm64" + ;; + MINGW*:x86_64|MSYS*:x86_64|CYGWIN*:x86_64) + ARTIFACT_NAME="java-lib-win-x86_64" + ;; + *) + echo "Unsupported platform for Java native libraries: $OS $ARCH" >&2 + exit 1 + ;; +esac + +if [ -z "$RUN_ID" ]; then + if ! command -v gh >/dev/null 2>&1; then + echo "gh CLI is required when LBUG_JAVA_NATIVE_RUN_ID is not set" >&2 + exit 1 + fi + while IFS= read -r candidate_run_id; do + if gh api "/repos/${REPOSITORY}/actions/runs/${candidate_run_id}/artifacts" \ + --jq '.artifacts[].name' | grep -qx "$ARTIFACT_NAME"; then + RUN_ID="$candidate_run_id" + break + fi + done < <(gh run list --repo "$REPOSITORY" --workflow "Build and Deploy" --status success \ + --limit 20 --json databaseId --jq '.[].databaseId') +fi + +if [ -z "$RUN_ID" ]; then + echo "Unable to resolve a workflow run with artifact $ARTIFACT_NAME" >&2 + exit 1 +fi + +TMPDIR="$(mktemp -d)" +trap 'rm -rf "$TMPDIR"' EXIT + +mkdir -p "$TARGET_DIR" +gh run download "$RUN_ID" --repo "$REPOSITORY" --name "$ARTIFACT_NAME" --dir "$TMPDIR" +find "$TMPDIR" -type f -name 'liblbug_java_native*' -exec cp {} "$TARGET_DIR/" \; + +echo "Installed $ARTIFACT_NAME from $REPOSITORY run $RUN_ID into $TARGET_DIR"