Skip to content

Commit 82f5f98

Browse files
author
Sylvain MARIE
committed
Improved error message and added python 2 in declaration
1 parent b90f796 commit 82f5f98

13 files changed

+401
-102
lines changed

.travis.yml

Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,38 @@ language: python
22

33
cache: pip
44

5-
python:
6-
# - "2.6"
7-
# - "2.7"
8-
# - "3.2"
9-
# - "3.3"
10-
# - "3.4"
11-
- "3.5"
12-
# - "3.5-dev" # 3.5 development branch
13-
- "3.6"
14-
# - "3.6-dev" # 3.6 development branch
15-
# - "3.7-dev" # 3.7 development branch
16-
# - "nightly" # currently points to 3.7-dev
17-
# PyPy versions
18-
# - "pypy" # PyPy2 2.5.0
19-
# - "pypy3" # Pypy3 2.4.0
20-
# - "pypy-5.3.1"
21-
#
5+
matrix:
6+
fast_finish: true
7+
include:
8+
# - python: 2.6
9+
- python: 2.7
10+
# - python: 3.3
11+
# - python: 3.4
12+
- python: 3.5
13+
- python: 3.6
14+
- python: 3.7
15+
dist: xenial
16+
sudo: true
2217

2318
env:
2419
global:
2520
- GH_REF: [email protected]:smarie/python-mini-lambda.git
2621

2722
before_install:
23+
# (a) linux dependencies
2824
- sudo apt-get install pandoc
2925
- sudo apt-get install ant
3026
- sudo apt-get install ant-optional
3127

3228
install:
33-
- pip install -r ci_tools/requirements-setup.txt
34-
- pip install -r ci_tools/requirements-test.txt
35-
- pip install -r ci_tools/requirements-report.txt
36-
- pip install -r ci_tools/requirements-doc.txt
37-
- pip install codecov # https://github.com/codecov/example-python. This is specific to travis integration
38-
# - pip install coveralls # this is an alternative to codecov
29+
- pip list
30+
# needs to be installed beforehand
31+
- pip install setuptools_scm
32+
- python ci_tools/py_install.py pip ci_tools/requirements-pip.txt
33+
# travis-specific installs
34+
- pip install PyGithub # for ci_tools/github_release.py
35+
- pip install codecov # See https://github.com/codecov/example-python.
36+
- pip list
3937

4038
script:
4139
# - coverage run tests.py
@@ -48,46 +46,56 @@ script:
4846
# now done in a dedicated script to capture exit code 1 and transform it to 0
4947
- chmod a+x ./ci_tools/run_tests.sh
5048
- sh ./ci_tools/run_tests.sh
49+
- python ci_tools/generate-junit-badge.py 100 # generates the badge for the test results and fail build if less than x%
5150

5251
after_success:
5352
# ***reporting***
5453
# - junit2html junit.xml testrun.html output is really not nice
5554
- ant -f ci_tools/generate-junit-html.xml # generates the html for the test results. Actually we dont use it anymore
56-
- python ci_tools/generate-junit-badge.py # generates the badge for the test results
5755
- codecov
58-
- pylint mini_lambda # note that at the moment the report is simply lost, we dont transform the result into anything
56+
# - pylint mini_lambda # note that at the moment the report is simply lost, we dont transform the result into anything
5957
# ***documentation***
6058
- mkdocs build -f docs/mkdocs.yml
61-
- if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then exit 0; fi;
6259
- mv reports/junit site/
6360
# mkdocs gh-deploy requires special care :
6461
# ---grant the possibility to push on the repo---
6562
- openssl aes-256-cbc -K $encrypted_fdc2c20d7f8b_key -iv $encrypted_fdc2c20d7f8b_iv -in ci_tools/github_travis_rsa.enc -out ci_tools/github_travis_rsa -d
66-
- chmod 600 ci_tools/github_travis_rsa
67-
- eval `ssh-agent -s` # launch the authentication agent
68-
- ssh-add ci_tools/github_travis_rsa # register the key
69-
- git config user.name "Automatic Publish"
70-
- git config user.email "[email protected]"
71-
- git remote add gh-remote "${GH_REF}";
72-
- git fetch gh-remote && git fetch gh-remote gh-pages:gh-pages;
73-
# push but only if this is not a build triggered by a pull request
74-
# note: here we use the --dirty flag so that mkdocs does not clean the additional reports that we copied in the site
75-
- if [ "${TRAVIS_PYTHON_VERSION}" = "3.5" ]; then echo "Pushing to github"; PYTHONPATH=mini_lambda/ mkdocs gh-deploy -v --dirty -f docs/mkdocs.yml --remote-name gh-remote; git push gh-remote gh-pages; fi;
76-
# - if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_PYTHON_VERSION}" = "3.5" ]; then echo "Pushing to github"; git push gh-remote gh-pages; fi;
63+
# If the output file does not exist, that is because the secret is invalid. This can happen in forked repos so do not fail the build
64+
- |
65+
if [ -s "ci_tools/github_travis_rsa" ]; then
66+
chmod 600 ci_tools/github_travis_rsa
67+
eval `ssh-agent -s` # launch the authentication agent
68+
ssh-add ci_tools/github_travis_rsa # register the decrypted key
69+
git config user.name "Automatic Publish"
70+
git config user.email "[email protected]"
71+
git remote add gh-remote "${GH_REF}";
72+
git fetch gh-remote && git fetch gh-remote gh-pages:gh-pages; # make sure we have the latest gh-remote
73+
# push but only if this is not a build triggered by a pull request
74+
# note: here we use the --dirty flag so that mkdocs does not clean the additional reports that we copied in the site
75+
if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_PYTHON_VERSION}" = "3.5" ]; then echo "Pushing to github"; PYTHONPATH=mini_lambda/ mkdocs gh-deploy -v --dirty -f docs/mkdocs.yml --remote-name gh-remote; git push gh-remote gh-pages; fi;
76+
else
77+
echo "File 'ci_tools/github_travis_rsa' has not been created, please check your encrypted repo token in .travis.yml, on the line starting with 'openssl aes-256-cbc...'"
78+
fi
7779
7880
deploy:
79-
provider: pypi
80-
user: "smarie"
81-
password:
82-
secure: "L4CcfT7Aq4bTiVAkMadR1dHUgU0GEHFphuywP38OpPAofsgf1b/IFIZPT3SDpo5AhbzpDSm0GGgQmITJrFwUlh4K5ubs/QYB3AWQN/w1yEf9T+ON/UcwtJYvjtrMNHV5yNxtDiSmDe6T8pjV0w9210KB7cW0r3Nkjq4A/Vo6bdInMAiK1pSgreuYHqkvDvKytjBnray8UlPQK4Bc1w7ixA91veNvcD+0OlOrSROzb5No0zbZ8+6PVu0Sa6G5gV32cDWxL7sSSbfaFeebZFgoYPaZkPl14IhG/VA9698yZ26owaqI9UqKPnoO/ySisgxmljc0QA7zJksFYCPzjFOUVVmcDnRgJmcMrqg3wrbXJLYAPHoj1jDtd3R6eEXBDV/Z/rdX33YfalfeRiXj2xA6RBeYGscIrfe93PbOfKOl2oAv5So4Guip2gjubXyHH7720PUQu1D8h5kA/GP0OhISwrRc7SVg3gsx31vpQUMMWgryS4B40aVf30VIlruJFD/JNPBEIjH+otZmc1j4PIJ3swWtPgDKijaPkj0isvacCwMH89+DAYR19QyG/fuLZwEm4Vykrruk6s52FPnootWSShluRu6APbPeZ473UV7SaPDDYXt8eZAz4l7GvGz7yVpHLXLS368oUb4L8N3yICtmHha6vRJcFaVsQ6JFFH3S98A="
83-
on:
84-
tags: true
85-
python: 3.6 # only one of the builds have to be deployed, we'll take the latest since generated code will be more complete
86-
# server: https://test.pypi.org/legacy/
87-
distributions: "sdist bdist_wheel"
81+
# Deploy on PyPI on tags
82+
- provider: pypi
83+
user: "smarie"
84+
password:
85+
secure: "L4CcfT7Aq4bTiVAkMadR1dHUgU0GEHFphuywP38OpPAofsgf1b/IFIZPT3SDpo5AhbzpDSm0GGgQmITJrFwUlh4K5ubs/QYB3AWQN/w1yEf9T+ON/UcwtJYvjtrMNHV5yNxtDiSmDe6T8pjV0w9210KB7cW0r3Nkjq4A/Vo6bdInMAiK1pSgreuYHqkvDvKytjBnray8UlPQK4Bc1w7ixA91veNvcD+0OlOrSROzb5No0zbZ8+6PVu0Sa6G5gV32cDWxL7sSSbfaFeebZFgoYPaZkPl14IhG/VA9698yZ26owaqI9UqKPnoO/ySisgxmljc0QA7zJksFYCPzjFOUVVmcDnRgJmcMrqg3wrbXJLYAPHoj1jDtd3R6eEXBDV/Z/rdX33YfalfeRiXj2xA6RBeYGscIrfe93PbOfKOl2oAv5So4Guip2gjubXyHH7720PUQu1D8h5kA/GP0OhISwrRc7SVg3gsx31vpQUMMWgryS4B40aVf30VIlruJFD/JNPBEIjH+otZmc1j4PIJ3swWtPgDKijaPkj0isvacCwMH89+DAYR19QyG/fuLZwEm4Vykrruk6s52FPnootWSShluRu6APbPeZ473UV7SaPDDYXt8eZAz4l7GvGz7yVpHLXLS368oUb4L8N3yICtmHha6vRJcFaVsQ6JFFH3S98A="
86+
on:
87+
tags: true
88+
python: 3.6 # only one of the builds have to be deployed, we'll take the latest since generated code will be more complete
89+
# server: https://test.pypi.org/legacy/
90+
distributions: "sdist bdist_wheel"
8891

89-
matrix:
90-
fast_finish: true
92+
# Create a github release on tags
93+
- provider: script
94+
script: python ci_tools/github_release.py -s $GITHUB_TOKEN --repo-slug smarie/python-decopatch -cf ./docs/changelog.md -d https://smarie.github.io/python-mini-lambda/changelog/ $TRAVIS_TAG
95+
skip_cleanup: true
96+
on:
97+
tags: true
98+
python: 3.5 #only one of the builds have to be deployed
9199

92100
notifications:
93101
email:

ci_tools/Readme-travis.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,44 @@ This is a reminder on how to grant travis the rights to deploy your site on gith
66

77
The following does not work on windows as explained [here](https://github.com/travis-ci/travis-ci/issues/4746)
88

9+
Note: if you get tlsV1 errors below, create_function sure that you have the latest OpenSSL. If it is not available from you package manager, look at this [compilation sequance](https://github.com/curl/curl/issues/1583#issuecomment-309477196) (replace_fixture all versions with the ones you need / the latest). No need to use nghttp2. Dont forget to add `--with-libssh2` to curl compilation step, as mentioned in the [script](https://github.com/dertin/lemp-stack-debian/blob/develop/install.sh)!
10+
911
## Install travis commandline
1012

1113
You have to be outside of the proxy for everything to work correctly, otherwise you will get strange errors mentioning ipaddr... either here or later in the process.
1214

13-
Install ruby using RVM : (**DO NOT USE su OR sudo**)
15+
**1- Install ruby** using RVM : (**DO NOT USE su NOR sudo**)
1416

1517
```bash
1618
> \curl -sSL https://get.rvm.io | bash -s stable --ruby
1719
> source /home/ubuntu/.rvm/scripts/rvm
18-
> rvm install ruby (this installs to /home/ubuntu/.rvm/src/ruby...)
20+
> rvm install 2.5.1 (this installs to /home/ubuntu/.rvm/src/ruby...)
21+
```
22+
23+
*Note: if you already have an old version of rvm you can update it to see the latest ruby versions*:
24+
```bash
25+
> rvm get master
26+
> rvm list known
27+
```
28+
29+
*Note: if at some point there is an openssl issue inside ruby it is possible to either create_function it use the path you like or have it use its own version as explained [here](https://stackoverflow.com/questions/15511943/troubles-with-rvm-and-openssl)*:
30+
31+
Either
32+
```bash
33+
> rvm install 2.5.1 --with-openssl-dir=/usr/local/ssl or (does not work) /usr/bin/openssl
34+
```
35+
36+
or
37+
38+
```bash
39+
> rvm pkg install openssl
40+
> rvm install 2.5.1 --with-openssl-dir=$HOME/.rvm/usr
1941
```
2042

21-
Then install travis commandline:
43+
**2- install travis commandline** by following [these instructions](https://github.com/travis-ci/travis.rb#installation):
2244

2345
```bash
24-
> gem install travis
46+
> gem install travis -v 1.8.8 --no-rdoc --no-ri
2547
```
2648

2749
source:
@@ -47,7 +69,7 @@ Generate an asymetric security key (public + private):
4769
ssh-keygen -t rsa -b 4096 -C "<your_github_email_address>" -f ci_tools/github_travis_rsa
4870
```
4971

50-
On the github repository page, `Settings > Deploy Keys > Add deploy key > add` the PUBLIC generated key (the file `ci_tools/github_travis_rsa.pub`)
72+
On the github repository page, `Settings > Deploy Keys > Add deploy key > add` the PUBLIC generated key (the file `ci_tools/github_travis_rsa.pub`) with write access
5173

5274

5375
Use travis CLI to encrypt your PRIVATE key:
@@ -64,6 +86,8 @@ Follow the instructions on screen :
6486
- modify the relative path to the generated file by adding 'ci_tools/' in front of 'github_travis_rsa_...enc'.
6587
- git add the generated file 'github_travis_rsa_...enc' but DO NOT ADD the private key
6688

89+
Note: if you find bug 'no implicit conversion of nil intro String' as mentioned [here](https://github.com/travis-ci/travis.rb/issues/190#issuecomment-377823703), [here](https://github.com/travis-ci/travis.rb/issues/585#issuecomment-374307229) and especially [here](https://github.com/travis-ci/travis.rb/issues/586) it can either be a network proxy error (check that http_proxy is not set...) or a ruby/travis cli version issue. Or worse: an openssl version issue (you check check with wireshark). Best is to reinstall at least the gems: `rvm gemset empty` and then `gem install travis ...` (see above). Note that reinstalling ruby takes a *lot* more time than reinstalling the gems :).
90+
6791
source:
6892
* https://djw8605.github.io/2017/02/08/deploying-docs-on-github-with-travisci/ (rejecting https://docs.travis-ci.com/user/deployment/pages/ as this would grant full access to travis)
6993
* https://docs.travis-ci.com/user/encrypting-files/
@@ -84,7 +108,7 @@ source: https://docs.travis-ci.com/user/deployment/pypi/
84108

85109
## To deploy file releases on github
86110

87-
Similar procedure to encrypt the OAuth password for github releases. **WARNING** unlike 'travis encrypt', this WILL modify your `travis.yml` file. Therefore you should make a backup of it beforehand, and then execute this command with the '--force' option.
111+
Similar procedure to encrypt the OAuth password for github releases. **WARNING** unlike 'travis encrypt', this WILL modify your `travis.yml` file. Therefore you should create_function a backup of it beforehand, and then execute this command with the '--force' option.
88112

89113
```bash
90114
> (cd, source, travis login)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
This conftest adds a source link to all tests in the various test reports
3+
"""
14
from py.xml import html
25
import pytest
36
from setuptools_scm.git import GitWorkdir

ci_tools/generate-junit-badge.py

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,70 @@
1+
import sys
2+
try:
3+
# python 3
4+
from urllib.parse import quote_plus
5+
except ImportError:
6+
# python 2
7+
from urllib import quote_plus
8+
19
import requests
210
import shutil
311
from os import makedirs, path
412
import xunitparser
513

614

7-
def download_badge(junit_xml: str='reports/junit/junit.xml', dest_folder: str='reports/junit'):
15+
class TestStats(object):
16+
def __init__(self, success_percentage, success, runned, skipped):
17+
self.success_percentage = success_percentage
18+
self.success = success
19+
self.runned = runned
20+
self.skipped = skipped
821

9-
makedirs(dest_folder, exist_ok=True)
1022

11-
# read the junit test file
23+
def get_test_stats(junit_xml='reports/junit/junit.xml' # type: str
24+
):
25+
# type: (...) -> TestStats
26+
"""
27+
read the junit test file and extract the success percentage
28+
:param junit_xml: the junit xml file path
29+
:return: the success percentage (an int)
30+
"""
1231
ts, tr = xunitparser.parse(open(junit_xml))
13-
runned = tr.testsRun
32+
skipped = len(tr.skipped)
33+
runned = tr.testsRun - skipped
1434
failed = len(tr.failures)
35+
success = runned - failed
36+
37+
success_percentage = round(success * 100 / runned)
38+
39+
return TestStats(success_percentage, success, runned, skipped)
40+
41+
42+
def download_badge(test_stats, # type: TestStats
43+
dest_folder='reports/junit' # type: str
44+
):
45+
"""
46+
Downloads the badge corresponding to the provided success percentage, from https://img.shields.io.
1547
16-
success_percentage = round((runned - failed) * 100 / runned)
17-
if success_percentage < 50:
48+
:param test_stats:
49+
:param dest_folder:
50+
:return:
51+
"""
52+
if not path.exists(dest_folder):
53+
makedirs(dest_folder) # , exist_ok=True) not python 2 compliant
54+
55+
if test_stats.success_percentage < 50:
1856
color = 'red'
19-
elif success_percentage < 75:
57+
elif test_stats.success_percentage < 75:
2058
color = 'orange'
21-
elif success_percentage < 90:
59+
elif test_stats.success_percentage < 90:
2260
color = 'green'
2361
else:
2462
color = 'brightgreen'
25-
url = 'https://img.shields.io/badge/tests-' + str(success_percentage) + '%25-' + color + '.svg'
63+
64+
left_txt = "tests"
65+
# right_txt = "%s%%" % test_stats.success_percentage
66+
right_txt = "%s/%s" % (test_stats.success, test_stats.runned)
67+
url = 'https://img.shields.io/badge/%s-%s-%s.svg' % (left_txt, quote_plus(right_txt), color)
2668

2769
dest_file = path.join(dest_folder, 'junit-badge.svg')
2870

@@ -35,5 +77,19 @@ def download_badge(junit_xml: str='reports/junit/junit.xml', dest_folder: str='r
3577

3678

3779
if __name__ == "__main__":
38-
# execute only if run as a script
39-
download_badge()
80+
# Execute only if run as a script.
81+
# Check the arguments
82+
assert len(sys.argv[1:]) == 1, "a single mandatory argument is required: <threshold>"
83+
threshold = float(sys.argv[1])
84+
85+
# First retrieve the success percentage from the junit xml
86+
test_stats = get_test_stats()
87+
88+
# Validate against the threshold
89+
print("Success percentage is %s%%. Checking that it is >= %s" % (test_stats.success_percentage, threshold))
90+
if test_stats.success_percentage < threshold:
91+
raise Exception("Success percentage %s%% is strictly lower than required threshold %s%%"
92+
"" % (test_stats.success_percentage, threshold))
93+
94+
# Download the badge
95+
download_badge(test_stats)

0 commit comments

Comments
 (0)