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
77 changes: 2 additions & 75 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,82 +14,9 @@ jobs:
with:
fail_level: error

# One leg per platform. Each leg runs the same script a developer runs locally
# (native/linux.sh, native/macos.sh, native/windows.ps1) and uploads native/dist/resources.
# One leg per platform, defined once in native.yml and shared with release.yml.
native:
name: native ${{ matrix.leg }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- { leg: linux-x86_64, runner: ubuntu-22.04, script: native/linux.sh --no-sync-java }
- { leg: linux-aarch64, runner: ubuntu-22.04-arm, script: native/linux.sh --no-sync-java }
- { leg: osx-x86_64, runner: macos-15-intel, script: native/macos.sh }
- { leg: osx-aarch64, runner: macos-14, script: native/macos.sh }
- { leg: windows-x86_64, runner: windows-2022, script: pwsh native/windows.ps1 }
steps:
- uses: actions/checkout@v7
with:
submodules: recursive

- name: Submodule revision
id: sub
shell: bash
run: echo "sha=$(git rev-parse HEAD:native/lightgbm)" >> "$GITHUB_OUTPUT"

- name: Cache native/dist
id: cache
uses: actions/cache@v6
with:
path: native/dist
key: native-v1-${{ matrix.leg }}-${{ steps.sub.outputs.sha }}-${{ hashFiles('native/Dockerfile', 'native/*.sh', 'native/*.ps1') }}

- name: Install toolchain (macOS)
if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'macOS'
run: brew install cmake swig libomp

- name: Install toolchain (Windows)
if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Windows'
run: choco install swig --no-progress -y

- name: Set up JDK
if: steps.cache.outputs.cache-hit != 'true' && runner.os != 'Linux'
uses: actions/setup-java@v6
with:
distribution: temurin
java-version: '11'

- name: Set up buildx
if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Linux'
uses: docker/setup-buildx-action@v4

- name: Build natives
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
env:
DOCKER_BUILD_EXTRA_ARGS: --cache-from type=gha,scope=${{ matrix.leg }} --cache-to type=gha,scope=${{ matrix.leg }},mode=max
run: ${{ matrix.script }}

- name: List output
shell: bash
run: find native/dist -type f | sort

- uses: actions/upload-artifact@v7
with:
name: natives-${{ matrix.leg }}
path: native/dist/resources
if-no-files-found: error
retention-days: 7

- name: Upload generated SWIG java (canonical leg)
if: matrix.leg == 'linux-x86_64'
uses: actions/upload-artifact@v7
with:
name: swig-java
path: native/dist/java
if-no-files-found: error
retention-days: 7
uses: ./.github/workflows/native.yml

test:
name: test ${{ matrix.leg }} jdk${{ matrix.jvm }}
Expand Down
83 changes: 83 additions & 0 deletions .github/workflows/native.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: native

# Reusable: builds the native libs on every platform and uploads one artifact per leg.
# Called by ci.yml (PRs, main) and release.yml (tags). Each leg runs the same script a developer
# runs locally (native/linux.sh, native/macos.sh, native/windows.ps1) and uploads native/dist/resources.
on:
workflow_call:

jobs:
native:
name: native ${{ matrix.leg }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- { leg: linux-x86_64, runner: ubuntu-22.04, script: native/linux.sh --no-sync-java }
- { leg: linux-aarch64, runner: ubuntu-22.04-arm, script: native/linux.sh --no-sync-java }
- { leg: osx-x86_64, runner: macos-15-intel, script: native/macos.sh }
- { leg: osx-aarch64, runner: macos-14, script: native/macos.sh }
- { leg: windows-x86_64, runner: windows-2022, script: pwsh native/windows.ps1 }
steps:
- uses: actions/checkout@v7
with:
submodules: recursive

- name: Submodule revision
id: sub
shell: bash
run: echo "sha=$(git rev-parse HEAD:native/lightgbm)" >> "$GITHUB_OUTPUT"

- name: Cache native/dist
id: cache
uses: actions/cache@v6
with:
path: native/dist
key: native-v1-${{ matrix.leg }}-${{ steps.sub.outputs.sha }}-${{ hashFiles('native/Dockerfile', 'native/*.sh', 'native/*.ps1') }}

- name: Install toolchain (macOS)
if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'macOS'
run: brew install cmake swig libomp

- name: Install toolchain (Windows)
if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Windows'
run: choco install swig --no-progress -y

- name: Set up JDK
if: steps.cache.outputs.cache-hit != 'true' && runner.os != 'Linux'
uses: actions/setup-java@v6
with:
distribution: temurin
java-version: '11'

- name: Set up buildx
if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Linux'
uses: docker/setup-buildx-action@v4

- name: Build natives
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
env:
DOCKER_BUILD_EXTRA_ARGS: --cache-from type=gha,scope=${{ matrix.leg }} --cache-to type=gha,scope=${{ matrix.leg }},mode=max
run: ${{ matrix.script }}

- name: List output
shell: bash
run: find native/dist -type f | sort

- uses: actions/upload-artifact@v7
with:
name: natives-${{ matrix.leg }}
path: native/dist/resources
if-no-files-found: error
retention-days: 7

- name: Upload generated SWIG java (canonical leg)
if: matrix.leg == 'linux-x86_64'
uses: actions/upload-artifact@v7
with:
name: swig-java
path: native/dist/java
if-no-files-found: error
retention-days: 7
90 changes: 90 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: release

# Tag X.Y.Z-N on main -> build natives on all platforms (native.yml), publish to Maven Central,
# create the GitHub release. Same shape and secret names as metarank/ltrlib's release.yml.
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+*' # 4.6.0-3 — no v prefix

permissions:
contents: write # create release + upload assets

jobs:
native:
uses: ./.github/workflows/native.yml

publish:
needs: native
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
with:
lfs: true # test data under src/test/resources; deploy runs the tests

- uses: actions/download-artifact@v8
with:
pattern: natives-*
path: native/dist/resources
merge-multiple: true

- uses: actions/download-artifact@v8
with:
name: swig-java
path: native/dist/java

- name: Verify all natives present
run: bash native/verify-dist.sh

- name: Committed SWIG java is up to date
run: |
find src/main/java/com/microsoft/ml/lightgbm -maxdepth 1 -name '*.java' ! -name PredictionType.java ! -name SwigPointers.java -delete
cp native/dist/java/com/microsoft/ml/lightgbm/*.java src/main/java/com/microsoft/ml/lightgbm/
git diff --exit-code --stat -- src/main/java/com/microsoft/ml/lightgbm \
|| { echo "::error::src/main/java/com/microsoft/ml/lightgbm is stale; run native/linux.sh and commit the result"; exit 1; }

- uses: actions/setup-java@v6
with:
distribution: temurin
java-version: '11'
cache: maven
server-id: central # matches <publishingServerId> in pom.xml
server-username: SONATYPE_USERNAME
server-password: SONATYPE_PASSWORD

- name: Verify pom version matches the tag
run: |
version="$(mvn -B -q help:evaluate -Dexpression=project.version -DforceStdout)"
[[ "$version" == "$GITHUB_REF_NAME" ]] \
|| { echo "::error::pom.xml version is $version but the tag is $GITHUB_REF_NAME"; exit 1; }

- name: Import PGP key
run: echo "$PGP_SECRET" | gpg --batch --import
env:
PGP_SECRET: ${{ secrets.PGP_SECRET }}

- name: Build and check the jar bundles all five platforms
run: |
mvn -B -DskipTests package
jar=""
for f in target/lightgbm4j-*.jar; do
case "$f" in *-sources.jar|*-javadoc.jar) ;; *) jar="$f" ;; esac
done
[[ -n "$jar" ]] || { echo "::error::main jar not found in target/"; exit 1; }
unzip -l "$jar" | grep 'lightgbm4j/' | grep -E 'lib_lightgbm' | tee /tmp/natives.txt
for dir in linux/x86_64 linux/aarch64 osx/x86_64 osx/aarch64 windows/x86_64; do
[[ "$(grep -c "lightgbm4j/$dir/" /tmp/natives.txt)" == 4 ]] || { echo "::error::$dir does not have 2 libs + 2 md5 in $jar"; exit 1; }
done

- name: Test, sign and publish to Maven Central
run: mvn -B deploy
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}

- name: Create GitHub release
uses: softprops/action-gh-release@v3
with:
generate_release_notes: true
files: target/lightgbm4j-*.jar*
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ To install, use the following maven coordinates:
<dependency>
<groupId>io.github.metarank</groupId>
<artifactId>lightgbm4j</artifactId>
<version>4.6.0-2</version>
<version>4.6.0-3</version>
</dependency>
```

Expand Down Expand Up @@ -91,6 +91,21 @@ mvn test
# bump <version> in pom.xml, then commit native/lightgbm, src/main/java/com/microsoft/ml/lightgbm and pom.xml
```

### Releasing

Releases are published by CI (`.github/workflows/release.yml`) when a version tag is pushed:

```bash
# bump <version> in pom.xml and in the README snippet above, then:
git commit -am "release X.Y.Z-N"
git tag X.Y.Z-N
git push origin main X.Y.Z-N
```

The workflow builds the natives on all platforms, checks the pom version matches the tag, runs the tests, signs and
publishes to Maven Central, and creates the GitHub release with the jars attached. It needs the `SONATYPE_USERNAME`,
`SONATYPE_PASSWORD`, `PGP_SECRET` and `PGP_PASSPHRASE` secrets (shared with other metarank repos).

### GPU support

It is possible to force GPU support for a training:
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.metarank</groupId>
<artifactId>lightgbm4j</artifactId>
<version>4.6.0-2</version>
<version>4.6.0-3</version>

<name>LightGBM4j: Java LightGBM wrapper</name>
<description>A high-level wrapper for LightGBM toolkit</description>
Expand Down Expand Up @@ -162,7 +162,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<version>3.2.8</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down
Loading