Skip to content

Commit 2938ad2

Browse files
committed
Add CI/CD (close snowplow#180)
1 parent 961877d commit 2938ad2

3 files changed

Lines changed: 104 additions & 7 deletions

File tree

.travis.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ python:
77
- '3.4'
88
- '3.5'
99
install:
10-
- "pip install -r requirements-test.txt"
11-
- "pip install -e ."
12-
# command to run tests
13-
script:
14-
pytest --cov=snowplow_tracker
15-
after_success:
16-
coveralls
10+
- pip install -r requirements-test.txt
11+
- pip install release-manager
12+
- pip install -e .
13+
script: pytest --cov=snowplow_tracker
14+
after_success: coveralls
15+
deploy:
16+
skip_cleanup: true
17+
provider: script
18+
script: ./.travis/deploy.py
19+
on:
20+
tags: true
21+
python: '2.7'
22+
env:
23+
global:
24+
secure: SnavmHqH0sB6xmyqSiN7HscdVpNr6pk+bWs/8Oin2FZ0Kp52V9vIQf1A9TjDQY67P3YgUsMFJKWmCIpbsWFUl65Nos2LXGK6oTe9mt7O5fsR6BsI1IiiZoC8wNZwmaUjqyJa3/Y5KUYvWXlTLYChbyiqxcTCtkBDnLaiFFDOEis=

.travis/deploy.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env python
2+
3+
4+
import os
5+
from os.path import expanduser
6+
import sys
7+
8+
from release_manager import utils, logger
9+
10+
from snowplow_tracker import _version
11+
12+
# --- Constants
13+
14+
15+
HOME = expanduser("~")
16+
DEFAULT_SERVER = 'https://pypi.python.org/pypi'
17+
DEFAULT_REPO = 'pypi'
18+
PYPIRC_FILE = '%s/.pypirc' % HOME
19+
20+
if 'TRAVIS_TAG' in os.environ:
21+
TRAVIS_TAG = os.environ.get('TRAVIS_TAG')
22+
else:
23+
sys.exit("Environment variable TRAVIS_TAG is unavailable")
24+
25+
if 'TRAVIS_BUILD_DIR' in os.environ:
26+
TRAVIS_BUILD_DIR = os.environ.get('TRAVIS_BUILD_DIR')
27+
else:
28+
sys.exit("Environment variable TRAVIS_BUILD_DIR is unavailable")
29+
30+
if 'PYPI_PASSWORD' in os.environ:
31+
PYPI_PASSWORD = os.environ.get('PYPI_PASSWORD')
32+
else:
33+
sys.exit("Environment variable PYPI_PASSWORD is unavailable")
34+
35+
36+
# --- Helpers
37+
38+
39+
def check_version():
40+
"""Fail deploy if tag version doesn't match version"""
41+
logger.log_start("Checking versions")
42+
if TRAVIS_TAG != _version.__build_version__:
43+
sys.exit("Version extracted from project doesn't match the TRAVIS_TAG variable. TRAVIS_TAG: {}, __build_version__: {}!".format(TRAVIS_TAG, _version.__build_version__))
44+
else:
45+
logger.log_info("Versions match!")
46+
logger.log_done()
47+
48+
49+
def write_config():
50+
"""Writes an array of lines to the PyPi config file"""
51+
logger.log_start("Writing ~/.pypirc file")
52+
lines = [
53+
'[distutils]\n',
54+
'index-servers =\n',
55+
' %s\n' % DEFAULT_REPO,
56+
'\n',
57+
'[%s]\n' % DEFAULT_REPO,
58+
'repository=%s\n' % DEFAULT_SERVER,
59+
'username=snowplow\n',
60+
'password=%s\n' % PYPI_PASSWORD
61+
]
62+
63+
with open(PYPIRC_FILE, 'w') as outfile:
64+
for line in lines:
65+
outfile.write(line)
66+
logger.log_info("The ~/.pypirc file has been written!")
67+
logger.log_done()
68+
69+
70+
def deploy_to_pypi():
71+
"""Deploys the release to PyPi"""
72+
logger.log_start("Deploying to PyPi")
73+
os.chdir(TRAVIS_BUILD_DIR)
74+
utils.execute("python setup.py register -r pypi", shell=True)
75+
utils.execute("python setup.py sdist upload -r pypi", shell=True)
76+
logger.log_info("Module deployed to PyPi!")
77+
logger.log_done()
78+
79+
80+
# --- Main
81+
82+
83+
if __name__ == "__main__":
84+
logger.log_header("Deploying snowplow-python-tracker to PyPi")
85+
check_version()
86+
write_config()
87+
deploy_to_pypi()
88+
logger.log_footer("Deployed version %s to PyPi!" % TRAVIS_TAG)

snowplow_tracker/_version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222

2323
__version_info__ = (0, 8, 0)
2424
__version__ = ".".join(str(x) for x in __version_info__)
25+
__build_version__ = __version__ + ''

0 commit comments

Comments
 (0)