-
Notifications
You must be signed in to change notification settings - Fork 2
/
tasks.py
63 lines (51 loc) · 1.74 KB
/
tasks.py
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
import os
import subprocess
import currint
from invoke import task
VERSION_FILE = os.path.join(os.path.dirname(currint.__file__), "__init__.py")
def _write_to_version_file(version):
with open(VERSION_FILE, 'r') as version_read:
output = []
for line in version_read:
if line.startswith('__version__'):
output.append('__version__ = %r' % version)
else:
output.append(line.strip())
with open(VERSION_FILE, 'w') as version_write:
for line in output:
version_write.write(line + '\n')
def _commit_and_tag(version):
"""Commit changes to version file and tag the release"""
subprocess.check_call(
['git', 'add', VERSION_FILE],
)
subprocess.check_call(
['git', 'commit', '-m', "Releasing version %s" % version]
)
subprocess.check_call(
['git', 'tag', version]
)
def _push_release_changes(version):
push = raw_input('Push release changes to master? (y/n): ')
if push == 'y':
print subprocess.check_output(
['git', 'push', 'origin', 'master']
)
# push the release tag
print subprocess.check_output(
['git', 'push', 'origin', version]
)
else:
print 'Not pushing changes to master!'
print 'Make sure you remember to explictily push the tag!'
@task
def release():
# Prompt for version
print "Current version: %s" % currint.__version__
release_version = raw_input('Enter a new version (or "exit"): ')
if not release_version or release_version == 'exit':
print 'Cancelling release!'
return
_write_to_version_file(release_version)
_commit_and_tag(release_version)
_push_release_changes(release_version)