jenkins: adopt authentic way of doing tox.ini and Jenkinsfile

This commit is contained in:
Benjamin Dauvergne 2020-06-03 09:37:55 +02:00
parent 6e4cef6d5c
commit af2513e56e
4 changed files with 59 additions and 22 deletions

16
Jenkinsfile vendored
View File

@ -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()
}
}

5
pylint.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
set -e
pylint -f parseable "$@" > pylint.out || /bin/true

View File

@ -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

56
tox.ini
View File

@ -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