-
Notifications
You must be signed in to change notification settings - Fork 24
499 lines (432 loc) · 15 KB
/
build.yml
File metadata and controls
499 lines (432 loc) · 15 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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
name: Build
on:
pull_request:
types:
- opened
- reopened
- synchronize
- labeled
push:
branches:
- main
tags:
- "*"
workflow_dispatch:
inputs:
publish:
description: 'Publish'
required: true
default: 'false'
permissions:
contents: read
packages: read
actions: read
jobs:
read-version:
name: Read C2PA version
runs-on: ubuntu-latest
outputs:
c2pa-native-version: ${{ steps.read-version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Read version from file
id: read-version
run: echo "version=$(cat c2pa-native-version.txt | tr -d '\r\n')" >> $GITHUB_OUTPUT
check-format:
name: Check code format
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install development dependencies
run: python -m pip install -r requirements-dev.txt
- name: Check Python syntax
run: python3 -m py_compile src/c2pa/c2pa.py
continue-on-error: true
- name: Check code style with flake8
run: flake8 src/c2pa/c2pa.py
continue-on-error: true
tests-unix:
name: Unit tests for developer setup (Unix)
needs: read-version
if: |
github.event_name != 'pull_request' ||
github.event.pull_request.author_association == 'COLLABORATOR' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.user.login == 'dependabot[bot]' ||
contains(github.event.pull_request.labels.*.name, 'safe to test')
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ macos-latest, ubuntu-latest, ubuntu-24.04-arm ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
- name: Install project dependencies
run: python -m pip install -r requirements.txt
- name: Install project development dependencies
run: python -m pip install -r requirements-dev.txt
- name: Prepare build directories
run: |
mkdir -p artifacts
mkdir -p src/c2pa/libs
rm -rf dist/* build/*
- name: Download native artifacts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Ensure the token is being used
echo "Using GitHub token for authentication"
python3 scripts/download_artifacts.py ${{ needs.read-version.outputs.c2pa-native-version }}
- name: Install package in development mode
run: |
pip uninstall -y c2pa
pip install -e .
- name: Verify installation
run: |
python3 -c "from c2pa import C2paError; print('C2paError imported successfully')"
- name: Run tests
run: python3 ./tests/test_unit_tests.py
tests-windows:
name: Unit tests for developer setup (Windows)
needs: read-version
if: |
github.event_name != 'pull_request' ||
github.event.pull_request.author_association == 'COLLABORATOR' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.user.login == 'dependabot[bot]' ||
contains(github.event.pull_request.labels.*.name, 'safe to test')
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
- name: Install project dependencies
run: python -m pip install -r requirements.txt
- name: Install project development dependencies
run: python -m pip install -r requirements-dev.txt
- name: Prepare build directories
run: |
New-Item -ItemType Directory -Force -Path artifacts
New-Item -ItemType Directory -Force -Path src\c2pa\libs
if (Test-Path dist) { Remove-Item -Recurse -Force dist }
if (Test-Path build) { Remove-Item -Recurse -Force build }
- name: Check GitHub API rate limit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Checking GitHub API rate limit..."
curl -s -H "Authorization: token $env:GITHUB_TOKEN" https://api.github.com/rate_limit
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to check rate limit"
exit 1
}
- name: Download native artifacts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Ensure the token is being used
echo "Using GitHub token for authentication"
python scripts\download_artifacts.py ${{ needs.read-version.outputs.c2pa-native-version }}
- name: Install package in development mode
run: |
pip uninstall -y c2pa
pip install -e .
- name: Verify installation
run: |
python -c "from c2pa import C2paError; print('C2paError imported successfully')"
- name: Run tests
run: python .\tests\test_unit_tests.py
build-linux-wheel:
name: Build Linux wheel
uses: ./.github/workflows/build-wheel.yml
needs: [tests-unix, read-version]
with:
python-version: "3.10"
architecture: ${{ matrix.target }}
artifact-name: wheels-linux-${{ matrix.target }}
runs-on: ${{ matrix.runs-on }}
c2pa-version: ${{ needs.read-version.outputs.c2pa-native-version }}
secrets:
github-token: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
include:
- target: x86_64
runs-on: ubuntu-24.04
- target: aarch64
runs-on: ubuntu-24.04-arm
if: |
github.event_name != 'pull_request' ||
github.event.pull_request.author_association == 'COLLABORATOR' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.user.login == 'dependabot[bot]' ||
contains(github.event.pull_request.labels.*.name, 'safe to test')
test-built-linux-wheel:
name: Test Linux built wheel
needs: build-linux-wheel
runs-on: ${{ matrix.runs-on }}
strategy:
matrix:
include:
- target: x86_64
runs-on: ubuntu-24.04
- target: aarch64
runs-on: ubuntu-24.04-arm
if: |
github.event_name != 'pull_request' ||
github.event.pull_request.author_association == 'COLLABORATOR' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.user.login == 'dependabot[bot]' ||
contains(github.event.pull_request.labels.*.name, 'safe to test')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
- name: Download wheel artifacts
uses: actions/download-artifact@v4
with:
name: wheels-linux-${{ matrix.target }}
path: dist
- name: Create and activate virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install wheel for testing
run: |
source venv/bin/activate
pip install dist/c2pa_python-*.whl
- name: Run unittest tests on installed wheel
run: |
source venv/bin/activate
python ./tests/test_unit_tests.py
- name: Install pytest (in venv)
run: |
source venv/bin/activate
pip install pytest
- name: Run tests with pytest (venv)
run: |
source venv/bin/activate
venv/bin/pytest tests/test_unit_tests.py -v
build-windows-wheel:
name: Build Windows wheel
uses: ./.github/workflows/build-wheel.yml
needs: [tests-windows, read-version]
with:
python-version: "3.10"
architecture: ${{ matrix.target }}
artifact-name: wheels-windows-${{ matrix.target }}
runs-on: windows-latest
c2pa-version: ${{ needs.read-version.outputs.c2pa-native-version }}
secrets:
github-token: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
target: [x64]
if: |
github.event_name != 'pull_request' ||
github.event.pull_request.author_association == 'COLLABORATOR' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.user.login == 'dependabot[bot]' ||
contains(github.event.pull_request.labels.*.name, 'safe to test')
test-built-windows-wheel:
name: Test Windows built wheel
needs: build-windows-wheel
runs-on: windows-latest
strategy:
matrix:
target: [x64]
if: |
github.event_name != 'pull_request' ||
github.event.pull_request.author_association == 'COLLABORATOR' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.user.login == 'dependabot[bot]' ||
contains(github.event.pull_request.labels.*.name, 'safe to test')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
- name: Download wheel artifacts
uses: actions/download-artifact@v4
with:
name: wheels-windows-${{ matrix.target }}
path: dist
- name: Create and activate virtual environment
run: |
python -m venv venv
.\venv\Scripts\activate
- name: Install wheel for testing
run: |
.\venv\Scripts\activate
$wheel = Get-ChildItem -Path dist -Filter "c2pa_python-*.whl" | Select-Object -First 1
if (-not $wheel) { Write-Error "No wheel file found in dist directory"; exit 1 }
pip install $wheel.FullName
- name: Run unittest tests on installed wheel
run: |
.\venv\Scripts\activate
python .\tests\test_unit_tests.py
- name: Install pytest (in venv)
run: |
.\venv\Scripts\activate
pip install pytest
- name: Run tests with pytest (venv)
run: |
.\venv\Scripts\activate
.\venv\Scripts\pytest .\tests\test_unit_tests.py -v
build-macos-wheel:
name: Build macOS wheels
uses: ./.github/workflows/build-wheel.yml
needs: [tests-unix, read-version]
with:
python-version: "3.10"
runs-on: ${{ matrix.runs-on }}
artifact-name: wheels-macos-${{ matrix.target }}
architecture: ${{ matrix.target }}
c2pa-version: ${{ needs.read-version.outputs.c2pa-native-version }}
secrets:
github-token: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
include:
- target: universal2
runs-on: macos-latest
- target: arm64
runs-on: macos-latest
- target: x86_64
runs-on: macos-15-intel
if: |
github.event_name != 'pull_request' ||
github.event.pull_request.author_association == 'COLLABORATOR' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.user.login == 'dependabot[bot]' ||
contains(github.event.pull_request.labels.*.name, 'safe to test')
test-built-macos-wheel:
name: Test macOS built wheels
needs: build-macos-wheel
runs-on: ${{ matrix.runs-on }}
strategy:
matrix:
include:
- target: arm64
runs-on: macos-latest
- target: x86_64
runs-on: macos-15-intel
if: |
github.event_name != 'pull_request' ||
github.event.pull_request.author_association == 'COLLABORATOR' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.user.login == 'dependabot[bot]' ||
contains(github.event.pull_request.labels.*.name, 'safe to test')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
- name: Download wheel artifacts
uses: actions/download-artifact@v4
with:
name: wheels-macos-${{ matrix.target }}
path: dist
- name: Create and activate virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install wheel for testing
run: |
source venv/bin/activate
pip install dist/c2pa_python-*.whl
- name: Run unittest tests on installed wheel
run: |
source venv/bin/activate
python ./tests/test_unit_tests.py
- name: Install pytest (in venv)
run: |
source venv/bin/activate
pip install pytest
- name: Run tests with pytest (venv)
run: |
source venv/bin/activate
venv/bin/pytest tests/test_unit_tests.py -v
sdist:
runs-on: ubuntu-latest
needs: [tests-unix, tests-windows]
if: |
github.event_name != 'pull_request' ||
github.event.pull_request.author_association == 'COLLABORATOR' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.user.login == 'dependabot[bot]' ||
contains(github.event.pull_request.labels.*.name, 'safe to test')
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
- name: Install dependencies
run: pip install -r requirements.txt
- name: Install dev dependencies for build
run: pip install -r requirements-dev.txt
- name: Build sdist
run: python -m build --sdist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist
release:
name: Release
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true'
runs-on: ubuntu-latest
environment: pypipublish
needs: [test-built-linux-wheel, test-built-macos-wheel, test-built-windows-wheel, sdist]
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Create dist directory
run: mkdir -p dist
- name: Download all wheels
uses: actions/download-artifact@v4
with:
pattern: wheels-*
path: dist
merge-multiple: true
- name: List downloaded artifacts
run: |
echo "Downloaded Artifacts"
ls -la dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist
# Uncomment to use TestPyPI
# repository-url: https://test.pypi.org/legacy/
verbose: true
# Uncomment below for test runs, otherwise fails on existing packages being reuploaded
skip-existing: true