Projet

Général

Profil

0001-create-a-jenkins-pipeline-33771.patch

Emmanuel Cazenave, 06 juin 2019 17:54

Télécharger (5,51 ko)

Voir les différences:

Subject: [PATCH] create a jenkins pipeline (#33771)

 Jenkinsfile                | 38 ++++++++++++++++++++++++++++
 django_journal/__init__.py |  2 +-
 django_journal/tests.py    |  2 +-
 setup.py                   | 52 ++++++++++++++++++--------------------
 tox.ini                    | 14 ++++++++++
 5 files changed, 78 insertions(+), 30 deletions(-)
 create mode 100644 Jenkinsfile
 create mode 100644 tox.ini
Jenkinsfile
1
@Library('eo-jenkins-lib@master') import eo.Utils
2

  
3
pipeline {
4
    agent any
5
    options { disableConcurrentBuilds() }
6
    stages {
7
        stage('Unit Tests') {
8
            steps {
9
                sh 'tox -rv'
10
            }
11
            post {
12
                always {
13
                    junit 'junit.xml'
14
                }
15
            }
16
        }
17
        stage('Packaging') {
18
            steps {
19
                script {
20
                    if (env.JOB_NAME == 'django-journal' && env.GIT_BRANCH == 'origin/master') {
21
                        sh 'sudo -H -u eobuilder /usr/local/bin/eobuilder -d jessie,stretch django-journal'
22
                    }
23
                }
24
            }
25
        }
26
    }
27
    post {
28
        always {
29
            script {
30
                utils = new Utils()
31
                utils.mail_notify(currentBuild, env, 'admin+jenkins-django-journal@entrouvert.com')
32
            }
33
        }
34
        success {
35
            cleanWs()
36
        }
37
    }
38
}
django_journal/__init__.py
9 9
from decorator import atomic
10 10

  
11 11
__all__ = ('record', 'error_record', 'Journal')
12
__version__ = '1.25.2'
12

  
13 13

  
14 14
def unicode_truncate(s, length, encoding='utf-8'):
15 15
    '''Truncate an unicode string so that its UTF-8 encoding is less than
django_journal/tests.py
13 13
        models.JOURNAL_METADATA_CACHE_TIMEOUT = 0
14 14
        self.users = []
15 15
        self.groups = []
16
        with transaction.commit_on_success():
16
        with transaction.atomic():
17 17
            for i in range(20):
18 18
                self.users.append(
19 19
                        User.objects.create(username='user%s' % i))
setup.py
1 1
#!/usr/bin/python
2 2
import os
3
import subprocess
3 4
import sys
4 5

  
5 6
from setuptools import setup, find_packages
......
70 71

  
71 72

  
72 73
def get_version():
73
    import glob
74
    import re
75
    import os
76

  
77
    version = None
78
    for d in glob.glob('*'):
79
        if not os.path.isdir(d):
80
            continue
81
        module_file = os.path.join(d, '__init__.py')
82
        if not os.path.exists(module_file):
83
            continue
84
        for v in re.findall("""__version__ *= *['"](.*)['"]""",
85
                open(module_file).read()):
86
            assert version is None
87
            version = v
88
        if version:
89
            break
90
    assert version is not None
74
    '''Use the VERSION, if absent generates a version with git describe, if not
75
       tag exists, take 0.0- and add the length of the commit log.
76
    '''
77
    if os.path.exists('VERSION'):
78
        with open('VERSION', 'r') as v:
79
            return v.read()
91 80
    if os.path.exists('.git'):
92
        import subprocess
93
        p = subprocess.Popen(['git','describe','--dirty', '--match=v*'],
94
                stdout=subprocess.PIPE)
81
        p = subprocess.Popen(
82
            ['git', 'describe', '--dirty=.dirty', '--match=v*'],
83
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
95 84
        result = p.communicate()[0]
96
        assert p.returncode == 0, 'git returned non-zero'
97
        new_version = result.split()[0][1:]
98
        major_minor_release = new_version.split('-')[0]
99
        assert  version == major_minor_release, \
100
                '__version__ (%s) must match the last git annotated tag (%s)' % (version, major_minor_release)
101
        version = new_version.replace('-', '.').replace('.g', '+g')
102
    return version
85
        if p.returncode == 0:
86
            result = result.decode('ascii').strip()[1:]  # strip spaces/newlines and initial v
87
            if '-' in result:  # not a tagged version
88
                real_number, commit_count, commit_hash = result.split('-', 2)
89
                version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
90
            else:
91
                version = result
92
            return version
93
        else:
94
            return '0.0.post%s' % len(
95
                    subprocess.check_output(
96
                            ['git', 'rev-list', 'HEAD']).splitlines())
97
    return '0.0'
98

  
103 99

  
104 100
setup(name='django-journal',
105 101
      version=get_version(),
tox.ini
1
[tox]
2
toxworkdir = /tmp/tox-{env:USER}/combo/{env:BRANCH_NAME:}
3
envlist = py2
4

  
5

  
6
[testenv]
7
usedevelop = True
8
deps =
9
  pytest
10
  pytest-django
11
setenv =
12
  DJANGO_SETTINGS_MODULE=test_settings
13
commands =
14
  {posargs:py.test --junitxml=junit.xml django_journal/tests.py}
0
-