Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 15 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
57 changes: 57 additions & 0 deletions download-native-libs.sh
Original file line number Diff line number Diff line change
@@ -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"
Loading