feat: Java bindings #21
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "[Java] Release" | |
on: | |
pull_request: {} | |
push: | |
tags: | |
- java-v* | |
defaults: | |
run: | |
shell: bash | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
JAVA_VERSION: "17" | |
jobs: | |
build-native-libraries: | |
strategy: | |
matrix: | |
include: | |
- os: ubuntu-22.04 | |
target: x86_64-unknown-linux-gnu | |
lib: libcss_inline.so | |
platform: linux-x86_64 | |
- os: macos-13 | |
target: x86_64-apple-darwin | |
lib: libcss_inline.dylib | |
platform: darwin-x86_64 | |
- os: macos-14 | |
target: aarch64-apple-darwin | |
lib: libcss_inline.dylib | |
platform: darwin-aarch64 | |
- os: windows-2022 | |
target: x86_64-pc-windows-msvc | |
lib: css_inline.dll | |
platform: win32-x86_64 | |
name: Build native library for ${{ matrix.target }} | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: ${{ matrix.target }} | |
- name: Build native library | |
working-directory: bindings/java | |
run: cargo build --release --target ${{ matrix.target }} | |
- name: Upload native library | |
uses: actions/upload-artifact@v4 | |
with: | |
name: native-${{ matrix.platform }} | |
if-no-files-found: error | |
path: bindings/java/target/${{ matrix.target }}/release/${{ matrix.lib }} | |
build-jar: | |
name: Build JAR file | |
runs-on: ubuntu-22.04 | |
needs: build-native-libraries | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: "temurin" | |
java-version: ${{ env.JAVA_VERSION }} | |
- name: Download all native libraries | |
uses: actions/download-artifact@v4 | |
with: | |
path: native-libs | |
- name: Assemble JAR with native libraries | |
working-directory: bindings/java | |
run: | | |
mkdir -p src/main/resources/org/cssinline/native/{linux-x86_64,darwin-x86_64,darwin-aarch64,win32-x86_64} | |
# Copy native libraries to their expected location | |
cp ../../native-libs/native-linux-x86_64/libcss_inline.so src/main/resources/org/cssinline/native/linux-x86_64/ | |
cp ../../native-libs/native-darwin-x86_64/libcss_inline.dylib src/main/resources/org/cssinline/native/darwin-x86_64/ | |
cp ../../native-libs/native-darwin-aarch64/libcss_inline.dylib src/main/resources/org/cssinline/native/darwin-aarch64/ | |
cp ../../native-libs/native-win32-x86_64/css_inline.dll src/main/resources/org/cssinline/native/win32-x86_64/ | |
echo "=== Gradle version and Java info ===" | |
gradle --version | |
echo "=== Source files ===" | |
find src/main/java -name "*.java" | |
echo "=== Compile Java only first ===" | |
gradle compileJava --stacktrace --info | |
echo "=== Check compiled classes ===" | |
find build/classes -name "*.class" 2>/dev/null || echo "No compiled classes found!" | |
echo "=== Full build ===" | |
gradle build --stacktrace --info | |
echo "=== After gradle build ===" | |
ls -la build/libs/ || echo "No build/libs directory" | |
- name: Verify JAR contents | |
working-directory: bindings/java | |
run: | | |
echo "=== Built JARs ===" | |
ls -la build/libs/ | |
# Get the main JAR (not sources or javadoc) | |
MAIN_JAR=$(ls build/libs/css-inline-*-SNAPSHOT.jar | grep -v sources | grep -v javadoc) | |
echo "=== Checking main JAR: $MAIN_JAR ===" | |
echo "=== JAR contents (first 30 lines) ===" | |
jar tf "$MAIN_JAR" | head -30 | |
echo "=== Looking for CssInline class ===" | |
if jar tf "$MAIN_JAR" | grep -q "org/cssinline/CssInline.class"; then | |
echo "✅ CssInline.class found" | |
else | |
echo "❌ CssInline.class NOT found!" | |
echo "=== All .class files in JAR ===" | |
jar tf "$MAIN_JAR" | grep "\.class$" || echo "No .class files found!" | |
exit 1 | |
fi | |
echo "=== Looking for native libraries ===" | |
jar tf "$MAIN_JAR" | grep -E "\.(so|dylib|dll)$" || echo "No native libraries found" | |
echo "=== Classes found in main JAR ===" | |
jar tf "$MAIN_JAR" | grep "\.class$" | wc -l | |
echo "=== Native libs found in main JAR ===" | |
jar tf "$MAIN_JAR" | grep -E "\.(so|dylib|dll)$" | wc -l | |
- name: Upload JAR | |
uses: actions/upload-artifact@v4 | |
with: | |
name: java-jar | |
if-no-files-found: error | |
path: bindings/java/build/libs/*.jar | |
test-jar: | |
needs: build-jar | |
strategy: | |
matrix: | |
include: | |
- os: ubuntu-22.04 | |
platform: linux-x86_64 | |
- os: macos-13 | |
platform: darwin-x86_64 | |
- os: macos-14 | |
platform: darwin-aarch64 | |
- os: windows-2022 | |
platform: win32-x86_64 | |
name: Test JAR on ${{ matrix.platform }} | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Set up Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: "temurin" | |
java-version: ${{ env.JAVA_VERSION }} | |
- name: Download JAR | |
uses: actions/download-artifact@v4 | |
with: | |
name: java-jar | |
- name: Integration test on ${{ matrix.platform }} | |
run: | | |
cat > Test.java << 'EOF' | |
import org.cssinline.CssInline; | |
public class Test { | |
public static void main(String[] args) { | |
try { | |
String html = "<html><head><style>h1{color:red}</style></head><body><h1>Test</h1></body></html>"; | |
String result = CssInline.inline(html); | |
if (!result.contains("style=\"color: red;\"")) { | |
System.err.println("Expected inlined style not found in: " + result); | |
System.exit(1); | |
} | |
System.out.println("✓ Integration test passed on ${{ matrix.platform }}"); | |
} catch (Exception e) { | |
System.err.println("Integration test failed: " + e.getMessage()); | |
e.printStackTrace(); | |
System.exit(1); | |
} | |
} | |
} | |
EOF | |
JAR_FILE=$(ls *.jar) | |
if [[ "$RUNNER_OS" == "Windows" ]]; then | |
CLASSPATH_SEP=";" | |
else | |
CLASSPATH_SEP=":" | |
fi | |
javac -cp "$JAR_FILE" Test.java | |
java -cp "$JAR_FILE${CLASSPATH_SEP}." Test | |
publish-github-packages: | |
name: Publish to GitHub Packages | |
runs-on: ubuntu-22.04 | |
needs: [build-jar, test-jar] | |
if: startsWith(github.ref, 'refs/tags/java-v') | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: "temurin" | |
java-version: ${{ env.JAVA_VERSION }} | |
- name: Download JAR artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: java-jar | |
path: build/libs | |
- name: Extract version | |
run: echo "version=${GITHUB_REF#refs/tags/java-v}" >> $GITHUB_ENV | |
- name: Publish to GitHub Packages | |
working-directory: bindings/java | |
run: | | |
# Copy the pre-built JAR to the expected location | |
mkdir -p build/libs | |
cp ../../build/libs/*.jar build/libs/ | |
# Publish using the existing JAR | |
gradle publish -Pversion=${{ env.version }} | |
env: | |
GITHUB_ACTOR: ${{ github.actor }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
VERSION: ${{ env.version }} | |
release: | |
name: Create GitHub Release | |
runs-on: ubuntu-22.04 | |
needs: [build-jar, test-jar, publish-github-packages] | |
if: startsWith(github.ref, 'refs/tags/java-v') | |
steps: | |
- name: Download JAR | |
uses: actions/download-artifact@v4 | |
with: | |
name: java-jar | |
path: dist | |
- name: Extract version | |
run: echo "version=${GITHUB_REF#refs/tags/java-v}" >> $GITHUB_ENV | |
- name: GitHub Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
make_latest: false | |
draft: true | |
name: "[Java] Release ${{ env.version }}" | |
files: dist/*.jar |