|
| 1 | +name: "[Java] Release" |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: {} |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - java-v* |
| 8 | + |
| 9 | +defaults: |
| 10 | + run: |
| 11 | + shell: bash |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +env: |
| 18 | + JAVA_VERSION: "21" |
| 19 | + |
| 20 | +jobs: |
| 21 | + build-native-libs: |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + include: |
| 25 | + - os: ubuntu-22.04 |
| 26 | + target: x86_64-unknown-linux-gnu |
| 27 | + lib: libcss_inline.so |
| 28 | + platform: linux-x86_64 |
| 29 | + - os: ubuntu-22.04 |
| 30 | + target: aarch64-unknown-linux-gnu |
| 31 | + lib: libcss_inline.so |
| 32 | + platform: linux-aarch64 |
| 33 | + cross: true |
| 34 | + |
| 35 | + - os: macos-13 |
| 36 | + target: x86_64-apple-darwin |
| 37 | + lib: libcss_inline.dylib |
| 38 | + platform: darwin-x86_64 |
| 39 | + - os: macos-14 |
| 40 | + target: aarch64-apple-darwin |
| 41 | + lib: libcss_inline.dylib |
| 42 | + platform: darwin-aarch64 |
| 43 | + |
| 44 | + - os: windows-2022 |
| 45 | + target: x86_64-pc-windows-msvc |
| 46 | + lib: css_inline.dll |
| 47 | + platform: win32-x86_64 |
| 48 | + |
| 49 | + runs-on: ${{ matrix.os }} |
| 50 | + steps: |
| 51 | + - uses: actions/checkout@v4 |
| 52 | + |
| 53 | + - uses: dtolnay/rust-toolchain@master |
| 54 | + with: |
| 55 | + toolchain: stable |
| 56 | + targets: ${{ matrix.target }} |
| 57 | + |
| 58 | + - name: Install cross |
| 59 | + if: matrix.cross |
| 60 | + run: cargo install cross --git https://github.com/cross-rs/cross |
| 61 | + |
| 62 | + - name: Build native library |
| 63 | + working-directory: bindings/java |
| 64 | + run: | |
| 65 | + if [ "${{ matrix.cross }}" = "true" ]; then |
| 66 | + cross build --release --target ${{ matrix.target }} |
| 67 | + else |
| 68 | + cargo build --release --target ${{ matrix.target }} |
| 69 | + fi |
| 70 | +
|
| 71 | + - name: Upload native library |
| 72 | + uses: actions/upload-artifact@v4 |
| 73 | + with: |
| 74 | + name: native-${{ matrix.platform }} |
| 75 | + if-no-files-found: error |
| 76 | + path: bindings/java/target/${{ matrix.target }}/release/${{ matrix.lib }} |
| 77 | + |
| 78 | + build-jar: |
| 79 | + runs-on: ubuntu-22.04 |
| 80 | + needs: build-native-libs |
| 81 | + steps: |
| 82 | + - uses: actions/checkout@v4 |
| 83 | + |
| 84 | + - name: Set up Java |
| 85 | + uses: actions/setup-java@v4 |
| 86 | + with: |
| 87 | + distribution: "temurin" |
| 88 | + java-version: ${{ env.JAVA_VERSION }} |
| 89 | + |
| 90 | + - name: Download all native libraries |
| 91 | + uses: actions/download-artifact@v4 |
| 92 | + with: |
| 93 | + path: native-libs |
| 94 | + |
| 95 | + - name: Assemble JAR with native libraries |
| 96 | + working-directory: bindings/java |
| 97 | + run: | |
| 98 | + # Create resources directory structure |
| 99 | + mkdir -p src/main/resources/org/cssinline/native/{linux-x86_64,linux-aarch64,darwin-x86_64,darwin-aarch64,win32-x86_64} |
| 100 | +
|
| 101 | + # Copy native libraries to correct locations |
| 102 | + cp ../../native-libs/native-linux-x86_64/libcss_inline.so src/main/resources/org/cssinline/native/linux-x86_64/ |
| 103 | + cp ../../native-libs/native-linux-aarch64/libcss_inline.so src/main/resources/org/cssinline/native/linux-aarch64/ |
| 104 | + cp ../../native-libs/native-darwin-x86_64/libcss_inline.dylib src/main/resources/org/cssinline/native/darwin-x86_64/ |
| 105 | + cp ../../native-libs/native-darwin-aarch64/libcss_inline.dylib src/main/resources/org/cssinline/native/darwin-aarch64/ |
| 106 | + cp ../../native-libs/native-win32-x86_64/css_inline.dll src/main/resources/org/cssinline/native/win32-x86_64/ |
| 107 | +
|
| 108 | + # Extract version from tag |
| 109 | + echo "VERSION=${GITHUB_REF#refs/tags/java-v}" >> $GITHUB_ENV |
| 110 | +
|
| 111 | + # Build JAR |
| 112 | + gradle build -Pversion=${{ env.VERSION }} |
| 113 | +
|
| 114 | + - name: Upload JAR artifact |
| 115 | + uses: actions/upload-artifact@v4 |
| 116 | + with: |
| 117 | + name: java-jar |
| 118 | + if-no-files-found: error |
| 119 | + path: bindings/java/build/libs/*.jar |
| 120 | + |
| 121 | + test-jar: |
| 122 | + needs: build-jar |
| 123 | + strategy: |
| 124 | + matrix: |
| 125 | + include: |
| 126 | + - os: ubuntu-22.04 |
| 127 | + platform: linux |
| 128 | + - os: macos-13 |
| 129 | + platform: darwin-x86_64 |
| 130 | + - os: macos-14 |
| 131 | + platform: darwin-aarch64 |
| 132 | + - os: windows-2022 |
| 133 | + platform: windows |
| 134 | + |
| 135 | + runs-on: ${{ matrix.os }} |
| 136 | + steps: |
| 137 | + - uses: actions/checkout@v4 |
| 138 | + |
| 139 | + - name: Set up Java |
| 140 | + uses: actions/setup-java@v4 |
| 141 | + with: |
| 142 | + distribution: "temurin" |
| 143 | + java-version: ${{ env.JAVA_VERSION }} |
| 144 | + |
| 145 | + - name: Download JAR |
| 146 | + uses: actions/download-artifact@v4 |
| 147 | + with: |
| 148 | + name: java-jar |
| 149 | + path: jars |
| 150 | + |
| 151 | + - name: Test JAR on ${{ matrix.platform }} |
| 152 | + working-directory: bindings/java |
| 153 | + run: | |
| 154 | + # Copy JAR to build/libs for gradle to find |
| 155 | + mkdir -p build/libs |
| 156 | + cp ../../jars/*.jar build/libs/ |
| 157 | +
|
| 158 | + # Run tests to verify native library loads and works |
| 159 | + gradle test --info |
| 160 | +
|
| 161 | + - name: Integration test |
| 162 | + working-directory: bindings/java |
| 163 | + run: | |
| 164 | + java -cp "build/libs/*:build/classes/java/main" -c " |
| 165 | + import org.cssinline.CssInline; |
| 166 | + String result = CssInline.inline(\"<style>h1{color:red}</style><h1>Test</h1>\"); |
| 167 | + if (!result.contains(\"style=\\\"color: red;\\\"\")) { |
| 168 | + System.exit(1); |
| 169 | + } |
| 170 | + System.out.println(\"✓ Integration test passed on ${{ matrix.platform }}\"); |
| 171 | + " |
0 commit comments