-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathversion.py
63 lines (43 loc) · 1.26 KB
/
version.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, re
def version_file():
file = os.path.dirname(os.path.realpath(__file__))
file = os.path.join(file, 'package.json')
return file
def write_file(path, cnt):
with open(path, 'w') as f:
f.write(cnt)
def get_file_content(path):
ctx = ''
with open(path, 'r') as f:
for line in f:
ctx += line
return ctx
v=version_file()
appv=os.environ.get('APPVEYOR_REPO_TAG')
appbuild=os.getenv('APPVEYOR_BUILD_VERSION', 'nn.nn.nn')
appm=os.getenv('APPVEYOR_REPO_COMMIT_MESSAGE', '===')
appb=os.getenv('APPVEYOR_REPO_BRANCH', '---')
apptag=os.getenv('APPVEYOR_REPO_TAG_NAME', 'no tag')
travistag=os.environ.get('TRAVIS_TAG')
trbn=os.getenv('TRAVIS_BUILD_NUMBER', 'xx')
trc='TRAVIS'
trb=os.environ.get('TRAVIS_BRANCH')
travis=False
appveyor=False
if trb != None:
travis=True
if appv != None:
appveyor=True
lversion=os.environ.get('VERSION')
if None == lversion:
lversion='0.0.x'
if appveyor:
if None != appv:
lversion=appv
if travis:
if None != travistag:
lversion=travistag
cnt = get_file_content(v)
cnt = re.sub(r'"version": "\d+\.\d+\.\d+"', "\"version\": \"" + lversion + "\"", cnt)
print(cnt)
write_file(v, cnt)