diff --git a/vars/runJenkinsPipeline.groovy b/vars/runJenkinsPipeline.groovy index 7be4f442..c156ef78 100644 --- a/vars/runJenkinsPipeline.groovy +++ b/vars/runJenkinsPipeline.groovy @@ -1,7 +1,3 @@ -library identifier: 'JenkinsPythonHelperLibrary@2024.1.2', retriever: modernSCM( - [$class: 'GitSCMSource', - remote: 'https://github.com/UIUCLibrary/JenkinsPythonHelperLibrary.git', - ]) def getVersion(){ node(){ checkout scm @@ -102,6 +98,15 @@ def hasSonarCreds(credentialsId){ return true } def call(){ + library( + identifier: 'JenkinsPythonHelperLibrary@2024.12.0', + retriever: modernSCM( + [ + $class: 'GitSCMSource', + remote: 'https://github.com/UIUCLibrary/JenkinsPythonHelperLibrary.git' + ] + ) + ) pipeline { agent none parameters { @@ -669,159 +674,123 @@ def call(){ } } } - stage('Testing Python Package'){ + stage('Testing Packages'){ when{ equals expected: true, actual: params.TEST_PACKAGES } - matrix { - axes { - axis { - name 'PYTHON_VERSION' - values '3.9', '3.10', '3.11', '3.12', '3.13' - } - axis { - name 'OS' - values 'linux', 'macos', 'windows' - } - axis { - name 'ARCHITECTURE' - values 'arm64', 'x86_64' - } - axis { - name 'PACKAGE_TYPE' - values 'wheel', 'sdist' - } - } - excludes { - exclude { - axis { - name 'ARCHITECTURE' - values 'arm64' - } - axis { - name 'OS' - values 'windows' - } - } - } - when{ - expression{ - params.containsKey("INCLUDE_${OS}-${ARCHITECTURE}".toUpperCase()) && params["INCLUDE_${OS}-${ARCHITECTURE}".toUpperCase()] - } - } - options { - retry(conditions: [agent()], count: 2) - } - environment{ - UV_PYTHON="${PYTHON_VERSION}" - TOX_ENV="py${PYTHON_VERSION.replace('.', '')}" - UV_INDEX_STRATEGY='unsafe-best-match' - } - stages { - stage('Test Package in container') { - when{ - expression{['linux', 'windows'].contains(OS)} - beforeAgent true - } - environment{ - PIP_CACHE_DIR="${isUnix() ? '/tmp/pipcache': 'C:\\Users\\ContainerUser\\Documents\\pipcache'}" - UV_TOOL_DIR="${isUnix() ? '/tmp/uvtools': 'C:\\Users\\ContainerUser\\Documents\\uvtools'}" - UV_PYTHON_INSTALL_DIR="${isUnix() ? '/tmp/uvpython': 'C:\\Users\\ContainerUser\\Documents\\uvpython'}" - UV_CACHE_DIR="${isUnix() ? '/tmp/uvcache': 'C:\\Users\\ContainerUser\\Documents\\uvcache'}" - } - agent { - docker { - image 'python' - label "${OS} && ${ARCHITECTURE} && docker" - args "--mount source=uv_python_install_dir,target=${env.UV_PYTHON_INSTALL_DIR} ${['windows'].contains(OS) ? '--mount source=msvc-runtime,target=c:\\msvc_runtime\\': ''}" - } - } - steps { - unstash 'PYTHON_PACKAGES' - script{ - withEnv( - ["TOX_INSTALL_PKG=${findFiles(glob: PACKAGE_TYPE == 'wheel' ? 'dist/*.whl' : 'dist/*.tar.gz')[0].path}"] - ) { - if(isUnix()){ - 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 - ''' - ) - } else { - installMSVCRuntime('c:\\msvc_runtime\\') - script{ - retry(3){ - bat( - label: 'Testing with tox', - script: '''python -m venv venv - call venv\\Scripts\\activate.bat - pip install --disable-pip-version-check uv - uvx --with tox-uv tox - rmdir /S /Q .tox - rmdir /S /Q venv - ''' - ) - } - } - } - } - } - } - post{ - cleanup{ - cleanWs( - patterns: [ - [pattern: 'dist/', type: 'INCLUDE'], - [pattern: 'venv/', type: 'INCLUDE'], - [pattern: '**/__pycache__/', type: 'INCLUDE'], - ] - ) - } - } - } - stage('Test Package directly on agent') { - when{ - expression{['macos'].contains(OS)} - beforeAgent true - } - agent { - label "${OS} && ${ARCHITECTURE}" - } - steps { - unstash 'PYTHON_PACKAGES' - withEnv( - ["TOX_INSTALL_PKG=${findFiles(glob: PACKAGE_TYPE == 'wheel' ? 'dist/*.whl' : 'dist/*.tar.gz')[0].path}"] - ) { - sh( - label: 'Testing with tox', - script: '''python3 -m venv venv - trap "rm -rf venv" EXIT - . ./venv/bin/activate - pip install --disable-pip-version-check uv - uvx --with tox-uv tox - ''' - ) - } - } - post{ - cleanup{ - cleanWs( - patterns: [ - [pattern: 'dist/', type: 'INCLUDE'], - [pattern: 'venv/', type: 'INCLUDE'], - [pattern: '**/__pycache__/', type: 'INCLUDE'], - ] - ) - } - } - } - } - } + environment{ + UV_INDEX_STRATEGY='unsafe-best-match' + } + steps{ + customMatrix( + axes: [ + [ + name: 'PYTHON_VERSION', + values: ['3.9', '3.10', '3.11', '3.12','3.13'] + ], + [ + name: 'OS', + values: ['linux','macos','windows'] + ], + [ + name: 'ARCHITECTURE', + values: ['x86_64', 'arm64'] + ], + [ + name: 'PACKAGE_TYPE', + values: ['wheel', 'sdist'], + ] + ], + excludes: [ + [ + [ + name: 'OS', + values: 'windows' + ], + [ + name: 'ARCHITECTURE', + values: 'arm64', + ] + ] + ], + when: {entry -> "INCLUDE_${entry.OS}-${entry.ARCHITECTURE}".toUpperCase() && params["INCLUDE_${entry.OS}-${entry.ARCHITECTURE}".toUpperCase()]}, + stages: [ + { entry -> + stage('Test Package') { + node("${entry.OS} && ${entry.ARCHITECTURE} ${['linux', 'windows'].contains(entry.OS) ? '&& docker': ''}"){ + try{ + checkout scm + unstash 'PYTHON_PACKAGES' + if(['linux', 'windows'].contains(entry.OS) && params.containsKey("INCLUDE_${entry.OS}-${entry.ARCHITECTURE}".toUpperCase()) && params["INCLUDE_${entry.OS}-${entry.ARCHITECTURE}".toUpperCase()]){ + docker.image('python').inside(isUnix() ? '': "--mount type=volume,source=uv_python_install_dir,target=C:\\Users\\ContainerUser\\Documents\\uvpython --mount source=msvc-runtime,target=c:\\msvc_runtime\\"){ + if(isUnix()){ + withEnv([ + 'PIP_CACHE_DIR=/tmp/pipcache', + 'UV_TOOL_DIR=/tmp/uvtools', + 'UV_PYTHON_INSTALL_DIR=/tmp/uvpython', + 'UV_CACHE_DIR=/tmp/uvcache', + ]){ + sh( + label: 'Testing with tox', + script: """python3 -m venv venv + ./venv/bin/pip install --disable-pip-version-check uv + ./venv/bin/uv python install cpython-${entry.PYTHON_VERSION} + ./venv/bin/uvx --with tox-uv tox --installpkg ${findFiles(glob: entry.PACKAGE_TYPE == 'wheel' ? 'dist/*.whl' : 'dist/*.tar.gz')[0].path} -e py${entry.PYTHON_VERSION.replace('.', '')} + """ + ) + } + } else { + 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', + ]){ + installMSVCRuntime('c:\\msvc_runtime\\') + bat( + label: 'Testing with tox', + script: """python -m venv venv + .\\venv\\Scripts\\pip install --disable-pip-version-check uv + .\\venv\\Scripts\\uv python install cpython-${entry.PYTHON_VERSION} + .\\venv\\Scripts\\uvx --with tox-uv tox --installpkg ${findFiles(glob: entry.PACKAGE_TYPE == 'wheel' ? 'dist/*.whl' : 'dist/*.tar.gz')[0].path} -e py${entry.PYTHON_VERSION.replace('.', '')} + """ + ) + } + } + } + } else { + if(isUnix()){ + sh( + label: 'Testing with tox', + script: """python3 -m venv venv + ./venv/bin/pip install --disable-pip-version-check uv + ./venv/bin/uvx --with tox-uv tox --installpkg ${findFiles(glob: entry.PACKAGE_TYPE == 'wheel' ? 'dist/*.whl' : 'dist/*.tar.gz')[0].path} -e py${entry.PYTHON_VERSION.replace('.', '')} + """ + ) + } else { + bat( + label: 'Testing with tox', + script: """python -m venv venv + .\\venv\\Scripts\\pip install --disable-pip-version-check uv + .\\venv\\Scripts\\uv python install cpython-${entry.PYTHON_VERSION} + .\\venv\\Scripts\\uvx --with tox-uv tox --installpkg ${findFiles(glob: entry.PACKAGE_TYPE == 'wheel' ? 'dist/*.whl' : 'dist/*.tar.gz')[0].path} -e py${entry.PYTHON_VERSION.replace('.', '')} + """ + ) + } + } + } finally{ + if(isUnix()){ + sh "${tool(name: 'Default', type: 'git')} clean -dfx" + } else { + bat "${tool(name: 'Default', type: 'git')} clean -dfx" + } + } + } + } + } + ] + ) + } } } }