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