-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrelease.py
More file actions
executable file
·82 lines (64 loc) · 2.3 KB
/
release.py
File metadata and controls
executable file
·82 lines (64 loc) · 2.3 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python2
import json
import os
import shutil
import subprocess
from decimal import Decimal
from urlparse import urlparse
def run_command(command):
p = subprocess.Popen(command, stdout=subprocess.PIPE)
(response, err) = p.communicate()
# p_status = p.wait()
return (response, err)
def _tag_release(version):
if os.path.isfile('./token'):
with open('./token') as f:
read_data = f.read()
token = read_data.strip()
else:
print "Could not make release: token not found"
print "Get your own at: https://github.com/settings/tokens"
return
payload = {
"target_commitish": "master",
'tag_name': 'v' + str(version),
'name': 'v' + str(version),
'body': 'Release ' + str(version),
}
(url, err) = run_command(['git', 'config', '--get', 'remote.origin.url'])
data = urlparse(url)
path = data.path.replace('.git', '')
url = 'https://api.github.com/repos' + path.strip() + '/releases'
(resp, err) = run_command(['curl', '-H', 'Authorization: token ' +
str(token), url, '-X', 'POST', '-d',
json.dumps(payload)])
data = json.loads(resp)
if 'message' in data:
print "Release error:" + data['message']
def release():
with open('buildout.cfg', 'r') as f:
lines = f.read().split('\n')
out = []
found = False
for line in lines:
if (not found) and line.startswith('# v'):
line = line.replace('# v', '')
left, right = line.split(' ', 1)
digits = left.strip()
version = Decimal(digits)
version += Decimal('0.01')
line = '# v{} {}'.format(version, right).strip()
found = True
out.append(line)
shutil.copyfile('buildout.cfg', 'buildout.cfg.old')
with open('buildout.cfg', 'w') as f:
f.write('\n'.join(out))
subprocess.call(['git', 'pull'])
subprocess.call(['git', 'commit', 'buildout.cfg', '-m', '"Bump version"'])
subprocess.call(['git', 'tag', '-a', "v{}".format(version), '-m',
'Release {}'.format(version)])
subprocess.call(['git', 'push', '--tags'])
subprocess.call(['git', 'push'])
_tag_release(version)
if __name__ == "__main__":
release()