Jenkinsfile: use virtualenv and pg_virtualenv

This commit is contained in:
Benjamin Dauvergne 2020-05-16 12:12:39 +02:00
parent 75dc1f103b
commit 97c483172a
4 changed files with 61 additions and 20 deletions

18
Jenkinsfile vendored
View File

@ -2,10 +2,18 @@
pipeline {
agent any
options { disableConcurrentBuilds() }
environment {
TMPDIR = "/tmp/$BUILD_TAG"
}
stages {
stage('Unit Tests') {
steps {
sh 'tox -r'
sh "mkdir ${env.TMPDIR}"
sh """
virtualenv -p python3 ${env.TMPDIR}/venv/
${env.TMPDIR}/venv/bin/pip install tox
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 {
@ -13,8 +21,9 @@ pipeline {
utils = new Utils()
utils.publish_coverage('coverage.xml')
utils.publish_coverage_native('index.html')
utils.publish_pylint('pylint.out')
}
junit '*_results.xml'
mergeJunitResults()
}
}
}
@ -22,9 +31,9 @@ pipeline {
steps {
script {
if (env.JOB_NAME == 'petale' && env.GIT_BRANCH == 'origin/master') {
sh 'sudo -H -u eobuilder /usr/local/bin/eobuilder -d stretch petale'
sh 'sudo -H -u eobuilder /usr/local/bin/eobuilder petale'
} else if (env.GIT_BRANCH.startsWith('hotfix/')) {
sh "sudo -H -u eobuilder /usr/local/bin/eobuilder -d stretch --branch ${env.GIT_BRANCH} --hotfix petale"
sh "sudo -H -u eobuilder /usr/local/bin/eobuilder --branch ${env.GIT_BRANCH} --hotfix petale"
}
}
}
@ -38,6 +47,7 @@ pipeline {
}
}
success {
sh "rm -rf ${env.TMPDIR}"
cleanWs()
}
}

View File

@ -1,4 +1,6 @@
#!/bin/sh
#!/bin/bash
set -e
if [ -f /var/lib/jenkins/pylint.django.rc ]; then
PYLINT_RC=/var/lib/jenkins/pylint.django.rc
@ -8,7 +10,4 @@ else
echo No pylint RC found
exit 0
fi
test -f pylint.out && cp pylint.out pylint.out.prev
pylint -f parseable --rcfile ${PYLINT_RC} "$@" | tee pylint.out || /bin/true
test -f pylint.out.prev && (diff pylint.out.prev pylint.out | grep '^[><]' | grep .py) || /bin/true
pylint -f parseable --rcfile ${PYLINT_RC} "$@" > pylint.out || /bin/true

View File

@ -1,7 +1,16 @@
PETALE_AUTHENTIC_URL = 'http://example.net/idp/'
PETALE_AUTHENTIC_AUTH = ('foo', 'bar')
import os
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'petale',
}
}
if 'postgres' in DATABASES['default']['ENGINE']:
for key in ('PGPORT', 'PGHOST', 'PGUSER', 'PGPASSWORD'):
if key in os.environ:
DATABASES['default'][key[2:]] = os.environ[key]
PETALE_AUTHENTIC_URL = 'http://example.net/idp/'
PETALE_AUTHENTIC_AUTH = ('foo', 'bar')

41
tox.ini
View File

@ -1,35 +1,58 @@
[tox]
envlist = py27-coverage-dj111,py3-coverage-{dj111,dj22}
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/petale/
envlist =
py2-dj111-drf34
py3-dj111-drf34
py3-dj22-drf39
[tox:jenkins]
envlist =
pylint
py2-dj111-drf34
py3-dj111-drf34
py3-dj22-drf39
[testenv]
usedevelop=True
usedevelop=true
setenv =
DJANGO_SETTINGS_MODULE=petale.settings
PETALE_SETTINGS_FILE=tests/settings.py
coverage: COVERAGE=--junitxml=test_results.xml --cov-report xml --cov-report html --cov=petale/ --cov-config .coveragerc
JUNIT={tty::-o junit_suite_name={envname} --junit-xml=junit-{envname}.xml}
COVERAGE={tty::--junitxml=test_{envname}_results.xml --cov-report xml --cov-report html --cov=petale/ --cov-config .coveragerc}
passenv=
BRANCH_NAME
# support for pg_virtualenv
PGPORT
PGHOST
PGUSER
PGPASSWORD
deps =
dj111: django>=1.11,<2
dj22: django>=2.2,<2.3
pytest-cov
pytest-django
pytest
pylint<1.8
pylint-django<0.8.1
mock
django-webtest<1.9.3
psycopg2
pyquery
commands =
python setup.py compile_translations
py.test {env:COVERAGE:} {posargs:tests/}
py.test {env:COVERAGE:} {env:JUNIT:} {tty:--sw:} {posargs:tests/}
[testenv:pylint]
usedevelop = true
basepython = python2.7
deps =
pylint<1.8
pylint-django<0.8.1
Django<2.3
pylint<1.8
pylint-django<0.8.1
commands =
/bin/bash -c "./pylint.sh petale/"
/bin/bash -c "./pylint.sh petale/"
[pytest]
junit_family=xunit2
filterwarnings =
error
ignore:Using or importing the ABCs from 'collections':DeprecationWarning:django.*