-
Notifications
You must be signed in to change notification settings - Fork 5
315 lines (265 loc) · 9.33 KB
/
Copy pathbindings.yml
File metadata and controls
315 lines (265 loc) · 9.33 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
name: Build and Publish Bindings
on:
workflow_run:
workflows: ["Release"]
types: [completed]
workflow_dispatch:
inputs:
publish:
description: 'Publish to package registries'
required: false
default: 'false'
env:
CARGO_TERM_COLOR: always
jobs:
build-native:
name: Build Native Libraries
# Only run if Release workflow succeeded (or manual trigger)
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact: libunpdf.so
runtime: linux-x64
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
artifact: libunpdf.so
runtime: linux-musl-x64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact: unpdf.dll
runtime: win-x64
- os: macos-latest
target: x86_64-apple-darwin
artifact: libunpdf.dylib
runtime: osx-x64
- os: macos-latest
target: aarch64-apple-darwin
artifact: libunpdf.dylib
runtime: osx-arm64
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install musl-tools
if: contains(matrix.target, 'musl')
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Set RUSTFLAGS for musl
if: contains(matrix.target, 'musl')
run: echo "RUSTFLAGS=-C target-feature=-crt-static" >> $GITHUB_ENV
- name: Build native library
run: cargo build --release --features ffi --target ${{ matrix.target }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: native-${{ matrix.runtime }}
path: target/${{ matrix.target }}/release/${{ matrix.artifact }}
retention-days: 7
build-python:
name: Build Python Wheel
needs: build-native
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Download all native libraries
uses: actions/download-artifact@v4
with:
pattern: native-*
path: native-libs/
- name: Copy native libraries to package
run: |
mkdir -p bindings/python/src/unpdf/lib/linux-x64
mkdir -p bindings/python/src/unpdf/lib/linux-musl-x64
mkdir -p bindings/python/src/unpdf/lib/win-x64
mkdir -p bindings/python/src/unpdf/lib/osx-x64
mkdir -p bindings/python/src/unpdf/lib/osx-arm64
cp native-libs/native-linux-x64/* bindings/python/src/unpdf/lib/linux-x64/
cp native-libs/native-linux-musl-x64/* bindings/python/src/unpdf/lib/linux-musl-x64/
cp native-libs/native-win-x64/* bindings/python/src/unpdf/lib/win-x64/
cp native-libs/native-osx-x64/* bindings/python/src/unpdf/lib/osx-x64/
cp native-libs/native-osx-arm64/* bindings/python/src/unpdf/lib/osx-arm64/
ls -la bindings/python/src/unpdf/lib/*/
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build wheel
- name: Build wheel
working-directory: bindings/python
run: python -m build
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: python-wheel
path: bindings/python/dist/*.whl
retention-days: 7
build-nuget:
name: Build NuGet Package
needs: build-native
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Create runtime directories
run: |
mkdir -p bindings/csharp/Unpdf/runtimes/win-x64/native
mkdir -p bindings/csharp/Unpdf/runtimes/linux-x64/native
mkdir -p bindings/csharp/Unpdf/runtimes/linux-musl-x64/native
mkdir -p bindings/csharp/Unpdf/runtimes/osx-x64/native
mkdir -p bindings/csharp/Unpdf/runtimes/osx-arm64/native
- name: Download Windows native library
uses: actions/download-artifact@v4
with:
name: native-win-x64
path: bindings/csharp/Unpdf/runtimes/win-x64/native/
- name: Download Linux native library
uses: actions/download-artifact@v4
with:
name: native-linux-x64
path: bindings/csharp/Unpdf/runtimes/linux-x64/native/
- name: Download Linux musl native library
uses: actions/download-artifact@v4
with:
name: native-linux-musl-x64
path: bindings/csharp/Unpdf/runtimes/linux-musl-x64/native/
- name: Download macOS x64 native library
uses: actions/download-artifact@v4
with:
name: native-osx-x64
path: bindings/csharp/Unpdf/runtimes/osx-x64/native/
- name: Download macOS ARM64 native library
uses: actions/download-artifact@v4
with:
name: native-osx-arm64
path: bindings/csharp/Unpdf/runtimes/osx-arm64/native/
- name: Build NuGet package
working-directory: bindings/csharp
run: dotnet pack Unpdf/Unpdf.csproj -c Release -o ./artifacts
- name: Upload NuGet package
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: bindings/csharp/artifacts/*.nupkg
retention-days: 7
publish-pypi:
name: Publish to PyPI
needs: build-python
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.inputs.publish == 'true' }}
steps:
- name: Download Python wheel
uses: actions/download-artifact@v4
with:
name: python-wheel
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: dist/
skip-existing: true
publish-nuget:
name: Publish to NuGet
needs: build-nuget
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.inputs.publish == 'true' }}
steps:
- name: Download NuGet package
uses: actions/download-artifact@v4
with:
name: nuget-package
path: ./
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Publish to NuGet
run: dotnet nuget push "*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
test-python:
name: Test Python Bindings
needs: build-python
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.11']
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Download wheel
uses: actions/download-artifact@v4
with:
name: python-wheel
path: ./wheels/
- name: Install package
shell: bash
run: |
pip install pytest
pip install ./wheels/*.whl
- name: Run tests
working-directory: bindings/python
shell: bash
run: pytest tests/ -v --ignore=tests/test_integration.py
test-nuget:
name: Test NuGet Package
needs: build-nuget
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
artifact: native-linux-x64
runtime: linux-x64
- os: windows-latest
artifact: native-win-x64
runtime: win-x64
- os: macos-latest
artifact: native-osx-arm64
runtime: osx-arm64
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Download NuGet package
uses: actions/download-artifact@v4
with:
name: nuget-package
path: ./packages/
- name: Download native library
uses: actions/download-artifact@v4
with:
name: ${{ matrix.artifact }}
path: ./native-lib/
- name: Create local NuGet source
run: dotnet nuget add source "${{ github.workspace }}/packages" -n local
- name: Build test project
working-directory: bindings/csharp
run: dotnet build Unpdf.Tests/Unpdf.Tests.csproj -c Release
- name: Copy native library to test output
shell: bash
run: |
# Find all test output directories and copy native library
find bindings/csharp/Unpdf.Tests/bin/Release -type d -name "net*" | while read dir; do
cp ./native-lib/* "$dir/"
echo "Copied native library to $dir"
done
- name: Run tests
working-directory: bindings/csharp
run: dotnet test Unpdf.Tests/Unpdf.Tests.csproj -c Release --no-build