|
| 1 | +name: "[Java] Release" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - java-v* |
| 7 | + |
| 8 | +defaults: |
| 9 | + run: |
| 10 | + shell: bash |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +env: |
| 17 | + JAVA_VERSION: "17" |
| 18 | + |
| 19 | +jobs: |
| 20 | + build-native-libraries: |
| 21 | + strategy: |
| 22 | + matrix: |
| 23 | + include: |
| 24 | + - os: ubuntu-22.04 |
| 25 | + target: x86_64-unknown-linux-gnu |
| 26 | + lib: libcss_inline.so |
| 27 | + platform: linux-x86_64 |
| 28 | + |
| 29 | + - os: macos-13 |
| 30 | + target: x86_64-apple-darwin |
| 31 | + lib: libcss_inline.dylib |
| 32 | + platform: darwin-x86_64 |
| 33 | + - os: macos-14 |
| 34 | + target: aarch64-apple-darwin |
| 35 | + lib: libcss_inline.dylib |
| 36 | + platform: darwin-aarch64 |
| 37 | + |
| 38 | + - os: windows-2022 |
| 39 | + target: x86_64-pc-windows-msvc |
| 40 | + lib: css_inline.dll |
| 41 | + platform: win32-x86_64 |
| 42 | + |
| 43 | + name: Build native library for ${{ matrix.target }} |
| 44 | + runs-on: ${{ matrix.os }} |
| 45 | + steps: |
| 46 | + - uses: actions/checkout@v4 |
| 47 | + |
| 48 | + - uses: dtolnay/rust-toolchain@stable |
| 49 | + with: |
| 50 | + targets: ${{ matrix.target }} |
| 51 | + |
| 52 | + - uses: Swatinem/rust-cache@v2 |
| 53 | + with: |
| 54 | + workspaces: | |
| 55 | + css-inline |
| 56 | + bindings/java |
| 57 | +
|
| 58 | + - name: Build native library |
| 59 | + working-directory: bindings/java |
| 60 | + run: cargo build --release --target ${{ matrix.target }} |
| 61 | + |
| 62 | + - name: Upload native library |
| 63 | + uses: actions/upload-artifact@v4 |
| 64 | + with: |
| 65 | + name: native-${{ matrix.platform }} |
| 66 | + if-no-files-found: error |
| 67 | + path: bindings/java/target/${{ matrix.target }}/release/${{ matrix.lib }} |
| 68 | + |
| 69 | + build-jar: |
| 70 | + name: Build JAR file |
| 71 | + runs-on: ubuntu-22.04 |
| 72 | + needs: build-native-libraries |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v4 |
| 75 | + |
| 76 | + - name: Set up Java |
| 77 | + uses: actions/setup-java@v4 |
| 78 | + with: |
| 79 | + distribution: "temurin" |
| 80 | + java-version: ${{ env.JAVA_VERSION }} |
| 81 | + |
| 82 | + - name: Download all native libraries |
| 83 | + uses: actions/download-artifact@v4 |
| 84 | + with: |
| 85 | + path: native-libs |
| 86 | + |
| 87 | + - name: Assemble JAR with native libraries |
| 88 | + working-directory: bindings/java |
| 89 | + run: | |
| 90 | + mkdir -p src/main/resources/org/cssinline/native/{linux-x86_64,darwin-x86_64,darwin-aarch64,win32-x86_64} |
| 91 | +
|
| 92 | + # Copy native libraries to their expected location |
| 93 | + cp ../../native-libs/native-linux-x86_64/libcss_inline.so src/main/resources/org/cssinline/native/linux-x86_64/ |
| 94 | + cp ../../native-libs/native-darwin-x86_64/libcss_inline.dylib src/main/resources/org/cssinline/native/darwin-x86_64/ |
| 95 | + cp ../../native-libs/native-darwin-aarch64/libcss_inline.dylib src/main/resources/org/cssinline/native/darwin-aarch64/ |
| 96 | + cp ../../native-libs/native-win32-x86_64/css_inline.dll src/main/resources/org/cssinline/native/win32-x86_64/ |
| 97 | +
|
| 98 | + gradle build --info |
| 99 | +
|
| 100 | + - name: Upload JAR |
| 101 | + uses: actions/upload-artifact@v4 |
| 102 | + with: |
| 103 | + name: java-jar |
| 104 | + if-no-files-found: error |
| 105 | + path: bindings/java/build/libs/*.jar |
| 106 | + |
| 107 | + test-jar: |
| 108 | + needs: build-jar |
| 109 | + strategy: |
| 110 | + matrix: |
| 111 | + include: |
| 112 | + - os: ubuntu-22.04 |
| 113 | + platform: linux-x86_64 |
| 114 | + - os: macos-13 |
| 115 | + platform: darwin-x86_64 |
| 116 | + - os: macos-14 |
| 117 | + platform: darwin-aarch64 |
| 118 | + - os: windows-2022 |
| 119 | + platform: win32-x86_64 |
| 120 | + |
| 121 | + name: Test JAR on ${{ matrix.platform }} |
| 122 | + runs-on: ${{ matrix.os }} |
| 123 | + steps: |
| 124 | + - name: Set up Java |
| 125 | + uses: actions/setup-java@v4 |
| 126 | + with: |
| 127 | + distribution: "temurin" |
| 128 | + java-version: ${{ env.JAVA_VERSION }} |
| 129 | + |
| 130 | + - name: Download JAR |
| 131 | + uses: actions/download-artifact@v4 |
| 132 | + with: |
| 133 | + name: java-jar |
| 134 | + |
| 135 | + - name: Integration test on ${{ matrix.platform }} |
| 136 | + run: | |
| 137 | + cat > Test.java << 'EOF' |
| 138 | + import org.cssinline.CssInline; |
| 139 | + public class Test { |
| 140 | + public static void main(String[] args) { |
| 141 | + String html = "<html><head><style>h1{color:red}</style></head><body><h1>Test</h1></body></html>"; |
| 142 | + String result = CssInline.inline(html); |
| 143 | + if (!result.contains("style=\"color: red;\"")) { |
| 144 | + throw new RuntimeException("Expected inlined style not found in: " + result); |
| 145 | + } |
| 146 | + System.out.println("✓ Integration test passed on ${{ matrix.platform }}"); |
| 147 | + } |
| 148 | + } |
| 149 | + EOF |
| 150 | +
|
| 151 | + JAR_FILE=$(ls *.jar) |
| 152 | +
|
| 153 | + if [[ "$RUNNER_OS" == "Windows" ]]; then |
| 154 | + CLASSPATH_SEP=";" |
| 155 | + else |
| 156 | + CLASSPATH_SEP=":" |
| 157 | + fi |
| 158 | +
|
| 159 | + javac -cp "$JAR_FILE" Test.java |
| 160 | + java -cp "$JAR_FILE${CLASSPATH_SEP}." Test |
| 161 | +
|
| 162 | + publish-github-packages: |
| 163 | + name: Publish to GitHub Packages |
| 164 | + runs-on: ubuntu-22.04 |
| 165 | + needs: [build-jar, test-jar] |
| 166 | + if: startsWith(github.ref, 'refs/tags/java-v') |
| 167 | + permissions: |
| 168 | + contents: read |
| 169 | + packages: write |
| 170 | + steps: |
| 171 | + - uses: actions/checkout@v4 |
| 172 | + |
| 173 | + - name: Set up Java |
| 174 | + uses: actions/setup-java@v4 |
| 175 | + with: |
| 176 | + distribution: "temurin" |
| 177 | + java-version: ${{ env.JAVA_VERSION }} |
| 178 | + |
| 179 | + - name: Download JAR artifact |
| 180 | + uses: actions/download-artifact@v4 |
| 181 | + with: |
| 182 | + name: java-jar |
| 183 | + path: bindings/java/build/libs |
| 184 | + |
| 185 | + - name: Extract version |
| 186 | + run: echo "version=${GITHUB_REF#refs/tags/java-v}" >> $GITHUB_ENV |
| 187 | + |
| 188 | + - name: Publish to GitHub Packages |
| 189 | + working-directory: bindings/java |
| 190 | + run: gradle publish -Pversion=${{ env.version }} |
| 191 | + env: |
| 192 | + GITHUB_ACTOR: ${{ github.actor }} |
| 193 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 194 | + |
| 195 | + release: |
| 196 | + name: Create GitHub Release |
| 197 | + runs-on: ubuntu-22.04 |
| 198 | + needs: [build-jar, test-jar, publish-github-packages] |
| 199 | + if: startsWith(github.ref, 'refs/tags/java-v') |
| 200 | + steps: |
| 201 | + - name: Download JAR |
| 202 | + uses: actions/download-artifact@v4 |
| 203 | + with: |
| 204 | + name: java-jar |
| 205 | + path: dist |
| 206 | + |
| 207 | + - name: Extract version |
| 208 | + run: echo "version=${GITHUB_REF#refs/tags/java-v}" >> $GITHUB_ENV |
| 209 | + |
| 210 | + - name: GitHub Release |
| 211 | + uses: softprops/action-gh-release@v2 |
| 212 | + with: |
| 213 | + make_latest: false |
| 214 | + draft: true |
| 215 | + name: "[Java] Release ${{ env.version }}" |
| 216 | + files: dist/*.jar |
0 commit comments