From 81886bc3588d957a6e82035c430c975bcf81428f Mon Sep 17 00:00:00 2001 From: Henry Borchers Date: Fri, 1 Nov 2024 12:59:18 -0500 Subject: [PATCH] ci: use pyproject.toml for project metadata --- Jenkinsfile | 103 ++++++++++------------------ ci/jenkins/scripts/sonarqube.groovy | 36 ---------- 2 files changed, 37 insertions(+), 102 deletions(-) delete mode 100644 ci/jenkins/scripts/sonarqube.groovy diff --git a/Jenkinsfile b/Jenkinsfile index 2f5fdd99..f033f8ac 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -504,7 +504,8 @@ def mac_wheels(){ ) def fusedWheel = findFiles(excludes: '', glob: 'out/*.whl')[0] def pythonVersionShort = pythonVersion.replace('.','') - def universalWheel = "uiucprescon.ocr-${props.Version}-cp${pythonVersionShort}-cp${pythonVersionShort}-macosx_11_0_universal2.whl" + def props = readTOML( file: 'pyproject.toml')['project'] + def universalWheel = "uiucprescon.ocr-${props.version}-cp${pythonVersionShort}-cp${pythonVersionShort}-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" @@ -623,32 +624,17 @@ def mac_wheels(){ } parallel(wheelStages) } +def get_sonarqube_unresolved_issues(report_task_file){ + script{ -def get_props(){ - stage('Reading Package Metadata'){ - node() { - try{ - unstash 'DIST-INFO' - def metadataFile = findFiles(excludes: '', glob: '*.dist-info/METADATA')[0] - def package_metadata = readProperties interpolate: true, file: metadataFile.path - echo """Metadata: - - Name ${package_metadata.Name} - Version ${package_metadata.Version} - """ - return package_metadata - } finally { - cleanWs( - patterns: [ - [pattern: '*.dist-info/**', type: 'INCLUDE'], - ], - notFailBuild: true, - deleteDirs: true - ) - } - } + 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 } } + + def startup(){ def SONARQUBE_CREDENTIAL_ID = SONARQUBE_CREDENTIAL_ID parallel( @@ -669,47 +655,11 @@ def startup(){ } } }, - 'Getting Distribution Info': { - stage('Getting Distribution Info'){ - node('linux && docker') { - timeout(2){ - ws{ - checkout scm - try{ - docker.image('python').inside { - withEnv(['PIP_NO_CACHE_DIR=off']) { - sh( - label: 'Running setup.py with dist_info', - script: '''python --version - python setup.py dist_info - ''' - ) - } - stash includes: '*.dist-info/**', name: 'DIST-INFO' - archiveArtifacts artifacts: '*.dist-info/**' - } - } finally{ - cleanWs( - patterns: [ - [pattern: '*.dist-info/**', type: 'INCLUDE'], - [pattern: '.eggs/', type: 'INCLUDE'], - [pattern: '**/__pycache__/', type: 'INCLUDE'], - ], - notFailBuild: true, - deleteDirs: true - ) - } - } - } - } - } - } ] ) } stage('Pipeline Pre-tasks'){ startup() - props = get_props() } pipeline { agent none @@ -783,7 +733,11 @@ pipeline { } success{ publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'build/docs/html', reportFiles: 'index.html', reportName: 'Documentation', reportTitles: '']) - zip archive: true, dir: 'build/docs/html', glob: '', zipFile: "dist/${props.Name}-${props.Version}.doc.zip" + 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' } } @@ -1000,11 +954,28 @@ pipeline { } steps{ script{ - load('ci/jenkins/scripts/sonarqube.groovy').sonarcloudSubmit( - props, - 'reports/sonar-report.json', - SONARQUBE_CREDENTIAL_ID - ) + def props = readTOML( file: 'pyproject.toml')['project'] + withSonarQubeEnv(installationName:'sonarcloud', credentialsId: SONARQUBE_CREDENTIAL_ID) { + if (env.CHANGE_ID){ + sh( + label: 'Running Sonar Scanner', + script: "sonar-scanner -Dsonar.projectVersion=${props.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: "sonar-scanner -Dsonar.projectVersion=${props.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 { diff --git a/ci/jenkins/scripts/sonarqube.groovy b/ci/jenkins/scripts/sonarqube.groovy deleted file mode 100644 index eb08dab2..00000000 --- a/ci/jenkins/scripts/sonarqube.groovy +++ /dev/null @@ -1,36 +0,0 @@ - -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 - } -} - -def sonarcloudSubmit(props, outputJson, sonarCredentials){ - withSonarQubeEnv(installationName:'sonarcloud', credentialsId: sonarCredentials) { - if (env.CHANGE_ID){ - sh( - label: 'Running Sonar Scanner', - script:"sonar-scanner -Dsonar.projectVersion=${props.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: "sonar-scanner -Dsonar.projectVersion=${props.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: outputJson, json: outstandingIssues - } -} - -return this \ No newline at end of file