-
Notifications
You must be signed in to change notification settings - Fork 3
/
version_update.py
68 lines (46 loc) · 1.66 KB
/
version_update.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
64
65
66
67
68
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from milkcocoa import __version__ as version
from milkcocoa import __build_version__ as build_version
from sh import git
def create_tag(v, bv):
if not isinstance(v, str):
v = str(v)
if not isinstance(bv, str):
bv = str(bv)
tag_version = v + '-' + bv
git('tag', '-a', tag_version)
return tag_version
def upload_tag(tag_version):
git('push', 'origin', tag_version)
def update_build_version(build_version_old):
build_version_old += 1
return build_version_old
def get_build_version():
number_version = build_version
if isinstance(number_version, str):
number_version = int(number_version)
return number_version
def get_version():
return version
def commit_update_master(tag_version):
commit_message = 'feat version ' + tag_version
git('add', '-u')
git('commit', '-m', commit_message)
git('push', 'origin', 'master')
def save_build_version(old_build_version, build_version):
old_build_version = '__build_version__ = "' + str(old_build_version) + '"'
build_version = '__build_version__ = "' + str(build_version) + '"'
with open('milkcocoa/__init__.py', 'r+') as init_file:
lines = init_file.readlines()
lines = [line.replace(old_build_version, build_version) for line in lines]
init_file.seek(0) # Rewrite everything
init_file.writelines(lines)
if __name__ == '__main__':
old_bv = get_build_version()
bv = update_build_version(old_bv)
save_build_version(old_bv, bv)
v = get_version()
tag_version = create_tag(v, bv)
commit_update_master(tag_version)
upload_tag(tag_version)