Project

General

Profile

0001-use-Jenkinsfile-14810.patch

Benjamin Dauvergne, 02 Mar 2019 05:10 PM

Download (5.52 KB)

View differences:

Subject: [PATCH 1/2] use Jenkinsfile (#14810)

- Copied from authentic2-auth-kerberos
- Removal of .coveragerc as it prevented coverage from working, dunno
  why.
 .coveragerc            |  2 --
 Jenkinsfile            | 45 +++++++++++++++++++++++++++++
 merge-junit-results.py | 65 ++++++++++++++++++++++++++++++++++++++++++
 pylint.sh              | 13 +++++++++
 tox.ini                | 14 ++++++---
 5 files changed, 133 insertions(+), 6 deletions(-)
 delete mode 100644 .coveragerc
 create mode 100644 Jenkinsfile
 create mode 100755 merge-junit-results.py
 create mode 100755 pylint.sh
.coveragerc
1
[run]
2
omit = tests/*
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
                    script {
14
                        utils = new Utils()
15
                        utils.publish_coverage('coverage.xml')
16
                        utils.publish_coverage_native('index.html')
17
                        utils.publish_pylint('pylint.out')
18
                    }
19
                    sh './merge-junit-results.py junit-*.xml >junit.xml'
20
                    junit 'junit.xml'
21
                }
22
            }
23
        }
24
        stage('Packaging') {
25
            steps {
26
                script {
27
                    if (env.JOB_NAME == 'django-mellon' && env.GIT_BRANCH == 'origin/master') {
28
                        sh 'sudo -H -u eobuilder /usr/local/bin/eobuilder django-mellon'
29
                    }
30
                }
31
            }
32
        }
33
    }
34
    post {
35
        always {
36
            script {
37
                utils = new Utils()
38
                utils.mail_notify(currentBuild, env, 'admin+jenkins-django-mellon@entrouvert.com')
39
            }
40
        }
41
        success {
42
            cleanWs()
43
        }
44
    }
45
}
merge-junit-results.py
1
#!/usr/bin/env python
2
#
3
#  Corey Goldberg, Dec 2012
4
#
5

  
6
import os
7
import sys
8
import xml.etree.ElementTree as ET
9

  
10

  
11
"""Merge multiple JUnit XML files into a single results file.
12
Output dumps to sdtdout.
13
example usage:
14
    $ python merge_junit_results.py results1.xml results2.xml > results.xml
15
"""
16

  
17

  
18
def main():
19
    args = sys.argv[1:]
20
    if not args:
21
        usage()
22
        sys.exit(2)
23
    if '-h' in args or '--help' in args:
24
        usage()
25
        sys.exit(2)
26
    merge_results(args[:])
27

  
28

  
29
def merge_results(xml_files):
30
    failures = 0
31
    tests = 0
32
    errors = 0
33
    time = 0.0
34
    cases = []
35

  
36
    for file_name in xml_files:
37
        tree = ET.parse(file_name)
38
        test_suite = tree.getroot()
39
        failures += int(test_suite.attrib['failures'])
40
        tests += int(test_suite.attrib['tests'])
41
        errors += int(test_suite.attrib['errors'])
42
        time += float(test_suite.attrib['time'])
43
        name = test_suite.attrib.get('name', '')
44
        for child in test_suite.getchildren():
45
            child.attrib['classname'] = '%s-%s' % (name, child.attrib.get('classname', ''))
46
        cases.append(test_suite.getchildren())
47

  
48
    new_root = ET.Element('testsuite')
49
    new_root.attrib['failures'] = '%s' % failures
50
    new_root.attrib['tests'] = '%s' % tests
51
    new_root.attrib['errors'] = '%s' % errors
52
    new_root.attrib['time'] = '%s' % time
53
    for case in cases:
54
        new_root.extend(case)
55
    new_tree = ET.ElementTree(new_root)
56
    ET.dump(new_tree)
57

  
58

  
59
def usage():
60
    this_file = os.path.basename(__file__)
61
    print('Usage:  %s results1.xml results2.xml' % this_file)
62

  
63

  
64
if __name__ == '__main__':
65
    main()
pylint.sh
1
#!/bin/sh
2

  
3
set -e -x
4
env
5
if [ -f /var/lib/jenkins/pylint.django.rc ]; then
6
	PYLINT_RC=/var/lib/jenkins/pylint.django.rc
7
elif [ -f pylint.django.rc ]; then
8
	PYLINT_RC=pylint.django.rc
9
else
10
	echo No pylint RC found
11
	exit 0
12
fi
13
pylint -f parseable --rcfile ${PYLINT_RC} "$@" | tee pylint.out || /bin/true
tox.ini
10 10
  PYTHONPATH=.
11 11
  sqlite: DB_ENGINE=sqlite3
12 12
  pg: DB_ENGINE=postgresql_psycopg2
13
  coverage: COVERAGE=--junit-xml=junit-{envname}.xml --cov=mellon --cov-report xml
13
  coverage: COVERAGE=--cov=mellon --cov-branch --cov-append --cov-report xml --cov-report html
14 14
usedevelop =
15 15
    coverage: true
16
    nocoverage: false
17 16
deps =
18 17
  dj18: django>1.8,<1.9
19 18
  dj111: django>1.11,<1.12
......
34 33
commands =
35 34
  py2: ./getlasso.sh
36 35
  py3: ./getlasso3.sh
37
  py.test --random {env:COVERAGE:} {posargs:tests}
38
  coverage: mv coverage.xml coverage-{envname}.xml
36
  py.test -o junit_suite_name={envname} --junit-xml=junit-{envname}.xml --random {env:COVERAGE:} {posargs:tests}
37

  
38
[testenv:pylint]
39
basepython = python2.7
40
deps =
41
    pylint<1.8
42
    pylint-django<0.8.1
43
commands =
44
    pylint: ./pylint.sh mellon
39
-