forked from pace-neutrons/Euphonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.py
73 lines (62 loc) · 1.94 KB
/
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
67
68
69
70
71
72
73
import argparse
import json
import os
import re
import requests
import subprocess
from importlib_resources import open_text
import yaml
from euphonic import __version__
def main():
parser = get_parser()
args = parser.parse_args()
test = not args.notest
if args.github:
release_github(test)
def release_github(test=True):
with open('CHANGELOG.rst') as f:
changelog = f.read()
with open('CITATION.cff') as f:
citation = yaml.safe_load(f)
euphonic_ver = 'v' + __version__
version_dict = {}
version_dict['CHANGELOG.rst'] = re.findall('\n`(v\d+\.\d+\.\S+)\s',
changelog)[0]
version_dict['CITATION.cff'] = 'v' + citation['version']
for ver_name, ver in version_dict.items():
if euphonic_ver != ver:
raise Exception((
f'euphonic.__version__/{ver_name} version mismatch! '
f'euphonic.__version__: {euphonic_ver} {ver_name}: '
f'{ver}'))
desc = re.search('`v\d+\.\d+\.\S+.*?^-+\n(.*?)^`v', changelog,
re.DOTALL | re.MULTILINE).groups()[0].strip()
payload = {
"tag_name": euphonic_ver,
"target_commitish": "master",
"name": euphonic_ver,
"body": desc,
"draft": False,
"prerelease": True
}
if test:
print(payload)
else:
response = requests.post(
'https://api.github.com/repos/pace-neutrons/euphonic/releases',
data=json.dumps(payload),
headers={"Authorization": "token " + os.environ["GITHUB_TOKEN"]})
print(response.text)
def get_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
'--github',
action='store_true',
help='Release on Github')
parser.add_argument(
'--notest',
action='store_true',
help='Actually send/upload')
return parser
if __name__ == '__main__':
main()