create a jenkins pipeline (#33771)

This commit is contained in:
Emmanuel Cazenave 2019-06-06 17:35:40 +02:00
parent 68240dc15c
commit 36cd6a5cd6
5 changed files with 78 additions and 30 deletions

38
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,38 @@
@Library('eo-jenkins-lib@master') import eo.Utils
pipeline {
agent any
options { disableConcurrentBuilds() }
stages {
stage('Unit Tests') {
steps {
sh 'tox -rv'
}
post {
always {
junit 'junit.xml'
}
}
}
stage('Packaging') {
steps {
script {
if (env.JOB_NAME == 'django-journal' && env.GIT_BRANCH == 'origin/master') {
sh 'sudo -H -u eobuilder /usr/local/bin/eobuilder -d jessie,stretch django-journal'
}
}
}
}
}
post {
always {
script {
utils = new Utils()
utils.mail_notify(currentBuild, env, 'admin+jenkins-django-journal@entrouvert.com')
}
}
success {
cleanWs()
}
}
}

View File

@ -9,7 +9,7 @@ from django.conf import settings
from decorator import atomic
__all__ = ('record', 'error_record', 'Journal')
__version__ = '1.25.2'
def unicode_truncate(s, length, encoding='utf-8'):
'''Truncate an unicode string so that its UTF-8 encoding is less than

View File

@ -13,7 +13,7 @@ class JournalTestCase(TestCase):
models.JOURNAL_METADATA_CACHE_TIMEOUT = 0
self.users = []
self.groups = []
with transaction.commit_on_success():
with transaction.atomic():
for i in range(20):
self.users.append(
User.objects.create(username='user%s' % i))

View File

@ -1,5 +1,6 @@
#!/usr/bin/python
import os
import subprocess
import sys
from setuptools import setup, find_packages
@ -70,36 +71,31 @@ class install_lib(_install_lib):
def get_version():
import glob
import re
import os
version = None
for d in glob.glob('*'):
if not os.path.isdir(d):
continue
module_file = os.path.join(d, '__init__.py')
if not os.path.exists(module_file):
continue
for v in re.findall("""__version__ *= *['"](.*)['"]""",
open(module_file).read()):
assert version is None
version = v
if version:
break
assert version is not None
'''Use the VERSION, if absent generates a version with git describe, if not
tag exists, take 0.0- and add the length of the commit log.
'''
if os.path.exists('VERSION'):
with open('VERSION', 'r') as v:
return v.read()
if os.path.exists('.git'):
import subprocess
p = subprocess.Popen(['git','describe','--dirty', '--match=v*'],
stdout=subprocess.PIPE)
p = subprocess.Popen(
['git', 'describe', '--dirty=.dirty', '--match=v*'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = p.communicate()[0]
assert p.returncode == 0, 'git returned non-zero'
new_version = result.split()[0][1:]
major_minor_release = new_version.split('-')[0]
assert version == major_minor_release, \
'__version__ (%s) must match the last git annotated tag (%s)' % (version, major_minor_release)
version = new_version.replace('-', '.').replace('.g', '+g')
return version
if p.returncode == 0:
result = result.decode('ascii').strip()[1:] # strip spaces/newlines and initial v
if '-' in result: # not a tagged version
real_number, commit_count, commit_hash = result.split('-', 2)
version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
else:
version = result
return version
else:
return '0.0.post%s' % len(
subprocess.check_output(
['git', 'rev-list', 'HEAD']).splitlines())
return '0.0'
setup(name='django-journal',
version=get_version(),

14
tox.ini Normal file
View File

@ -0,0 +1,14 @@
[tox]
toxworkdir = /tmp/tox-{env:USER}/combo/{env:BRANCH_NAME:}
envlist = py2
[testenv]
usedevelop = True
deps =
pytest
pytest-django
setenv =
DJANGO_SETTINGS_MODULE=test_settings
commands =
{posargs:py.test --junitxml=junit.xml django_journal/tests.py}