forked from therion/therion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_release.py
executable file
·66 lines (57 loc) · 2.06 KB
/
make_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
import re, datetime, sys, subprocess
if sys.version_info.major > 2:
raw_input = input
banner = '''
Warning!
This script makes a new release and pushes it to github.
All changes should already be committed.
Continue? (no/yes): '''
def err(s):
print('\nfatal: %s\n' % s)
sys.exit(1)
if raw_input(banner) == 'yes':
# check CHANGES to assure that the release is ready and to get the tag message
isfirst = True
msg = ''
ver = ''
with open('CHANGES') as f:
for l in f:
if isfirst:
isfirst = False
m = re.match(r'Therion (\d+\.\d+(?:\.\d+)?) \((\d{4}-\d\d-\d\d)\):\s+$',l)
if m:
if m.group(2) != datetime.date.today().isoformat():
err('release date in the CHANGES is not today')
ver = m.group(1)
else:
err('no version info in the file CHANGES')
msg += l
else:
if l.startswith('-'*70):
break
else:
msg += l.replace('"',r'\"').replace('$',r'\$')
# check the branch
if subprocess.check_output('git rev-parse --abbrev-ref HEAD', shell=True) != b'master\n':
err('you are not on master branch')
# check for uncommited changes
subprocess.check_call('git pull', shell=True)
if subprocess.check_output('git status -s', shell=True):
err('there are uncommitted changes on your drive')
# add a tag and push
subprocess.check_call('git tag -a v%s -m "%s"' % (ver,msg), shell=True)
subprocess.check_call('git push origin v%s' % ver, shell=True)
# update CHANGES to assure that subsequent commits would not be mistaken for a release by set_version.py
m = re.match(r'(.+\.)(\d+)$', ver)
assert m
ver = '%s%d' % (m.group(1), int(m.group(2))+1)
with open('CHANGES') as f:
oldchanges = f.read()
with open('CHANGES', 'w') as f:
f.write("Therion %s (in progress):\n\n\n%s\n\n" % (ver, '-'*80) + oldchanges)
subprocess.check_call('git add CHANGES', shell=True)
subprocess.check_call('git commit -m "update CHANGES"', shell=True)
subprocess.check_call('git push', shell=True)
else:
print('bye')