From af2513e56ee40681c791926d5119fe6e069b7ffd Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 3 Jun 2020 09:37:55 +0200 Subject: [PATCH] jenkins: adopt authentic way of doing tox.ini and Jenkinsfile --- Jenkinsfile | 16 +++++++++++--- pylint.sh | 5 +++++ tests/conftest.py | 4 ++-- tox.ini | 56 +++++++++++++++++++++++++++++++++-------------- 4 files changed, 59 insertions(+), 22 deletions(-) create mode 100755 pylint.sh diff --git a/Jenkinsfile b/Jenkinsfile index 052f976..fc7f6a9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,19 +2,28 @@ pipeline { agent any + options { disableConcurrentBuilds() } + environment { + TMPDIR = "/tmp/$BUILD_TAG" + } stages { stage('Unit Tests') { steps { - sh 'tox -rv' + sh "mkdir ${env.TMPDIR}" + sh """ +virtualenv -p python3 ${env.TMPDIR}/venv/ +${env.TMPDIR}/venv/bin/pip install tox "virtualenv<=20.0.5" "importlib-resources<=1.0.2" +PGPORT=`python -c 'import struct; import socket; s=socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0)); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'` pg_virtualenv -o fsync=off ${env.TMPDIR}/venv/bin/tox -r""" } post { always { script { utils = new Utils() utils.publish_coverage('coverage.xml') - utils.publish_coverage_native() + utils.publish_coverage_native('index.html') + utils.publish_pylint('pylint.out') } - junit 'junit.xml' + mergeJunitResults() } } } @@ -36,6 +45,7 @@ pipeline { } } success { + sh "rm -rf ${env.TMPDIR}" cleanWs() } } diff --git a/pylint.sh b/pylint.sh new file mode 100755 index 0000000..452fac4 --- /dev/null +++ b/pylint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -e + +pylint -f parseable "$@" > pylint.out || /bin/true diff --git a/tests/conftest.py b/tests/conftest.py index ad0e261..9e35904 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -172,7 +172,7 @@ olap = olap with (wcs_dir / 'wcs.cfg').open('w') as fd: fd.write(u'''[main] -app_dir = %s\n''' % wcs_dir) +app_dir = %s\n''' % (str(wcs_dir).replace('%', '%%'))) with (wcs_dir / 'local_settings.py').open('w') as fd: fd.write(u''' @@ -230,7 +230,7 @@ orig = olap key = olap schema = olap cubes_slug = olap-slug -'''.format(wcs=wcs, model_dir=model_dir, dsn=postgres_db.dsn)) +'''.format(wcs=wcs, model_dir=str(model_dir).replace('%', '%%'), dsn=postgres_db.dsn)) from wcs_olap import cmd import sys diff --git a/tox.ini b/tox.ini index ca0f44a..a6b2e90 100644 --- a/tox.ini +++ b/tox.ini @@ -5,29 +5,51 @@ [tox] toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/wcs-olap/{env:BRANCH_NAME:} -envlist = py3-coverage +envlist = py3 + +[tox:jenkins] +envlist = + pylint + py3 [testenv] usedevelop = true setenv = - coverage: COVERAGE=--junit-xml=junit.xml --cov=wcs_olap --cov-report xml --cov-report html - WCS_MANAGE=wcs/manage.py + COVERAGE={tty::--cov=wcs_olap --cov-branch --cov-append --cov-report xml --cov-report html} + JUNIT={tty::-o junit_suite_name={envname} --junit-xml=junit-{envname}.xml} + WCS_MANAGE=wcs/manage.py + PGDATABASE=postgres deps = - coverage - pytest - pytest-cov - pytest-random - quixote>=3 - psycopg2-binary - vobject - pyproj - django-ratelimit<3 - gadjo - httmock - django>=1.11,<1.12 + pytest + pytest-cov + pytest-random + httmock + +# w.c.s. dependencies, as it cannot b installed through pip + quixote>=3 + psycopg2-binary + vobject + pyproj + django-ratelimit<3 + gadjo + django>=1.11,<1.12 +passenv= + BRANCH_NAME + # support for pg_virtualenv + PGPORT + PGHOST + PGUSER + PGPASSWORD commands = - ./get_wcs.sh - py.test {env:COVERAGE:} {posargs:--random-group tests} + ./get_wcs.sh + py.test {tty:--sw:} {env:JUNIT:} {env:COVERAGE:} {posargs:--random-group tests} + +[testenv:pylint] +basepython = python3 +deps = + pylint +commands = + /bin/bash -c "./pylint.sh wcs_olap" [pytest] junit_family=xunit2