-
-
Notifications
You must be signed in to change notification settings - Fork 37
216 lines (182 loc) · 6.18 KB
/
java-release.yml
File metadata and controls
216 lines (182 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
name: "[Java] Release"
on:
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-15
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@v6
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
workspaces: |
css-inline
bindings/java
- name: Build native library
working-directory: bindings/java
run: cargo build --release --target ${{ matrix.target }}
- name: Upload native library
uses: actions/upload-artifact@v6
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@v6
- name: Set up Java
uses: actions/setup-java@v5
with:
distribution: "temurin"
java-version: ${{ env.JAVA_VERSION }}
- name: Download all native libraries
uses: actions/download-artifact@v7
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/
gradle build --info
- name: Upload JAR
uses: actions/upload-artifact@v6
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-15
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@v5
with:
distribution: "temurin"
java-version: ${{ env.JAVA_VERSION }}
- name: Download JAR
uses: actions/download-artifact@v7
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) {
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;\"")) {
throw new RuntimeException("Expected inlined style not found in: " + result);
}
System.out.println("✓ Integration test passed on ${{ matrix.platform }}");
}
}
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@v6
- name: Set up Java
uses: actions/setup-java@v5
with:
distribution: "temurin"
java-version: ${{ env.JAVA_VERSION }}
- name: Download JAR artifact
uses: actions/download-artifact@v7
with:
name: java-jar
path: bindings/java/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: gradle publish -Pversion=${{ env.version }}
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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@v7
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