feat: Java bindings #1
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: "21" | |
| jobs: | |
| build-native-libs: | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-22.04 | |
| target: x86_64-unknown-linux-gnu | |
| lib: libcss_inline.so | |
| platform: linux-x86_64 | |
| - os: ubuntu-22.04 | |
| target: aarch64-unknown-linux-gnu | |
| lib: libcss_inline.so | |
| platform: linux-aarch64 | |
| cross: true | |
| - 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 | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@master | |
| with: | |
| toolchain: stable | |
| targets: ${{ matrix.target }} | |
| - name: Install cross | |
| if: matrix.cross | |
| run: cargo install cross --git https://github.com/cross-rs/cross | |
| - name: Build native library | |
| working-directory: bindings/java | |
| run: | | |
| if [ "${{ matrix.cross }}" = "true" ]; then | |
| cross build --release --target ${{ matrix.target }} | |
| else | |
| cargo build --release --target ${{ matrix.target }} | |
| fi | |
| - 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: | |
| runs-on: ubuntu-22.04 | |
| needs: build-native-libs | |
| 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: | | |
| # Create resources directory structure | |
| mkdir -p src/main/resources/org/cssinline/native/{linux-x86_64,linux-aarch64,darwin-x86_64,darwin-aarch64,win32-x86_64} | |
| # Copy native libraries to correct locations | |
| cp ../../native-libs/native-linux-x86_64/libcss_inline.so src/main/resources/org/cssinline/native/linux-x86_64/ | |
| cp ../../native-libs/native-linux-aarch64/libcss_inline.so src/main/resources/org/cssinline/native/linux-aarch64/ | |
| 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/ | |
| # Extract version from tag | |
| echo "VERSION=${GITHUB_REF#refs/tags/java-v}" >> $GITHUB_ENV | |
| # Build JAR | |
| gradle build -Pversion=${{ env.VERSION }} | |
| - name: Upload JAR artifact | |
| 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 | |
| - os: macos-13 | |
| platform: darwin-x86_64 | |
| - os: macos-14 | |
| platform: darwin-aarch64 | |
| - os: windows-2022 | |
| platform: windows | |
| runs-on: ${{ matrix.os }} | |
| 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 | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: java-jar | |
| path: jars | |
| - name: Test JAR on ${{ matrix.platform }} | |
| working-directory: bindings/java | |
| run: | | |
| # Copy JAR to build/libs for gradle to find | |
| mkdir -p build/libs | |
| cp ../../jars/*.jar build/libs/ | |
| # Run tests to verify native library loads and works | |
| gradle test --info | |
| - name: Integration test | |
| working-directory: bindings/java | |
| run: | | |
| java -cp "build/libs/*:build/classes/java/main" -c " | |
| import org.cssinline.CssInline; | |
| String result = CssInline.inline(\"<style>h1{color:red}</style><h1>Test</h1>\"); | |
| if (!result.contains(\"style=\\\"color: red;\\\"\")) { | |
| System.exit(1); | |
| } | |
| System.out.println(\"✓ Integration test passed on ${{ matrix.platform }}\"); | |
| " |