-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
1512 lines (1496 loc) · 103 KB
/
Jenkinsfile
File metadata and controls
1512 lines (1496 loc) · 103 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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
library identifier: 'JenkinsPythonHelperLibrary@2024.1.2', retriever: modernSCM(
[$class: 'GitSCMSource',
remote: 'https://github.com/UIUCLibrary/JenkinsPythonHelperLibrary.git',
])
def createUVConfig(){
if(isUnix()){
def scriptFile = 'ci/scripts/create_uv_config.sh'
if(! fileExists(scriptFile)){
checkout scm
}
return sh(label: 'Setting up uv.toml config file', script: "sh ${scriptFile} " + '$UV_INDEX_URL $UV_EXTRA_INDEX_URL', returnStdout: true).trim()
}
def scriptFile = "ci\\scripts\\new-uv-global-config.ps1"
if(! fileExists(scriptFile)){
checkout scm
}
return powershell(
label: 'Setting up uv.toml config file',
script: "& ${scriptFile} \$env:UV_INDEX_URL \$env:UV_EXTRA_INDEX_URL",
returnStdout: true
).trim()
}
def generate_ctest_memtest_script(scriptName){
writeFile( file: 'suppression.txt',
text: '''UNINITIALIZED READ: reading register rcx
libpthread.so.0!__pthread_initialize_minimal_internal
''')
writeFile(file: scriptName,
text: '''set(CTEST_SOURCE_DIRECTORY "$ENV{WORKSPACE}")
set(CTEST_BINARY_DIRECTORY build/cpp)
set(CTEST_MEMORYCHECK_COMMAND /usr/local/bin/drmemory)
set(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE "$ENV{WORKSPACE}/suppression.txt")
ctest_start("Experimental")
ctest_memcheck()
''')
}
def getPypiConfig() {
node(){
configFileProvider([configFile(fileId: 'pypi_config', variable: 'CONFIG_FILE')]) {
def config = readJSON( file: CONFIG_FILE)
return config['deployment']['indexes']
}
}
}
def installMSVCRuntime(cacheLocation){
def cachedFile = "${cacheLocation}\\vc_redist.x64.exe".replaceAll(/\\\\+/, '\\\\')
withEnv(
[
"CACHED_FILE=${cachedFile}",
"RUNTIME_DOWNLOAD_URL=https://aka.ms/vs/17/release/vc_redist.x64.exe"
]
){
lock("${cachedFile}-${env.NODE_NAME}"){
powershell(
label: 'Ensuring vc_redist runtime installer is available',
script: '''if ([System.IO.File]::Exists("$Env:CACHED_FILE"))
{
Write-Host 'Found installer'
} else {
Write-Host 'No installer found'
Write-Host 'Downloading runtime'
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;Invoke-WebRequest "$Env:RUNTIME_DOWNLOAD_URL" -OutFile "$Env:CACHED_FILE"
}
'''
)
}
powershell(label: 'Install VC Runtime', script: 'Start-Process -filepath "$Env:CACHED_FILE" -ArgumentList "/install", "/passive", "/norestart" -Passthru | Wait-Process;')
}
}
def SUPPORTED_MAC_VERSIONS = ['3.10', '3.11', '3.12', '3.13+gil', '3.14+gil', '3.14t']
def SUPPORTED_LINUX_VERSIONS = ['3.10', '3.11', '3.12', '3.13+gil', '3.14+gil', '3.14t']
def SUPPORTED_WINDOWS_VERSIONS = ['3.10', '3.11', '3.12', '3.13+gil', '3.14+gil', '3.14t']
// ============================================================================
// Dynamic variables. Used to help manage state
def wheelStashes = []
def startup(){
node(){
parallel(
[
failFast: true,
// 'Loading Reference Build Information': {
// stage('Loading Reference Build Information'){
// discoverGitReferenceBuild(latestBuildIfNotFound: true)
// }
// },
'Enable Git Forensics': {
stage('Enable Git Forensics'){
mineRepository()
}
},
]
)
}
}
def test_cpp_code(buildPath){
stage('Build'){
tee('logs/cmake-build.log'){
sh(label: 'Building C++ Code',
script: """conan install . -if ${buildPath}
cmake -B ${buildPath} -Wdev -DSAMPLE_IMAGES_ARCHIVE=\${SAMPLE_IMAGES_ARCHIVE} -DCMAKE_TOOLCHAIN_FILE=build/conan_paths.cmake -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true -DBUILD_TESTING:BOOL=true -DCMAKE_CXX_FLAGS="-fprofile-arcs -ftest-coverage -Wall -Wextra"
cmake --build ${buildPath} -j \$(grep -c ^processor /proc/cpuinfo)
"""
)
}
}
stage('CTest'){
sh(label: 'Running CTest',
script: "cd ${buildPath} && ctest --output-on-failure --no-compress-output -T Test"
)
}
}
def windows_wheels(pythonVersions, testPackages, params, wheelStashes){
def wheelStages = [:]
pythonVersions.each{ pythonVersion ->
if(params.INCLUDE_WINDOWS_X86_64 == true){
wheelStages["Python ${pythonVersion} - Windows"] = {
stage("Python ${pythonVersion} - Windows"){
stage("Build Wheel (${pythonVersion} Windows)"){
node('windows && docker'){
def dockerImageName = "${currentBuild.fullProjectName}_${UUID.randomUUID().toString()}".replaceAll("-", "_").replaceAll('/', "_").replaceAll(' ', "").toLowerCase()
checkout scm
retry(3){
try{
try{
timeout(60){
powershell(label: 'Building Wheel for Windows', script: "scripts/build_windows.ps1 -PythonVersion ${pythonVersion} -DockerImageName ${dockerImageName}")
}
stash includes: 'dist/*.whl', name: "python${pythonVersion} windows wheel"
wheelStashes << "python${pythonVersion} windows wheel"
archiveArtifacts artifacts: 'dist/*.whl'
} finally {
powershell(
label: "Untagging Docker Image used",
script: "docker image rm --no-prune ${dockerImageName}",
returnStatus: true
)
}
} finally {
bat "${tool(name: 'Default', type: 'git')} clean -dffx"
}
}
}
}
if(testPackages == true){
stage("Test Wheel (${pythonVersion} Windows)"){
node('windows && docker'){
checkout scm
try{
docker.image(env.DEFAULT_PYTHON_DOCKER_IMAGE ? env.DEFAULT_PYTHON_DOCKER_IMAGE: 'python')
.inside('\
--mount type=volume,source=uv_python_cache_dir,target=C:\\Users\\ContainerUser\\Documents\\cache\\uvpython \
--mount type=volume,source=pipcache,target=C:\\Users\\ContainerUser\\Documents\\cache\\pipcache \
--mount type=volume,source=uv_cache_dir,target=C:\\Users\\ContainerUser\\Documents\\cache\\uvcache \
--mount type=volume,source=msvc-runtime,target=c:\\msvc_runtime \
--mount type=volume,source=windows-certs,target=c:\\certs \
'
){
installMSVCRuntime('c:\\msvc_runtime\\')
unstash "python${pythonVersion} windows wheel"
withEnv([
'PIP_CACHE_DIR=C:\\Users\\ContainerUser\\Documents\\cache\\pipcache',
'UV_PYTHON_CACHE_DIR=C:\\Users\\ContainerUser\\Documents\\cache\\uvpython',
'UV_CACHE_DIR=C:\\Users\\ContainerUser\\Documents\\cache\\uvcache',
'UV_TOOL_DIR=C:\\Users\\ContainerUser\\Documents\\uvtools',
"UV_CONFIG_FILE=${createUVConfig()}",
"TOX_UV_PATH=${WORKSPACE}\\venv\\Scripts\\uv.exe"
]){
findFiles(glob: 'dist/*.whl').each{
retry(3){
timeout(60){
try{
bat(label: 'Running Tox',
script: """python -m venv venv
venv\\Scripts\\pip install --disable-pip-version-check uv
venv\\Scripts\\uv python install ${pythonVersion.replace('+gil','')}
venv\\Scripts\\uv run --only-group=tox-uv --python ${pythonVersion} tox run -e py${pythonVersion.replace('.', '').replace('+gil', '')} --installpkg ${it.path}
rmdir /S /Q venv
rmdir /S /Q .tox
"""
)
} catch (e){
bat 'dir dist\\'
throw e
}
}
}
}
}
}
} finally {
bat "${tool(name: 'Default', type: 'git')} clean -dffx"
}
}
}
}
}
}
}
}
parallel(wheelStages)
}
def linux_wheels(pythonVersions, testPackages, params, wheelStashes){
def wheelStages = [:]
def selectedArches = []
def allValidArches = ['arm64', 'amd64']
if(params.INCLUDE_LINUX_ARM == true){
selectedArches << 'arm64'
}
if(params.INCLUDE_LINUX_X86_64 == true){
selectedArches << 'amd64'
}
parallel([failFast: true] << pythonVersions.collectEntries{ pythonVersion ->
[
"Python ${pythonVersion} - Linux": {
stage("Python ${pythonVersion} - Linux"){
parallel([failFast: true] << allValidArches.collectEntries{ arch ->
def newStageName = "Python ${pythonVersion} Linux ${arch} Wheel"
return [
"${newStageName}":{
stage(newStageName){
if(selectedArches.contains(arch)){
stage("Build Wheel (${pythonVersion} Linux ${arch})"){
node("linux && docker && ${arch}"){
try{
checkout scm
withEnv(["UV_CONFIG_FILE=${createUVConfig()}"]){
def dockerImageName = "pyexiv2bind_builder-${UUID.randomUUID().toString()}"
try{
sh "scripts/build_linux_wheels.sh --python-version ${pythonVersion} --platform linux/${arch} --docker-image-name ${dockerImageName}"
stash includes: 'dist/*manylinux*.*whl', name: "python${pythonVersion} linux - ${arch} - wheel"
wheelStashes << "python${pythonVersion} linux - ${arch} - wheel"
archiveArtifacts artifacts: 'dist/*.whl'
} finally {
sh "docker rmi --force --no-prune ${dockerImageName}"
}
}
} finally {
sh "${tool(name: 'Default', type: 'git')} clean -dffx"
}
}
}
if(testPackages == true){
stage("Test Wheel (${pythonVersion} Linux ${arch})"){
retry(3){
node("docker && linux && ${arch}"){
checkout scm
unstash "python${pythonVersion} linux - ${arch} - wheel"
try{
withEnv([
'PIP_CACHE_DIR=/tmp/pipcache',
'UV_TOOL_DIR=/tmp/uvtools',
'UV_PYTHON_CACHE_DIR=/tmp/uvpython',
'UV_CACHE_DIR=/tmp/uvcache',
"UV_CONFIG_FILE=${createUVConfig()}"
]){
docker.image('ghcr.io/astral-sh/uv:debian').inside('--mount source=python-tmp-py3exiv2bind,target=/tmp --tmpfs /.local/share:exec --tmpfs /.local/bin:exec'){
timeout(60){
sh(
label: 'Testing with tox',
script: """uv python install ${pythonVersion.replace('+gil','')}
uv run --only-group=tox-uv tox --installpkg ${findFiles(glob:'dist/*.whl')[0].path} -e py${pythonVersion.replace('.', '').replace('+gil','')}
rm -rf .tox
"""
)
}
}
}
} finally {
sh "${tool(name: 'Default', type: 'git')} clean -dffx"
}
}
}
}
}
} else {
Utils.markStageSkippedForConditional(newStageName)
}
}
}
]
})
}
}
]
})
}
def mac_wheels(pythonVersions, testPackages, params, wheelStashes){
def selectedArches = []
def allValidArches = ['arm64', 'x86_64']
if(params.INCLUDE_MACOS_X86_64 == true){
selectedArches << 'x86_64'
}
if(params.INCLUDE_MACOS_ARM == true){
selectedArches << 'arm64'
}
parallel([failFast: true] << pythonVersions.collectEntries{ pythonVersion ->
[
"Python ${pythonVersion} - Mac":{
stage("Python ${pythonVersion} - Mac"){
stage("Single arch wheels for Python ${pythonVersion}"){
parallel([failFast: true] << allValidArches.collectEntries{arch ->
def newWheelStage = "MacOS - Python ${pythonVersion} - ${arch}: wheel"
return [
"${newWheelStage}": {
stage(newWheelStage){
if(selectedArches.contains(arch)){
stage("Build Wheel (${pythonVersion} MacOS ${arch})"){
node("mac && python3 && ${arch}"){
timeout(60){
checkout scm
try{
withEnv(["UV_CONFIG_FILE=${createUVConfig()}"]){
sh(label: 'Building wheel',
script: """python3 -m venv venv
trap "rm -rf venv" EXIT
venv/bin/pip install --disable-pip-version-check uv
scripts/build_mac_wheel.sh --uv=./venv/bin/uv --python-version=${pythonVersion}
"""
)
}
stash includes: 'dist/*.whl', name: "python${pythonVersion} mac ${arch} wheel"
wheelStashes << "python${pythonVersion} mac ${arch} wheel"
archiveArtifacts artifacts: 'dist/*.whl'
} finally {
sh "${tool(name: 'Default', type: 'git')} clean -dffx"
}
}
}
}
if(testPackages == true){
stage("Test Wheel (${pythonVersion} MacOS ${arch})"){
node("mac && python3 && ${arch}"){
checkout scm
unstash "python${pythonVersion} mac ${arch} wheel"
def wheels = findFiles(glob: 'dist/*.whl')
if(wheels.size() == 0){
error "No wheels found to test"
}
wheels.each{
try{
withEnv(["UV_CONFIG_FILE=${createUVConfig()}", "TOX_UV_PATH=${WORKSPACE}/venv/bin/uv"]){
timeout(60){
sh(label: 'Running Tox',
script: """python3 -m venv venv
./venv/bin/python -m pip install --disable-pip-version-check uv
./venv/bin/uv run --only-group=tox-uv --frozen tox run --installpkg ${it.path} -e py${pythonVersion.replace('.', '').replace('+gil', '')}"""
)
}
}
} finally {
sh "${tool(name: 'Default', type: 'git')} clean -dffx"
}
}
}
}
}
} else {
Utils.markStageSkippedForConditional(newWheelStage)
}
}
}
]
}
)
}
if(params.INCLUDE_MACOS_X86_64 && params.INCLUDE_MACOS_ARM){
stage("Universal2 Wheel: Python ${pythonVersion}"){
stage('Make Universal2 wheel'){
retry(3){
node("mac && python3") {
try{
checkout scm
withEnv(["UV_CONFIG_FILE=${createUVConfig()}"]){
unstash "python${pythonVersion} mac arm64 wheel"
unstash "python${pythonVersion} mac x86_64 wheel"
def wheelNames = []
findFiles(excludes: '', glob: 'dist/*.whl').each{wheelFile ->
wheelNames.add(wheelFile.path)
}
sh(label: 'Make Universal2 wheel',
script: """python${pythonVersion.replace('+gil', '')} -m venv venv
. ./venv/bin/activate
pip install --disable-pip-version-check --upgrade pip
pip install --disable-pip-version-check wheel delocate
mkdir -p out
delocate-merge ${wheelNames.join(' ')} --verbose -w ./out/
rm dist/*.whl
"""
)
def fusedWheel = findFiles(excludes: '', glob: 'out/*.whl')[0]
def props = readTOML( file: 'pyproject.toml')['project']
def universalWheel = "py3exiv2bind-${props.version}-cp${pythonVersion.replace('.', '').replace('+git', '')}-cp${pythonVersion.replace('.','').replace('+gil', '')}-macosx_11_0_universal2.whl"
sh "mv ${fusedWheel.path} ./dist/${universalWheel}"
stash includes: 'dist/*.whl', name: "python${pythonVersion} mac-universal2 wheel"
wheelStashes << "python${pythonVersion} mac-universal2 wheel"
archiveArtifacts artifacts: 'dist/*.whl'
}
} finally{
sh "${tool(name: 'Default', type: 'git')} clean -dffx"
}
}
}
}
if(testPackages == true){
stage("Test universal2 Wheel"){
def archStages = [:]
['x86_64', 'arm64'].each{arch ->
archStages["Test Python ${pythonVersion} universal2 Wheel on ${arch} mac"] = {
stage("Test Python ${pythonVersion} universal2 Wheel on ${arch} mac"){
if(! selectedArches.contains(arch)){
Utils.markStageSkippedForConditional("Test Python ${pythonVersion} universal2 Wheel on ${arch} mac")
return
}
node("mac && python3 && ${arch}"){
try{
checkout scm
withEnv(["UV_CONFIG_FILE=${createUVConfig()}", "TOX_UV_PATH=${WORKSPACE}/venv/bin/uv"]){
unstash "python${pythonVersion} mac-universal2 wheel"
findFiles(glob: 'dist/*.whl').each{
sh(label: 'Running Tox',
script: """python3 -m venv venv
trap "rm -rf venv" EXIT
./venv/bin/python -m pip install --disable-pip-version-check uv
trap "rm -rf venv && rm -rf .tox" EXIT
./venv/bin/uv run --only-group=tox-uv --frozen --python=${pythonVersion} tox --installpkg ${it.path} -e py${pythonVersion.replace('.', '').replace('+gil', '')}
"""
)
}
}
archiveArtifacts artifacts: 'dist/*.whl'
} finally {
sh "${tool(name: 'Default', type: 'git')} clean -dffx"
}
}
}
}
}
parallel(archStages)
}
}
}
}
}
}
]}
)
}
def get_sonarqube_unresolved_issues(report_task_file){
script{
if(! fileExists(report_task_file)){
error "Could not find ${report_task_file}"
}
def props = readProperties file: report_task_file
if(! props['serverUrl'] || ! props['projectKey']){
error "Could not find serverUrl or projectKey in ${report_task_file}"
}
def response = httpRequest url : props['serverUrl'] + '/api/issues/search?componentKeys=' + props['projectKey'] + '&resolved=no'
def outstandingIssues = readJSON text: response.content
return outstandingIssues
}
}
def calculateGCOV_PREFIX_STRIP(){
return sh(returnStdout: true, label: 'configuring GCOV_PREFIX_STRIP', script:'echo "$PWD" | awk -F/ \'{c=0; for(i=1;i<=NF;i++) if($i!="") c++; print c+2}\'')
}
// *****************************************************************************
stage('Pipeline Pre-tasks'){
startup()
}
pipeline {
agent none
parameters {
booleanParam(name: 'TEST_RUN_TOX', defaultValue: false, description: 'Run Tox Tests')
booleanParam(name: 'RUN_CHECKS', defaultValue: true, description: 'Run checks on code')
booleanParam(name: 'RUN_MEMCHECK', defaultValue: false, description: 'Run Memcheck. NOTE: This can be very slow.')
booleanParam(name: 'USE_SONARQUBE', defaultValue: true, description: 'Send data test data to SonarQube')
credentials(name: 'SONARCLOUD_TOKEN', credentialType: 'org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl', defaultValue: 'sonarcloud_token', required: false)
booleanParam(name: 'BUILD_PACKAGES', defaultValue: false, description: 'Build Python packages')
booleanParam(name: 'INCLUDE_MACOS_ARM', defaultValue: false, description: 'Include ARM(m1) architecture for Mac')
booleanParam(name: 'INCLUDE_MACOS_X86_64', defaultValue: false, description: 'Include x86_64 architecture for Mac')
booleanParam(name: 'INCLUDE_LINUX_ARM', defaultValue: false, description: 'Include ARM architecture for Linux')
booleanParam(name: 'INCLUDE_LINUX_X86_64', defaultValue: true, description: 'Include x86_64 architecture for Linux')
booleanParam(name: 'INCLUDE_WINDOWS_X86_64', defaultValue: true, description: 'Include x86_64 architecture for Windows')
booleanParam(name: 'TEST_PACKAGES', defaultValue: true, description: 'Test Python packages by installing them and running tests on the installed package')
booleanParam(name: 'DEPLOY_PYPI', defaultValue: false, description: 'Deploy to pypi')
booleanParam(name: 'DEPLOY_DOCS', defaultValue: false, description: 'Update online documentation')
}
stages {
stage('Building and Testing'){
when{
anyOf{
equals expected: true, actual: params.RUN_CHECKS
equals expected: true, actual: params.TEST_RUN_TOX
}
}
stages{
stage('Building and Testing'){
agent {
dockerfile {
filename 'ci/docker/linux/jenkins/Dockerfile'
label 'linux && docker && x86'
additionalBuildArgs '--build-arg PIP_EXTRA_INDEX_URL --build-arg CONAN_CENTER_PROXY_V2_URL'
args '--mount source=sonar-cache-py3exiv2bind,target=/opt/sonar/.sonar/cache --mount source=python-tmp-py3exiv2bind,target=/tmp --tmpfs /venv:exec -e UV_PROJECT_ENVIRONMENT=/venv --tmpfs /.config:exec'
}
}
environment{
PIP_CACHE_DIR='/tmp/pipcache'
UV_TOOL_DIR='/tmp/uvtools'
UV_PYTHON_CACHE_DIR='/tmp/uvpython'
UV_CACHE_DIR='/tmp/uvcache'
UV_CONFIG_FILE=createUVConfig()
}
stages{
stage('Setup Testing Environment'){
environment{
CXXFLAGS='--coverage -fprofile-arcs -ftest-coverage'
}
steps{
sh(
label: 'Create virtual environment',
script: '''mkdir -p build/python
uv sync --group ci --no-install-project --no-managed-python
mkdir -p build/temp
mkdir -p build/lib
mkdir -p build/docs
mkdir -p build/python
mkdir -p build/coverage
mkdir -p coverage_data/python_extension
mkdir -p coverage_data/cpp
mkdir -p logs
mkdir -p reports
mkdir -p reports/coverage
'''
)
sh(
label: 'Install project as editable module with ci dependencies',
script: '''VIRTUAL_ENV=$UV_PROJECT_ENVIRONMENT uv pip install "pybind11>=2.13" "uiucprescon.build @ https://github.com/UIUCLibrary/uiucprescon_build/releases/download/v0.5.0/uiucprescon_build-0.5.0-py3-none-any.whl"
mkdir -p build/build_wrapper_output_directory
build-wrapper-linux --out-dir build/build_wrapper_output_directory uv run setup.py build_clib build_ext --inplace --build-temp build/temp --build-lib build/lib --debug -v
'''
)
cleanWs(
deleteDirs: true,
patterns: [
[pattern: 'build/**/cmake_builds/**/*.gcno', type: 'INCLUDE'],
]
)
sh 'find build -name "*.gcno"'
}
}
stage('Building Documentation'){
environment{
GCOV_PREFIX='build/temp'
GCOV_PREFIX_STRIP=calculateGCOV_PREFIX_STRIP()
}
steps {
catchError(buildResult: 'UNSTABLE', message: 'Building Sphinx documentation has issues', stageResult: 'UNSTABLE') {
sh(label: 'Running Sphinx',
script: 'uv run -m sphinx -b html docs/source build/docs/html -d build/docs/doctrees -v -w logs/build_sphinx.log -W --keep-going && find build/temp -name "*.gcda"'
)
}
}
post{
always {
recordIssues(tools: [sphinxBuild(name: 'Sphinx Documentation Build', pattern: 'logs/build_sphinx.log', id: 'sphinx_build')])
}
success{
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'build/docs/html', reportFiles: 'index.html', reportName: 'Documentation', reportTitles: ''])
script{
def props = readTOML( file: 'pyproject.toml')['project']
zip archive: true, dir: 'build/docs/html', glob: '', zipFile: "dist/${props.name}-${props.version}.doc.zip"
}
stash includes: 'dist/*.doc.zip,build/docs/html/**', name: 'DOCS_ARCHIVE'
}
}
}
stage('Code Quality') {
when{
equals expected: true, actual: params.RUN_CHECKS
}
parallel{
stage('Python tests'){
environment{
GCOV_PREFIX='build/temp'
GCOV_PREFIX_STRIP=calculateGCOV_PREFIX_STRIP()
}
steps{
script{
parallel([
failFast: false,
'Run Doctest Tests': {
try{
sh 'uv run coverage run --parallel-mode --source=src/py3exiv2bind -m sphinx docs/source reports/doctest -b doctest -d build/docs/.doctrees --no-color -w logs/doctest_warnings.log'
} finally {
recordIssues(tools: [sphinxBuild(name: 'Doctest', pattern: 'logs/doctest_warnings.log', id: 'doctest')])
}
},
'MyPy Static Analysis': {
try{
tee('logs/mypy.log'){
sh(returnStatus: true,
script: 'uv run mypy -p py3exiv2bind --html-report reports/mypy/html'
)
}
} finally {
recordIssues(tools: [myPy(name: 'MyPy', pattern: 'logs/mypy.log')])
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'reports/mypy/html/', reportFiles: 'index.html', reportName: 'MyPy HTML Report', reportTitles: ''])
}
},
'Run Pylint Static Analysis': {
try{
catchError(buildResult: 'SUCCESS', message: 'Pylint found issues', stageResult: 'UNSTABLE') {
sh(
script: '''mkdir -p logs
mkdir -p reports
PYLINTHOME=. uv run pylint src/py3exiv2bind -r n --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" > reports/pylint.txt
''',
label: 'Running pylint'
)
}
sh(
label: 'Running pylint for sonarqube',
script: 'PYLINTHOME=. uv run pylint -r n --msg-template="{path}:{module}:{line}: [{msg_id}({symbol}), {obj}] {msg}" > reports/pylint_issues.txt',
returnStatus: true
)
} finally {
stash includes: 'reports/pylint_issues.txt,reports/pylint.txt', name: 'PYLINT_REPORT'
recordIssues(tools: [pyLint(pattern: 'reports/pylint.txt')])
}
},
'Flake8': {
try{
sh(
returnStatus: true,
script: 'uv run flake8 src/py3exiv2bind --tee --output-file ./logs/flake8.log'
)
} finally {
stash includes: 'logs/flake8.log', name: 'FLAKE8_REPORT'
recordIssues(tools: [flake8(name: 'Flake8', pattern: 'logs/flake8.log')])
}
},
'Running Unit Tests': {
try{
sh 'uv run coverage run --parallel-mode --source=src/py3exiv2bind -m pytest --junitxml=./reports/pytest/junit-pytest.xml'
} finally {
stash includes: 'reports/pytest/junit-pytest.xml', name: 'PYTEST_REPORT'
junit 'reports/pytest/junit-pytest.xml'
}
},
'Audit uv.lock File': {
catchError(buildResult: 'SUCCESS', message: 'uv-secure found issues', stageResult: 'UNSTABLE') {
sh 'uv run --only-group=audit-dependencies --isolated uv-secure --disable-cache uv.lock'
}
}
])
}
}
post {
always{
script{
try{
sh(label: 'Creating gcovr coverage report',
script: 'uv run gcovr --root $WORKSPACE --exclude \'\\.venv\' --exclude \'/.*/build/\' --exclude-directories=$WORKSPACE/.venv --exclude-directories=$WORKSPACE/build/cpp --exclude-directories=$WORKSPACE/build/temp/cmake_builds/exiv2/_deps --print-summary --json=$WORKSPACE/reports/coverage/coverage-c-extension_tests.json --txt=$WORKSPACE/reports/coverage/coverage-c-extension_tests.txt --exclude-throw-branches --exclude-unreachable-branches --fail-under-line=1 --gcov-object-directory=$WORKSPACE/build/temp/src build/temp/src'
)
} catch (e){
sh(label: 'locating gcno and gcda files', script: 'find . \\( -name "*.gcno" -o -name "*.gcda" \\)')
throw e
} finally {
if(fileExists('reports/coverage/coverage-c-extension_tests.txt')){
sh 'cat reports/coverage/coverage-c-extension_tests.txt'
}
}
}
}
}
}
stage('C++ tests'){
stages{
stage('Building C++ Tests with coverage data'){
steps{
tee('logs/cmake-build.log'){
sh(label: 'Building C++ Code',
script: '''uvx conan install conanfile.py -of build/cpp --build=missing -pr:b=default
uv run cmake --preset conan-release -B build/cpp/ -Wdev -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true -DBUILD_TESTING:BOOL=true -Dpyexiv2bind_generate_python_bindings:BOOL=false -DCMAKE_CXX_FLAGS="-fprofile-arcs -ftest-coverage -Wall -Wextra"
mkdir -p build/build_wrapper_output_directory
build-wrapper-linux --out-dir build/build_wrapper_output_directory uv run cmake --build build/cpp --target all
'''
)
}
}
post{
always{
recordIssues(
filters: [excludeFile('build/cpp/_deps/*')],
tools: [gcc(pattern: 'logs/cmake-build.log'), [$class: 'Cmake', pattern: 'logs/cmake-build.log']]
)
}
}
}
stage('Running Tests'){
steps{
script{
parallel([
failFast: false,
'Clang Tidy Analysis': {
try{
tee('logs/clang-tidy.log') {
catchError(buildResult: 'SUCCESS', message: 'Clang-Tidy found issues', stageResult: 'UNSTABLE') {
sh(label: 'Run Clang Tidy', script: 'run-clang-tidy -clang-tidy-binary clang-tidy -p ./build/cpp/ src/py3exiv2bind/')
}
}
} finally {
recordIssues(tools: [clangTidy(pattern: 'logs/clang-tidy.log')])
}
},
'Memcheck': {
if (params.RUN_MEMCHECK){
generate_ctest_memtest_script('memcheck.cmake')
try{
timeout(30){
sh(label: 'Running memcheck', script: 'uv run ctest -S memcheck.cmake --verbose -j $(grep -c ^processor /proc/cpuinfo)')
}
} finally {
recordIssues(
filters: [excludeFile('build/cpp/_deps/*'),],
tools: [
drMemory(pattern: 'build/cpp/Testing/Temporary/DrMemory/**/results.txt')
]
)
}
} else {
Utils.markStageSkippedForConditional('Memcheck')
}
},
'CPP Check': {
try{
catchError(buildResult: 'SUCCESS', message: 'cppcheck found issues', stageResult: 'UNSTABLE') {
sh(label: 'Running cppcheck',
script: 'cppcheck --error-exitcode=1 --project=build/cpp/compile_commands.json -i_deps --enable=all --suppressions-list=cppcheck_suppression_file.txt -rp=$PWD/build/cpp --xml --output-file=logs/cppcheck_debug.xml'
)
}
} finally {
recordIssues(
filters: [
excludeType('unmatchedSuppression'),
excludeType('missingIncludeSystem'),
excludeFile('catch.hpp'),
excludeFile('value.hpp'),
],
tools: [
cppCheck(pattern: 'logs/cppcheck_debug.xml')
]
)
}
},
'CTest': {
try{
sh(label: 'Running CTest',
script: '''cd build/cpp
uv run ctest --output-on-failure --no-compress-output -T Test
'''
)
} finally {
xunit(
testTimeMargin: '3000',
thresholdMode: 1,
thresholds: [
failed(),
skipped()
],
tools: [
CTest(
deleteOutputFiles: true,
failIfNotNew: true,
pattern: 'build/Testing/**/*.xml',
skipNoTestFiles: true,
stopProcessingIfError: true
)
]
)
}
},
])
}
}
}
}
post{
always{
sh(label: 'Creating gcovr coverage report',
script: '''uv run gcovr --root $WORKSPACE --print-summary --exclude \'/.*/build/\' --json=$WORKSPACE/reports/coverage/coverage_cpp_tests.json --txt=$WORKSPACE/reports/coverage/text_cpp_tests_summary.txt --exclude-throw-branches --gcov-object-directory=$WORKSPACE/build/cpp build/cpp
cat reports/coverage/text_cpp_tests_summary.txt
'''
)
}
}
}
stage('Misc tests'){
steps{
script{
parallel([
'Task Scanner': {
recordIssues(tools: [taskScanner(highTags: 'FIXME', includePattern: 'src/py3exiv2bind/**/*.py, src/py3exiv2bind/**/*.cpp, src/py3exiv2bind/**/*.h', normalTags: 'TODO')])
},
])
}
}
}
}
post{
always{
script{
if(fileExists('reports/coverage/coverage_cpp_tests.json') && fileExists('reports/coverage/coverage-c-extension_tests.json')){
sh(label: 'combining coverage data',
script: '''mkdir -p reports/coverage
uv run coverage combine
uv run coverage xml -o ./reports/coverage/coverage-python.xml
uv run gcovr --root $WORKSPACE --filter=src/py3exiv2bind --add-tracefile reports/coverage/coverage_cpp_tests.json --add-tracefile reports/coverage/coverage-c-extension_tests.json --keep --print-summary --cobertura reports/coverage/coverage_cpp.xml --txt reports/coverage/text_merged_summary.txt
cat reports/coverage/text_merged_summary.txt
'''
)
}
}
archiveArtifacts artifacts: 'reports/coverage/*.xml'
recordCoverage(tools: [[parser: 'COBERTURA', pattern: 'reports/coverage/*.xml']])
}
}
}
stage('Sonarcloud Analysis'){
options{
lock('py3exiv2bind-sonarcloud')
}
environment{
SONAR_USER_HOME = '/tmp/sonar'
}
when{
allOf{
equals expected: true, actual: params.USE_SONARQUBE
equals expected: true, actual: params.RUN_CHECKS
expression{
try{
withCredentials([string(credentialsId: params.SONARCLOUD_TOKEN, variable: 'dddd')]) {
echo 'Found credentials for sonarqube'
}
} catch(e){
return false
}
return true
}
}
}
steps{
script{
withSonarQubeEnv(installationName:'sonarcloud', credentialsId: params.SONARCLOUD_TOKEN) {
withCredentials([string(credentialsId: params.SONARCLOUD_TOKEN, variable: 'token')]) {
sh(
label: 'Running Sonar Scanner',
script: 'uv run pysonar -t $token -Dsonar.projectVersion=$VERSION -Dsonar.buildString="$BUILD_TAG" -Dsonar.cfamily.cache.enabled=false -Dsonar.cfamily.threads=$(grep -c ^processor /proc/cpuinfo) -Dsonar.cfamily.compile-commands=build/build_wrapper_output_directory/compile_commands.json -Dsonar.python.coverage.reportPaths=./reports/coverage/coverage-python.xml -Dsonar.cfamily.cobertura.reportPaths=reports/coverage/coverage_cpp.xml ' + (env.CHANGE_ID ? '-Dsonar.pullrequest.key=$CHANGE_ID -Dsonar.pullrequest.base=$CHANGE_TARGET' : '-Dsonar.branch.name=$BRANCH_NAME')
)
}
}
timeout(time: 1, unit: 'HOURS') {
def sonarqube_result = waitForQualityGate(abortPipeline: false)
if (sonarqube_result.status != 'OK') {
unstable "SonarQube quality gate: ${sonarqube_result.status}"
}
if(env.BRANCH_IS_PRIMARY){
writeJSON(file: 'reports/sonar-report.json', json: get_sonarqube_unresolved_issues('.sonar/report-task.txt'))
}
}
}
}
post {
always{
milestone 1
script{
if(fileExists('reports/sonar-report.json')){
recordIssues(tools: [sonarQube(pattern: 'reports/sonar-report.json')])
}
}
}
}
}
}
post{
cleanup{
sh "git clean -dffx"
}
}
}
stage('Run Tox test') {
when {
equals expected: true, actual: params.TEST_RUN_TOX
beforeAgent true
}
parallel{
stage('Linux'){
environment{
PIP_CACHE_DIR='/tmp/pipcache'
UV_TOOL_DIR='/tmp/uvtools'
UV_PYTHON_CACHE_DIR='/tmp/uvpython'
UV_CACHE_DIR='/tmp/uvcache'
}
when{
expression {return nodesByLabel('linux && docker').size() > 0}
}
steps{
script{
def envs = []
node('docker && linux'){
checkout scm
withEnv(["UV_CONFIG_FILE=${createUVConfig()}"]){
try{
docker.image('ghcr.io/astral-sh/uv:debian').inside('--mount source=python-tmp-py3exiv2bind,target=/tmp --tmpfs /venv:exec -e UV_PROJECT_ENVIRONMENT=/venv --tmpfs /tox:exec -e TOX_WORK_DIR=/tox'){
envs = sh(
label: 'Get tox environments',
script: 'uv run --quiet --only-group=tox --frozen tox list -d --no-desc',
returnStdout: true,
).trim().split('\n')
}
} finally{
sh "${tool(name: 'Default', type: 'git')} clean -dffx"
}
}
}
parallel(
envs.collectEntries{toxEnv ->
def version = toxEnv.replaceAll(/py(\d)(\d+)/, '$1.$2')
[
"Tox Environment: ${toxEnv}",
{
retry(2){
node('docker && linux'){
def maxRetries = 2
checkout scm
def image
lock("${env.JOB_NAME} - ${env.NODE_NAME}"){
retry(maxRetries){
image = docker.build(UUID.randomUUID().toString(), '-f ci/docker/linux/tox/Dockerfile --build-arg PIP_EXTRA_INDEX_URL --build-arg PIP_INDEX_URL --build-arg CONAN_CENTER_PROXY_V2_URL .')
}
}
try{
retry(maxRetries){
try{
withEnv(["UV_CONFIG_FILE=${createUVConfig()}"]){
image.inside('--mount source=python-tmp-py3exiv2bind,target=/tmp --tmpfs /venv:exec -e UV_PROJECT_ENVIRONMENT=/venv --tmpfs /tox:exec -e TOX_WORK_DIR=/tox'){
sh( label: 'Running Tox',
script: "uv run --only-group=tox-uv --frozen -p ${version} --python-preference only-system tox run -e ${toxEnv} --runner uv-venv-lock-runner -vvv"
)
}
}
} finally{
sh "${tool(name: 'Default', type: 'git')} clean -dffx"
}
}
} finally {
if (image){
sh "docker rmi --force --no-prune ${image.id}"
}
}
}
}
}
]
}
)
}
}
}
stage('Windows'){
when{
expression {return nodesByLabel('windows && docker && x86').size() > 0}
}
environment{
PIP_CACHE_DIR='C:\\Users\\ContainerUser\\Documents\\cache\\pipcache'
UV_TOOL_DIR='C:\\Users\\ContainerUser\\Documents\\uvtools'
UV_PYTHON_CACHE_DIR='C:\\Users\\ContainerUser\\Documents\\cache\\uvpython'
UV_CACHE_DIR='C:\\cache\\uvcache'
TOX_WORK_DIR='C:\\Users\\ContainerUser\\AppData\\Local\\Temp\\tox'
}
steps{
script{
def envs = []
node('docker && windows'){
checkout scm
try{