@@ -28,22 +28,34 @@ pipeline {
2828 }
2929 },
3030
31- " PEP8 " : {
31+ " Ruff " : {
3232 node(label : ' docker' ) {
3333 script {
34- sh ''' docker run -i --rm --name="$BUILD_TAG-pep8" -e GIT_SRC="https://github.com/eea/$GIT_NAME.git" -e GIT_NAME="$GIT_NAME" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/pep8'''
35- }
36- }
37- },
38-
39- " PyLint" : {
40- node(label : ' docker' ) {
41- script {
42- sh ''' docker run -i --rm --name="$BUILD_TAG-pylint" -e GIT_SRC="https://github.com/eea/$GIT_NAME.git" -e GIT_NAME="$GIT_NAME" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/pylint'''
34+ if (! (env. BRANCH_NAME != " master" && (env. CHANGE_ID == null || env. CHANGE_ID == ' ' ))) {
35+ return
36+ }
37+ checkout scm
38+ fix_result = sh(script : ''' docker run --pull=always --name="$BUILD_TAG-ruff-fix" -e GIT_SRC="https://github.com/eea/$GIT_NAME.git" -e GIT_NAME="$GIT_NAME" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/ruff format''' , returnStatus : true )
39+ sh ''' docker cp $BUILD_TAG-ruff-fix:/code/$GIT_NAME .'''
40+ sh ''' cp -rf eea.website.policy/* .'''
41+ sh ''' rm -rf eea.website.policy'''
42+ sh ''' docker rm -v $BUILD_TAG-ruff-fix'''
43+ FOUND_FIX = sh(script : ''' git diff --name-only '*.py' | wc -l''' , returnStdout : true ). trim()
44+
45+ if (FOUND_FIX != ' 0' ) {
46+ withCredentials([string(credentialsId : ' eea-jenkins-token' , variable : ' GITHUB_TOKEN' )]) {
47+ sh ''' sed -i "s|url = .*|url = https://eea-jenkins:$GITHUB_TOKEN@github.com/eea/$GIT_NAME.git|" .git/config'''
48+ }
49+ sh ''' git fetch origin $GIT_BRANCH:$GIT_BRANCH'''
50+ sh ''' git checkout $GIT_BRANCH'''
51+ sh ''' git add -- '*.py' '''
52+ sh ''' git commit -m "style: Automated code fix" '''
53+ sh ''' git push --set-upstream origin $GIT_BRANCH'''
54+ sh ''' exit 1'''
55+ }
4356 }
4457 }
4558 }
46-
4759 )
4860 }
4961 }
@@ -64,9 +76,32 @@ pipeline {
6476 }
6577 },
6678
67- " PyFlakes " : {
79+ " Ruff " : {
6880 node(label : ' docker' ) {
69- sh ''' docker run -i --rm --name="$BUILD_TAG-pyflakes" -e GIT_SRC="https://github.com/eea/$GIT_NAME.git" -e GIT_NAME="$GIT_NAME" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/pyflakes'''
81+ script {
82+ if (! (env. BRANCH_NAME != " master" && (env. CHANGE_ID == null || env. CHANGE_ID == ' ' ))) {
83+ return
84+ }
85+ checkout scm
86+ fix_result = sh(script : ''' docker run --pull=always --name="$BUILD_TAG-ruff-fix" -e GIT_SRC="https://github.com/eea/$GIT_NAME.git" -e GIT_NAME="$GIT_NAME" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/ruff check''' , returnStatus : true )
87+ sh ''' docker cp $BUILD_TAG-ruff-fix:/code/$GIT_NAME .'''
88+ sh ''' cp -rf eea.website.policy/* .'''
89+ sh ''' rm -rf eea.website.policy'''
90+ sh ''' docker rm -v $BUILD_TAG-ruff-fix'''
91+ FOUND_FIX = sh(script : ''' git diff --name-only '*.py' | wc -l''' , returnStdout : true ). trim()
92+
93+ if (FOUND_FIX != ' 0' ) {
94+ withCredentials([string(credentialsId : ' eea-jenkins-token' , variable : ' GITHUB_TOKEN' )]) {
95+ sh ''' sed -i "s|url = .*|url = https://eea-jenkins:$GITHUB_TOKEN@github.com/eea/$GIT_NAME.git|" .git/config'''
96+ }
97+ sh ''' git fetch origin $GIT_BRANCH:$GIT_BRANCH'''
98+ sh ''' git checkout $GIT_BRANCH'''
99+ sh ''' git add -- '*.py' '''
100+ sh ''' git commit -m "lint: Automated code fix" '''
101+ sh ''' git push --set-upstream origin $GIT_BRANCH'''
102+ sh ''' exit 1'''
103+ }
104+ }
70105 }
71106 },
72107
@@ -79,56 +114,46 @@ pipeline {
79114 }
80115 }
81116
82- // stage('Tests') {
83- // steps {
84- // parallel(
85- // "Plone 5": {
86- // node(label: 'docker') {
87- // sh '''docker run -i --rm --name="$BUILD_TAG-plone5" -e GIT_BRANCH="$BRANCH_NAME" -e ADDONS="$GIT_NAME" -e DEVELOP="src/$GIT_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/plone-test:5-python3 -v -vv -s $GIT_NAME'''
88- // }
89- // },
90-
91- // // "Plone 6": {
92- // // node(label: 'docker') {
93- // // script {
94- // // checkout scm
95- // // sh '''docker run -i --rm --name="$BUILD_TAG-plone6" -v $(pwd):/app/src/$GIT_NAME -e ADDONS="/app/src/$GIT_NAME[test]" -e DEVELOP="/app/src/$GIT_NAME" eeacms/eea-website-backend bin/zope-testrunner --auto-color --auto-progress --test-path /app/src/$GIT_NAME'''
96- // // }
97- // // }
98- // // }
99- // )
100- // }
101- // }
102-
103- // stage('Report to SonarQube') {
104- // when {
105- // allOf {
106- // environment name: 'CHANGE_ID', value: ''
107- // }
108- // }
109- // steps {
110- // node(label: 'swarm') {
111- // script{
112- // checkout scm
113- // // dir("xunit-reports") {
114- // // unstash "xunit-reports"
115- // // }
116- // // unstash "coverage.xml"
117- // // dir('xunit-functional') {
118- // // unstash "xunit-functional"
119- // // }
120- // def scannerHome = tool 'SonarQubeScanner';
121- // def nodeJS = tool 'NodeJS11';
122- // withSonarQubeEnv('Sonarqube') {
123- // // sh '''sed -i "s|/plone/instance/src/$GIT_NAME|$(pwd)|g" coverage.xml'''
124- // // sh '''find xunit-functional -type f -exec mv {} xunit-reports/ ";"'''
125- // sh "export PATH=$PATH:${scannerHome}/bin:${nodeJS}/bin; sonar-scanner -Dsonar.python.xunit.skipDetails=true -Dsonar.python.xunit.reportPath=xunit-reports/*.xml -Dsonar.python.coverage.reportPath=coverage.xml -Dsonar.sources=./eea -Dsonar.projectKey=$GIT_NAME-$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME-$BUILD_NUMBER"
126- // sh '''try=2; while [ \$try -gt 0 ]; do curl -s -XPOST -u "${SONAR_AUTH_TOKEN}:" "${SONAR_HOST_URL}api/project_tags/set?project=${GIT_NAME}-${BRANCH_NAME}&tags=${SONARQUBE_TAGS},${BRANCH_NAME}" > set_tags_result; if [ \$(grep -ic error set_tags_result ) -eq 0 ]; then try=0; else cat set_tags_result; echo "... Will retry"; sleep 60; try=\$(( \$try - 1 )); fi; done'''
127- // }
128- // }
129- // }
130- // }
131- // }
117+ stage(' Tests' ) {
118+ steps {
119+ parallel(
120+ " Plone6 & Python3" : {
121+ node(label : ' docker' ) {
122+ sh ''' docker run --pull="always" -i --name="$BUILD_TAG-tests" -e GIT_NAME="$GIT_NAME" -e GIT_BRANCH="$BRANCH_NAME" -e DEVELOP="src/$GIT_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/plone-test:6'''
123+ sh ''' docker cp $BUILD_TAG-tests:/app/coverage ./coverage'''
124+ sh ''' docker rm -v $BUILD_TAG-tests'''
125+ stash includes : ' coverage/**' , name : ' coverage'
126+ }
127+ }
128+ )
129+ }
130+ }
131+
132+ stage(' Report to SonarQube' ) {
133+ when {
134+ allOf {
135+ environment name : ' CHANGE_ID' , value : ' '
136+ }
137+ }
138+ steps {
139+ node(label : ' swarm' ) {
140+ script {
141+ checkout scm
142+ unstash ' coverage'
143+ junit ' coverage/junit-results/testreports/*.xml'
144+ def scannerHome = tool ' SonarQubeScanner' ;
145+ def nodeJS = tool ' NodeJS11' ;
146+ sh " sed -i 's|<source>/app</source>|<source>.</source>|g' coverage/coverage.xml"
147+ sh " sed -i \" s|filename=\\\" src/$GIT_NAME /|filename=\\\" |g\" coverage/coverage.xml"
148+ sh " sed -i \" s|package name=\\\" src\\ .$GIT_NAME |package name=\\\" |g\" coverage/coverage.xml"
149+ withSonarQubeEnv(' Sonarqube' ) {
150+ sh " export PATH=$PATH :${ scannerHome} /bin:${ nodeJS} /bin; sonar-scanner -Dsonar.python.xunit.skipDetails=true -Dsonar.python.xunit.reportPath=coverage/junit-results/testreports/*.xml -Dsonar.python.coverage.reportPaths=coverage/coverage.xml -Dsonar.sources=./eea -Dsonar.exclusions=**/tests/**,**/setup.py -Dsonar.projectKey=$GIT_NAME -$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME -$BUILD_NUMBER "
151+ sh ''' try=2; while [ \$ try -gt 0 ]; do curl -s -XPOST -u "${SONAR_AUTH_TOKEN}:" "${SONAR_HOST_URL}api/project_tags/set?project=${GIT_NAME}-${BRANCH_NAME}&tags=${SONARQUBE_TAGS},${BRANCH_NAME}" > set_tags_result; if [ \$ (grep -ic error set_tags_result ) -eq 0 ]; then try=0; else cat set_tags_result; echo "... Will retry"; sleep 60; try=\$ (( \$ try - 1 )); fi; done'''
152+ }
153+ }
154+ }
155+ }
156+ }
132157
133158 stage(' Pull Request' ) {
134159 when {
0 commit comments