forked from man-hep-tier2/argus_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_release.py
46 lines (36 loc) · 1.17 KB
/
update_release.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
import json
import os
import re
def update_metadata_json(release):
input_file = 'metadata.json'
with open(input_file) as f:
content = json.load(f)
content['version'] = release
with open(input_file, 'w+') as f:
json.dump(content, f, indent=2)
def update_readme(release):
input_file = 'README.md'
with open(input_file) as f:
content = f.readlines()
pattern = "v(\d+\.)?(\d+\.)?(\*|\d+)$"
for i, line in enumerate(content):
if 'Latest stable version' in line:
line = re.sub(pattern, 'v' + release, line)
content[i] = line
break
content = ''.join(content)
with open(input_file, 'w+') as f:
f.write(content)
def update_changelog(release):
input_file = 'CHANGELOG.md'
with open(input_file) as f:
content = f.read()
content = content.replace('Unreleased', 'v' + release)
content = content.replace('HEAD', 'v' + release)
with open(input_file, 'w+') as f:
f.write(content)
if __name__ == '__main__':
release = os.environ.get('RELEASE', 'unreleased')
update_metadata_json(release)
update_readme(release)
update_changelog(release)