-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
1539 lines (1525 loc) · 101 KB
/
Jenkinsfile
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 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;')
}
}
SUPPORTED_MAC_VERSIONS = ['3.9', '3.10', '3.11', '3.12', '3.13']
SUPPORTED_LINUX_VERSIONS = ['3.9', '3.10', '3.11', '3.12', '3.13']
SUPPORTED_WINDOWS_VERSIONS = ['3.9', '3.10', '3.11', '3.12', '3.13']
// ============================================================================
// Dynamic variables. Used to help manage state
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 -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(){
def wheelStages = [:]
SUPPORTED_WINDOWS_VERSIONS.each{ pythonVersion ->
if(params.INCLUDE_WINDOWS_X86_64 == true){
wheelStages["Python ${pythonVersion} - Windows"] = {
stage("Python ${pythonVersion} - Windows"){
stage("Build Wheel (${pythonVersion} Windows)"){
buildPythonPkg(
agent: [
dockerfile: [
label: 'windows && docker',
filename: 'ci/docker/windows/tox/Dockerfile',
additionalBuildArgs: '--build-arg PIP_EXTRA_INDEX_URL --build-arg PIP_INDEX_URL --build-arg CHOCOLATEY_SOURCE --build-arg chocolateyVersion'
]
],
retries: 3,
buildCmd: {
withEnv([
'PIP_CACHE_DIR=C:\\Users\\ContainerUser\\Documents\\pipcache',
'UV_TOOL_DIR=C:\\Users\\ContainerUser\\Documents\\uvtools',
'UV_PYTHON_INSTALL_DIR=C:\\Users\\ContainerUser\\Documents\\uvpython',
'UV_CACHE_DIR=C:\\Users\\ContainerUser\\Documents\\uvcache',
'UV_INDEX_STRATEGY=unsafe-best-match',
]){
bat """python -m venv venv
venv\\Scripts\\pip install --disable-pip-version-check uv
venv\\Scripts\\uv build --python ${pythonVersion} --wheel
rmdir /S /Q venv
"""
}
},
post:[
cleanup: {
cleanWs(
patterns: [
[pattern: 'venv/', type: 'INCLUDE'],
[pattern: 'dist/', type: 'INCLUDE'],
],
notFailBuild: true,
deleteDirs: true
)
},
success: {
stash includes: 'dist/*.whl', name: "python${pythonVersion} windows wheel"
wheelStashes << "python${pythonVersion} windows wheel"
archiveArtifacts artifacts: 'dist/*.whl'
}
]
)
}
stage("Test Wheel (${pythonVersion} Windows)"){
node('windows && docker'){
docker.image('python').inside('--mount source=uv_python_install_dir,target=C:\\Users\\ContainerUser\\Documents\\uvpython --mount source=msvc-runtime,target=c:\\msvc_runtime --mount source=windows-certs,target=c:\\certs'){
installMSVCRuntime('c:\\msvc_runtime\\')
checkout scm
unstash "python${pythonVersion} windows wheel"
withEnv([
'PIP_CACHE_DIR=C:\\Users\\ContainerUser\\Documents\\pipcache',
'UV_TOOL_DIR=C:\\Users\\ContainerUser\\Documents\\uvtools',
'UV_PYTHON_INSTALL_DIR=C:\\Users\\ContainerUser\\Documents\\uvpython',
'UV_CACHE_DIR=C:\\Users\\ContainerUser\\Documents\\uvcache',
'UV_INDEX_STRATEGY=unsafe-best-match',
]){
findFiles(glob: 'dist/*.whl').each{
retry(3){
bat(label: 'Running Tox',
script: """python -m venv venv
venv\\Scripts\\pip install --disable-pip-version-check uv
venv\\Scripts\\uvx --python ${pythonVersion} --with-requirements requirements-dev.txt --with tox-uv tox run -e py${pythonVersion.replace('.', '')} --installpkg ${it.path}
rmdir /S /Q venv
rmdir /S /Q .tox
"""
)
}
}
}
}
}
}
}
}
}
}
parallel(wheelStages)
}
def linux_wheels(){
def wheelStages = [:]
def selectedArches = []
def allValidArches = ['arm64', 'x86_64']
if(params.INCLUDE_LINUX_ARM == true){
selectedArches << 'arm64'
}
if(params.INCLUDE_LINUX_X86_64 == true){
selectedArches << 'x86_64'
}
parallel([failFast: true] << SUPPORTED_LINUX_VERSIONS.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})"){
buildPythonPkg(
agent: [
dockerfile: [
label: "linux && docker && ${arch}",
filename: 'ci/docker/linux/package/Dockerfile',
additionalBuildArgs: "--build-arg PIP_EXTRA_INDEX_URL --build-arg PIP_INDEX_URL --build-arg manylinux_image=${arch=='x86_64'? 'quay.io/pypa/manylinux_2_28_x86_64': 'quay.io/pypa/manylinux_2_28_aarch64'}"
]
],
retries: 3,
buildCmd: {
try{
sh(label: 'Building python wheel',
script:"""python${pythonVersion} -m venv venv
trap "rm -rf venv" EXIT
./venv/bin/pip install --disable-pip-version-check uv
./venv/bin/uv build --index-strategy unsafe-best-match --python ${pythonVersion} --wheel
auditwheel repair ./dist/*.whl -w ./dist
"""
)
} catch(e) {
sh "python${pythonVersion} -m pip list"
throw e
}
},
post:[
cleanup: {
cleanWs(
patterns: [
[pattern: 'dist/', type: 'INCLUDE'],
[pattern: '**/__pycache__/', type: 'INCLUDE'],
],
notFailBuild: true,
deleteDirs: true
)
},
success: {
stash includes: 'dist/*manylinux*.*whl', name: "python${pythonVersion} linux - ${arch} - wheel"
wheelStashes << "python${pythonVersion} linux - ${arch} - wheel"
archiveArtifacts artifacts: 'dist/*.whl'
}
]
)
}
if(params.TEST_PACKAGES == 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_INDEX_STRATEGY=unsafe-best-match',
'UV_TOOL_DIR=/tmp/uvtools',
'UV_PYTHON_INSTALL_DIR=/tmp/uvpython',
'UV_CACHE_DIR=/tmp/uvcache',
"TOX_INSTALL_PKG=${findFiles(glob:'dist/*.whl')[0].path}",
"TOX_ENV=py${pythonVersion.replace('.', '')}"
]){
docker.image('python').inside('--mount source=python-tmp-py3exiv2bind,target=/tmp'){
sh(
label: 'Testing with tox',
script: '''python3 -m venv venv
. ./venv/bin/activate
trap "rm -rf venv" EXIT
pip install --disable-pip-version-check uv
uvx --with tox-uv tox
rm -rf .tox
'''
)
}
}
} finally {
cleanWs(
patterns: [
[pattern: '.tox/', type: 'INCLUDE'],
[pattern: 'dist/', type: 'INCLUDE'],
[pattern: 'venv/', type: 'INCLUDE'],
[pattern: '**/__pycache__/', type: 'INCLUDE'],
]
)
}
}
}
}
}
} else {
Utils.markStageSkippedForConditional(newStageName)
}
}
}
]
})
}
}
]
})
}
def mac_wheels(){
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] << SUPPORTED_MAC_VERSIONS.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})"){
buildPythonPkg(
agent: [
label: "mac && python${pythonVersion} && ${arch}",
],
retries: 3,
buildCmd: {
sh(label: 'Building wheel',
script: "contrib/build_mac_wheel.sh . --venv-path=./venv --base-python=python${pythonVersion}"
)
},
post:[
cleanup: {
cleanWs(
patterns: [
[pattern: 'dist/', type: 'INCLUDE'],
[pattern: 'venv/', type: 'INCLUDE'],
],
notFailBuild: true,
deleteDirs: true
)
},
success: {
stash includes: 'dist/*.whl', name: "python${pythonVersion} mac ${arch} wheel"
wheelStashes << "python${pythonVersion} mac ${arch} wheel"
archiveArtifacts artifacts: 'dist/*.whl'
}
]
)
}
if(params.TEST_PACKAGES == true){
stage("Test Wheel (${pythonVersion} MacOS ${arch})"){
testPythonPkg(
agent: [
label: "mac && python${pythonVersion} && ${arch}",
],
testSetup: {
checkout scm
unstash "python${pythonVersion} mac ${arch} wheel"
},
retries: 3,
testCommand: {
findFiles(glob: 'dist/*.whl').each{
sh(label: 'Running Tox',
script: """python${pythonVersion} -m venv venv
./venv/bin/python -m pip install --disable-pip-version-check --upgrade pip
./venv/bin/pip install --disable-pip-version-check -r requirements-dev.txt
./venv/bin/tox --installpkg ${it.path} -e py${pythonVersion.replace('.', '')}"""
)
}
},
post:[
cleanup: {
cleanWs(
patterns: [
[pattern: 'dist/', type: 'INCLUDE'],
[pattern: 'venv/', type: 'INCLUDE'],
[pattern: '.tox/', type: 'INCLUDE'],
],
notFailBuild: true,
deleteDirs: true
)
}
]
)
}
}
} else {
Utils.markStageSkippedForConditional(newWheelStage)
}
}
}
]
}
)
}
if(params.INCLUDE_MACOS_X86_64 && params.INCLUDE_MACOS_ARM){
stage("Universal2 Wheel: Python ${pythonVersion}"){
stage('Make Universal2 wheel'){
node("mac && python${pythonVersion}") {
checkout scm
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)
}
try{
sh(label: 'Make Universal2 wheel',
script: """python${pythonVersion} -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('.','')}-cp${pythonVersion.replace('.','')}-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 {
cleanWs(
patterns: [
[pattern: 'out/', type: 'INCLUDE'],
[pattern: 'dist/', type: 'INCLUDE'],
[pattern: 'venv/', type: 'INCLUDE'],
],
notFailBuild: true,
deleteDirs: true
)
}
}
}
if(params.TEST_PACKAGES == true){
stage("Test universal2 Wheel"){
def archStages = [:]
['x86_64', 'arm64'].each{arch ->
archStages["Test Python ${pythonVersion} universal2 Wheel on ${arch} mac"] = {
testPythonPkg(
agent: [
label: "mac && python${pythonVersion} && ${arch}",
],
testSetup: {
checkout scm
unstash "python${pythonVersion} mac-universal2 wheel"
},
retries: 3,
testCommand: {
findFiles(glob: 'dist/*.whl').each{
withEnv(['UV_INDEX_STRATEGY=unsafe-best-match']){
sh(label: 'Running Tox',
script: """python${pythonVersion} -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/uvx --python=${pythonVersion} --with-requirements requirements-dev.txt --with tox-uv tox --installpkg ${it.path} -e py${pythonVersion.replace('.', '')}
"""
)
}
}
},
post:[
cleanup: {
cleanWs(
patterns: [
[pattern: 'dist/', type: 'INCLUDE'],
[pattern: 'venv/', type: 'INCLUDE'],
[pattern: '.tox/', type: 'INCLUDE'],
],
notFailBuild: true,
deleteDirs: true
)
},
success: {
archiveArtifacts artifacts: 'dist/*.whl'
}
]
)
}
}
parallel(archStages)
}
}
}
}
}
}
]}
)
}
def get_sonarqube_unresolved_issues(report_task_file){
script{
def props = readProperties file: '.scannerwork/report-task.txt'
def response = httpRequest url : props['serverUrl'] + '/api/issues/search?componentKeys=' + props['projectKey'] + '&resolved=no'
def outstandingIssues = readJSON text: response.content
return outstandingIssues
}
}
// *****************************************************************************
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'
args '--mount source=sonar-cache-py3exiv2bind,target=/opt/sonar/.sonar/cache'
}
}
environment{
PIP_CACHE_DIR='/tmp/pipcache'
UV_INDEX_STRATEGY='unsafe-best-match'
UV_TOOL_DIR='/tmp/uvtools'
UV_PYTHON_INSTALL_DIR='/tmp/uvpython'
UV_CACHE_DIR='/tmp/uvcache'
}
options{
retry(3)
}
stages{
stage('Setup'){
stages{
stage('Setup Testing Environment'){
steps{
sh(
label: 'Create virtual environment',
script: '''python3 -m venv bootstrap_uv
bootstrap_uv/bin/pip install --disable-pip-version-check uv
bootstrap_uv/bin/uv venv venv
. ./venv/bin/activate
bootstrap_uv/bin/uv pip install --index-strategy unsafe-best-match uv
rm -rf bootstrap_uv
uv pip install --index-strategy unsafe-best-match -r requirements-dev.txt
'''
)
}
}
stage('Installing project as editable module'){
steps{
sh(label: 'Building debug build with coverage data',
script: '''mkdir -p build/build_wrapper_output_directory
. ./venv/bin/activate
CFLAGS="--coverage -fprofile-arcs -ftest-coverage" LFLAGS="-lgcov --coverage" build-wrapper-linux --out-dir build/build_wrapper_output_directory uv pip install --verbose -e .
'''
)
}
}
}
}
stage('Building Documentation'){
steps {
catchError(buildResult: 'UNSTABLE', message: 'Building Sphinx documentation has issues', stageResult: 'UNSTABLE') {
sh(label: 'Running Sphinx',
script: '''. ./venv/bin/activate
sphinx-build -b html docs/source build/docs/html -d build/docs/doctrees -v -w logs/build_sphinx.log -W --keep-going
'''
)
}
}
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
}
stages{
stage('Building C++ Tests with coverage data'){
steps{
tee('logs/cmake-build.log'){
sh(label: 'Building C++ Code',
script: '''. ./venv/bin/activate
conan install . -if build/cpp/
cmake -B build/cpp/ -Wdev -DCMAKE_TOOLCHAIN_FILE=build/cpp/conan_paths.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true -DBUILD_TESTING:BOOL=true -Dpyexiv2bind_generate_python_bindings:BOOL=true -DCMAKE_CXX_FLAGS="-fprofile-arcs -ftest-coverage -Wall -Wextra" -DCMAKE_BUILD_TYPE=Debug
'''
)
}
sh '''. ./venv/bin/activate
mkdir -p build/build_wrapper_output_directory
build-wrapper-linux --out-dir build/build_wrapper_output_directory cmake --build build/cpp -j $(grep -c ^processor /proc/cpuinfo) --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'){
parallel {
stage('Clang Tidy Analysis') {
steps{
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/')
}
}
}
post{
always {
recordIssues(
tools: [clangTidy(pattern: 'logs/clang-tidy.log')]
)
}
}
}
stage('Task Scanner'){
steps{
recordIssues(tools: [taskScanner(highTags: 'FIXME', includePattern: 'src/py3exiv2bind/**/*.py, src/py3exiv2bind/**/*.cpp, src/py3exiv2bind/**/*.h', normalTags: 'TODO')])
}
}
stage('Memcheck'){
when{
equals expected: true, actual: params.RUN_MEMCHECK
}
steps{
generate_ctest_memtest_script('memcheck.cmake')
timeout(30){
sh( label: 'Running memcheck',
script: '''. ./venv/bin/activate
ctest -S memcheck.cmake --verbose -j $(grep -c ^processor /proc/cpuinfo)
'''
)
}
}
post{
always{
recordIssues(
filters: [
excludeFile('build/cpp/_deps/*'),
],
tools: [
drMemory(pattern: 'build/cpp/Testing/Temporary/DrMemory/**/results.txt')
]
)
}
}
}
stage('CPP Check'){
steps{
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'
)
}
}
post{
always {
recordIssues(
filters: [
excludeType('unmatchedSuppression'),
excludeType('missingIncludeSystem'),
excludeFile('catch.hpp'),
excludeFile('value.hpp'),
],
tools: [
cppCheck(pattern: 'logs/cppcheck_debug.xml')
]
)
}
}
}
stage('CTest'){
steps{
sh(label: 'Running CTest',
script: '''. ./venv/bin/activate
cd build/cpp
ctest --output-on-failure --no-compress-output -T Test
'''
)
}
post{
always{
xunit(
testTimeMargin: '3000',
thresholdMode: 1,
thresholds: [
failed(),
skipped()
],
tools: [
CTest(
deleteOutputFiles: true,
failIfNotNew: true,
pattern: 'build/Testing/**/*.xml',
skipNoTestFiles: true,
stopProcessingIfError: true
)
]
)
}
}
}
stage('Run Doctest Tests'){
steps {
sh '''. ./venv/bin/activate
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
'''
}
post{
always {
recordIssues(tools: [sphinxBuild(name: 'Doctest', pattern: 'logs/doctest_warnings.log', id: 'doctest')])
}
}
}
stage('MyPy Static Analysis') {
steps{
tee('logs/mypy.log'){
sh(returnStatus: true,
script: '''. ./venv/bin/activate
mypy -p py3exiv2bind --html-report reports/mypy/html
'''
)
}
}
post {
always {
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: ''])
}
}
}
stage('Run Pylint Static Analysis') {
steps{
catchError(buildResult: 'SUCCESS', message: 'Pylint found issues', stageResult: 'UNSTABLE') {
sh(
script: '''mkdir -p logs
mkdir -p reports
. ./venv/bin/activate
PYLINTHOME=. 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: '''. ./venv/bin/activate
PYLINTHOME=. pylint -r n --msg-template="{path}:{module}:{line}: [{msg_id}({symbol}), {obj}] {msg}" > reports/pylint_issues.txt
''',
returnStatus: true
)
}
post{
always{
stash includes: 'reports/pylint_issues.txt,reports/pylint.txt', name: 'PYLINT_REPORT'
recordIssues(tools: [pyLint(pattern: 'reports/pylint.txt')])
}
}
}
stage('Flake8') {
steps{
sh(
returnStatus: true,
script: '''. ./venv/bin/activate
flake8 src/py3exiv2bind --tee --output-file ./logs/flake8.log
'''
)
}
post {
always {
stash includes: 'logs/flake8.log', name: 'FLAKE8_REPORT'
recordIssues(tools: [flake8(name: 'Flake8', pattern: 'logs/flake8.log')])
}
}
}
stage('Running Unit Tests'){
steps{
sh '''. ./venv/bin/activate
coverage run --parallel-mode --source=src/py3exiv2bind -m pytest --junitxml=./reports/pytest/junit-pytest.xml
'''
}
post{
always{
stash includes: 'reports/pytest/junit-pytest.xml', name: 'PYTEST_REPORT'
junit 'reports/pytest/junit-pytest.xml'
}
}
}
}
}
}
post{
always{
sh(label: 'combining coverage data',
script: '''mkdir -p reports/coverage
. ./venv/bin/activate
coverage combine
coverage xml -o ./reports/coverage/coverage-python.xml
gcovr --root . --filter src/py3exiv2bind --exclude-directories build/cpp/_deps/libcatch2-build --exclude-directories build/python/temp/conan_cache --exclude-throw-branches --exclude-unreachable-branches --print-summary --keep --json -o reports/coverage/coverage-c-extension.json
gcovr --root . --filter src/py3exiv2bind --exclude-directories build/cpp/_deps/libcatch2-build --exclude-throw-branches --exclude-unreachable-branches --print-summary --keep --json -o reports/coverage/coverage_cpp.json
gcovr --add-tracefile reports/coverage/coverage-c-extension.json --add-tracefile reports/coverage/coverage_cpp.json --keep --print-summary --xml -o reports/coverage/coverage_cpp.xml --sonarqube -o reports/coverage/coverage_cpp_sonar.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
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) {
if (env.CHANGE_ID){
sh(
label: 'Running Sonar Scanner',
script: """. ./venv/bin/activate
uvx pysonar-scanner -Dsonar.projectVersion=\$VERSION -Dsonar.buildString=\"${env.BUILD_TAG}\" -Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.cfamily.cache.enabled=false -Dsonar.cfamily.threads=\$(grep -c ^processor /proc/cpuinfo) -Dsonar.cfamily.build-wrapper-output=build/build_wrapper_output_directory
"""
)
} else {
sh(
label: 'Running Sonar Scanner',
script: """. ./venv/bin/activate
uvx pysonar-scanner -Dsonar.projectVersion=\$VERSION -Dsonar.buildString=\"${env.BUILD_TAG}\" -Dsonar.branch.name=${env.BRANCH_NAME} -Dsonar.cfamily.cache.enabled=false -Dsonar.cfamily.threads=\$(grep -c ^processor /proc/cpuinfo) -Dsonar.cfamily.build-wrapper-output=build/build_wrapper_output_directory
"""
)
}
}
timeout(time: 1, unit: 'HOURS') {
def sonarqube_result = waitForQualityGate(abortPipeline: false)
if (sonarqube_result.status != 'OK') {
unstable "SonarQube quality gate: ${sonarqube_result.status}"
}
def outstandingIssues = get_sonarqube_unresolved_issues('.scannerwork/report-task.txt')
writeJSON file: 'reports/sonar-report.json', json: outstandingIssues
}
}
}
post {
always{
milestone 1
script{
if(fileExists('reports/sonar-report.json')){
recordIssues(tools: [sonarQube(pattern: 'reports/sonar-report.json')])
}
}
}
}
}
}
post{
cleanup{
cleanWs(
patterns: [
[pattern: '.coverage/', type: 'INCLUDE'],
[pattern: '.eggs/', type: 'INCLUDE'],
[pattern: '.mypy_cache/', type: 'INCLUDE'],
[pattern: '.pytest_cache/', type: 'INCLUDE'],
[pattern: 'dist/', type: 'INCLUDE'],
[pattern: 'build/', type: 'INCLUDE'],
[pattern: '*.dist-info/', type: 'INCLUDE'],
[pattern: 'logs/', type: 'INCLUDE'],
[pattern: 'reports/', type: 'INCLUDE'],
[pattern: 'generatedJUnitFiles/', type: 'INCLUDE'],
[pattern: 'py3exiv2bind/*.so', type: 'INCLUDE'],
[pattern: '**/__pycache__/', type: 'INCLUDE'],
[pattern: 'venv/', type: 'INCLUDE'],
],
notFailBuild: true,
deleteDirs: true
)
}
}
}
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_INDEX_STRATEGY='unsafe-best-match'
UV_TOOL_DIR='/tmp/uvtools'
UV_PYTHON_INSTALL_DIR='/tmp/uvpython'
UV_CACHE_DIR='/tmp/uvcache'
}
when{
expression {return nodesByLabel('linux && docker').size() > 0}
}
steps{
script{
def envs = []
node('docker && linux'){
docker.image('python').inside('--mount source=python-tmp-py3exiv2bind,target=/tmp'){
try{
checkout scm
sh(script: 'python3 -m venv venv && venv/bin/pip install --disable-pip-version-check uv')
envs = sh(
label: 'Get tox environments',
script: './venv/bin/uvx --quiet --with tox-uv tox list -d --no-desc',
returnStdout: true,
).trim().split('\n')
} finally{
cleanWs(
patterns: [
[pattern: 'venv/', type: 'INCLUDE'],
[pattern: '.tox', type: 'INCLUDE'],
[pattern: '**/__pycache__/', type: 'INCLUDE'],
]
)
}
}
}
parallel(
envs.collectEntries{toxEnv ->
def version = toxEnv.replaceAll(/py(\d)(\d+)/, '$1.$2')
[
"Tox Environment: ${toxEnv}",
{
node('docker && linux'){
checkout scm
def image
lock("${env.JOB_NAME} - ${env.NODE_NAME}"){
image = docker.build(UUID.randomUUID().toString(), '-f ci/docker/linux/tox/Dockerfile --build-arg PIP_EXTRA_INDEX_URL --build-arg PIP_INDEX_URL .')
}
try{
image.inside('--mount source=python-tmp-tox-py3exiv2bind,target=/tmp'){
retry(3){