Skip to content

refactor jar strategy from fatjar to jar by plateform #40

refactor jar strategy from fatjar to jar by plateform

refactor jar strategy from fatjar to jar by plateform #40

name: Build and Publish
on:
push:
tags:
- 'v*'
permissions:
contents: read
jobs:
build-natives:
name: Natives ${{ matrix.platform-id }} (${{ matrix.variant }})
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
platform-id: linux-x64
lib: libflecs.so
variant: release
- os: ubuntu-24.04-arm
platform-id: linux-aarch64
lib: libflecs.so
variant: release
- os: windows-latest
platform-id: windows-x64
lib: flecs.dll
variant: release
- os: macos-13
platform-id: macos-x64
lib: libflecs.dylib
variant: release
- os: macos-latest
platform-id: macos-aarch64
lib: libflecs.dylib
variant: release
- os: ubuntu-latest
platform-id: linux-x64
lib: libflecs.so
variant: debug
- os: ubuntu-24.04-arm
platform-id: linux-aarch64
lib: libflecs.so
variant: debug
- os: windows-latest
platform-id: windows-x64
lib: flecs.dll
variant: debug
- os: macos-13
platform-id: macos-x64
lib: libflecs.dylib
variant: debug
- os: macos-latest
platform-id: macos-aarch64
lib: libflecs.dylib
variant: debug
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up JDK 25
uses: actions/setup-java@v4
with:
java-version: '25'
distribution: 'temurin'
- name: Install GCC (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y gcc build-essential
- name: Install GCC (Windows)
if: runner.os == 'Windows'
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
install: mingw-w64-x86_64-gcc
- name: Grant execute permission for gradlew
if: runner.os != 'Windows'
run: chmod +x gradlew
- name: Compile native (${{ matrix.variant }})
run: >
./gradlew
compileFlecsNative-${{ matrix.platform-id }}-${{ matrix.variant }}
-PNATIVE_ARCH=${{ matrix.platform-id }}
shell: bash
- name: Verify native library
shell: bash
run: |
FILE="build/natives/${{ matrix.platform-id }}/${{ matrix.variant }}/${{ matrix.lib }}"
echo "Checking $FILE ..."
if [ ! -f "$FILE" ]; then
echo "❌ Not found: $FILE"; exit 1
fi
SIZE=$(wc -c < "$FILE")
echo "Size: $SIZE bytes"
if [ "$SIZE" -lt 102400 ]; then
echo "❌ Too small ($SIZE bytes, expected ≥ 102400)"; exit 1
fi
echo "✅ OK"
ls -lh "$FILE"
- name: Upload native artifact
uses: actions/upload-artifact@v4
with:
name: native-${{ matrix.platform-id }}-${{ matrix.variant }}
path: build/natives/${{ matrix.platform-id }}/${{ matrix.variant }}/${{ matrix.lib }}
retention-days: 1
publish:
name: Publish to Maven Central
needs: build-natives
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 25
uses: actions/setup-java@v4
with:
java-version: '25'
distribution: 'temurin'
- name: Download all native artifacts
uses: actions/download-artifact@v4
with:
pattern: native-*
path: downloaded-natives
merge-multiple: false
- name: Place natives in build/natives/
shell: bash
run: |
# Structure attendue par les tâches jarNatives-* :
# build/natives/<platform-id>/<variant>/<libName>
echo "=== Downloaded artifacts ==="
find downloaded-natives -type f | sort
for artifact_dir in downloaded-natives/native-*/; do
# artifact_dir = downloaded-natives/native-linux-x64-release/
basename=$(basename "$artifact_dir") # native-linux-x64-release
rest=${basename#native-} # linux-x64-release
variant=${rest##*-} # release (ou debug)
platform=${rest%-$variant} # linux-x64
dest="build/natives/$platform/$variant"
mkdir -p "$dest"
cp "$artifact_dir"/* "$dest/"
echo "✅ $platform/$variant → $dest"
done
echo ""
echo "=== Final tree ==="
find build/natives -type f | sort
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build JAR (API + processor, sans natifs embarqués)
run: ./gradlew jar sourcesJar javadocJar -x compileFlecsNative -x extractFlecs -x downloadFlecs
- name: Build all native JARs
run: ./gradlew $(./gradlew tasks --quiet | grep "^jarNatives-" | awk '{print $1}' | tr '\n' ' ')
- name: Verify JAR contents
shell: bash
run: |
VERSION=${GITHUB_REF_NAME#v}
JAR="build/libs/flecs-java-$VERSION.jar"
echo "=== Main JAR: $JAR ==="
jar tf "$JAR" | grep "natives/" | sort && echo "(no natives expected)" || true
echo ""
echo "=== Native JARs ==="
for f in build/libs/flecs-java-$VERSION-natives-*.jar; do
echo "--- $f ---"
jar tf "$f" | grep "natives/"
done
echo ""
echo "Verifying all expected classifiers..."
EXPECTED=(
"natives-linux-x64"
"natives-linux-aarch64"
"natives-windows-x64"
"natives-macos-x64"
"natives-macos-aarch64"
"natives-linux-x64-debug"
"natives-linux-aarch64-debug"
"natives-windows-x64-debug"
"natives-macos-x64-debug"
"natives-macos-aarch64-debug"
)
ALL_OK=true
for classifier in "${EXPECTED[@]}"; do
f="build/libs/flecs-java-$VERSION-$classifier.jar"
if [ -f "$f" ]; then
echo "✅ $classifier"
else
echo "❌ $classifier — MISSING"
ALL_OK=false
fi
done
$ALL_OK || exit 1
- name: Publish to Maven Central
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository