forked from pace-neutrons/Euphonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.py
79 lines (66 loc) · 2.01 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
74
75
76
77
78
79
import argparse
import json
import os
import re
import requests
import subprocess
from euphonic import __version__
def main():
parser = get_parser()
args = parser.parse_args()
test = not args.notest
if args.github:
release_github(test)
if args.pypi:
release_pypi(test)
def release_github(test=True):
with open('CHANGELOG.rst') as f:
changelog = f.read()
euphonic_ver = 'v' + __version__
changelog_ver = re.findall('\n`(v\d+\.\d+\.\S+)\s', changelog)[0]
if euphonic_ver != changelog_ver:
raise Exception((
f'euphonic.__version__/changelog.rst version mismatch! '
f'euphonic.__version__: {euphonic_ver} changelog.rst: '
f'{changelog_ver}'))
desc = re.search('`v\d+\.\d+\.\S+.*?^-+\n(.*?)^`v', changelog,
re.DOTALL | re.MULTILINE).groups()[0].strip()
payload = {
"tag_name": changelog_ver,
"target_commitish": "master",
"name": changelog_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 release_pypi(test=True):
subprocess.run(['rm','-r','dist'])
subprocess.run(['rm','-r','build'])
subprocess.run(['python', 'setup.py', 'sdist'])
if not test:
subprocess.run(['twine', 'upload', 'dist/*'])
def get_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
'--github',
action='store_true',
help='Release on Github')
parser.add_argument(
'--pypi',
action='store_true',
help='Release on PyPI')
parser.add_argument(
'--notest',
action='store_true',
help='Actually send/upload')
return parser
if __name__ == '__main__':
main()