diff --git a/jobs/templates/includes/stage-python-tests.groovy.j2 b/jobs/templates/includes/stage-python-tests.groovy.j2 new file mode 100644 index 0000000..3237e34 --- /dev/null +++ b/jobs/templates/includes/stage-python-tests.groovy.j2 @@ -0,0 +1,34 @@ +stage('Unit tests') { + options { + timeout(time: 20, unit: 'MINUTES') + } + steps { + sh ''' + python3 -m tox -e $TOX_ENVIRONMENT -- \ + --cov-report=xml \ + --junit-xml=test-results.xml \ + -v + ''' + } + post { + always { + step([$class: 'CoberturaPublisher', + autoUpdateHealth: false, + autoUpdateStability: false, + coberturaReportFile: 'coverage.xml', + failNoReports: false, + failUnhealthy: false, + failUnstable: false, + maxNumberOfBuilds: 10, + onlyStable: false, + sourceEncoding: 'ASCII', + zoomCoverageChart: false]) + + // JUnit report + junit( + allowEmptyResults: true, + testResults: 'test-results.xml', + ) + } + } // post +} // unit tests diff --git a/jobs/templates/swh-pipeline.groovy.j2 b/jobs/templates/swh-pipeline.groovy.j2 index df063c0..9e5313c 100644 --- a/jobs/templates/swh-pipeline.groovy.j2 +++ b/jobs/templates/swh-pipeline.groovy.j2 @@ -1,137 +1,106 @@ pipeline { agent { docker { image 'swh-jenkins/{{docker_image}}' args '--tmpfs /tmp:exec --mount type=volume,src=shared-jenkins-cachedir,dst=/home/jenkins/.cache' } } environment { PHAB_CONDUIT_URL = 'https://forge.softwareheritage.org/api/' } stages { stage('Checkout') { steps { {% filter indent(width=8) %} {%- include 'includes/create-phabricator-artifacts.groovy.j2' -%} {% endfilter %} checkout([ $class: 'GitSCM', branches: [[name: "${params.REVISION}"]], doGenerateSubmoduleConfigurations: false, extensions: [], gitTool: 'Default', submoduleCfg: [], userRemoteConfigs: [ [url: 'https://forge.softwareheritage.org/source/{{repo_name}}.git'], ], browser: [$class: 'Phabricator', repoUrl: 'https://forge.softwareheritage.org', repo: '{{name}}'] ]) } } {%- if phabricator_diff %} {% filter indent(width=4) %} {%- include 'includes/stage-apply-phabricator-diff.groovy.j2' -%} {% endfilter %} {%- endif %} stage('Cleanup') { steps { {% filter indent(width=8) %} {%- include 'includes/cleanup-workspace.groovy.j2' -%} {% endfilter %} } } stage('Static analysis') { steps { echo 'flake8' sh '''python3 -m tox -e flake8''' echo 'mypy' sh '''if python3 -m tox -a 2>/dev/null | grep -qx mypy ; then python3 -m tox -e mypy ; fi''' echo 'radon'; sh ''' mkdir -p reports python3 -m radon raw --json swh/ > reports/raw_report.json python3 -m radon cc --json swh/ > reports/cc_report.json python3 -m radon mi --json swh/ > reports/mi_report.json python3 -m radon hal --json swh/ > reports/hal_report.json python3 -m radon cc --xml swh/ > reports/cc_report.xml ''' } post { always { // Warnings NG recordIssues( enabledForFailure: true, tools: [ ccm(pattern: '**/reports/cc_report.xml'), ], ) } } } // static analysis - stage('Unit tests') { - options { - timeout(time: 20, unit: 'MINUTES') - } - steps { - sh ''' - python3 -m tox -e $TOX_ENVIRONMENT -- \ - --cov-report=xml \ - --junit-xml=test-results.xml \ - -v - ''' - } - post { - always { - step([$class: 'CoberturaPublisher', - autoUpdateHealth: false, - autoUpdateStability: false, - coberturaReportFile: 'coverage.xml', - failNoReports: false, - failUnhealthy: false, - failUnstable: false, - maxNumberOfBuilds: 10, - onlyStable: false, - sourceEncoding: 'ASCII', - zoomCoverageChart: false]) - - // JUnit report - junit( - allowEmptyResults: true, - testResults: 'test-results.xml', - ) - } - } // post - } // unit tests + {% filter indent(width=4) %} + {%- include 'includes/stage-python-tests.groovy.j2' -%} + {% endfilter %} } // stages post { always { // Archive a few report files archiveArtifacts allowEmptyArchive: true, artifacts: 'reports/*,*.xml,tox*.ini', fingerprint: true step([$class: 'PhabricatorNotifier', commentOnSuccess: true, commentWithConsoleLinkOnFailure: true, commentFile: '.phabricator-comment', commentSize: '1000000', preserveFormatting: true, processLint: true, lintFile: '.phabricator-lint', lintFileSize: '1000000', ]) {% filter indent(width=6) %} {%- include 'includes/cleanup-workspace.groovy.j2' -%} {% endfilter %} } // always } // post } // pipeline