-
Notifications
You must be signed in to change notification settings - Fork 8
/
release_python.py
executable file
·142 lines (114 loc) · 4.44 KB
/
release_python.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
"""
In general, this script is out of date. Make any changes as necessary.
(e.g. repo names, year numbers, new frontend deploy process, different specs)
Here's what this script does:
* Generates a comparison link to review the changes
* Adds version number and changelog to specs/specs.md
* Converts `specs.md` into a fancy specs html document (`frontend/public/specs.html`).
* Deploys the frontend.
* Updates setup.py version number.
* Publishes the updated package to PyPi.
* Commits, tags and pushes.
"""
import argparse
import subprocess
import os
import datetime
def main(version):
generate_comparison_link()
specs(version)
# TODO should be adapted now that we use markdeep instead
fancy_specs()
deploy_frontend()
update_setup_py_version(version)
publish_pypi()
commit_tag_push(version)
def generate_comparison_link():
"""
Generate a comparison link like https://github.com/battlecode/battlecode20/compare/commit...commit
comparing the most recent commit with the latest released version.
"""
# get latest tag
latest_tag = subprocess.check_output("git tag --sort=committerdate | tail -1", shell=True).decode("utf-8").strip('\n')
# get commit
commit = subprocess.check_output("git rev-list -n 1 " + latest_tag, shell=True).decode('utf-8').strip('\n')
# get latest commit
latest = subprocess.check_output("git rev-parse HEAD", shell=True).decode('utf-8').strip('\n')
# print the link
link = "https://github.com/battlecode/battlehack20/compare/" + commit + "..." + latest
print("Go to the following link and check out the differences:")
print(link)
# wait until the user says yes
response = input("enter 'y' to proceed with the release: ")
while response != 'y':
response = input("enter 'y' to proceed with the release: ")
def specs(version):
with open('specs/specs.md', 'r') as f:
gr = f.read()
# prompt for changelog in specs, engine
l = ['spec', 'engine']
d = {i: [] for i in l}
for i in l:
while True:
x = input(i + " change: ")
if x == "":
break
d[i].append(x)
now = datetime.datetime.now()
changelogstring = "- " + version + " (" + str(now.month) + "/" + str(now.day) + "/" + str(now.year)[2:] + ")\n"
for i in l:
changelogstring += " - " + i + " changes:"
if len(d[i]) == 0:
changelogstring += " none\n"
else:
changelogstring += "\n"
for dd in d[i]:
changelogstring += " - " + dd + '\n'
g = gr.split('\n')
for i in range(len(g)):
if "# Changelog" in g[i]:
g.insert(i+2, changelogstring.rstrip())
if "Current version: " in g[i]:
g[i] = "Current version: " + version
gr = "\n".join(g)
with open('specs/specs.md', 'w') as f:
f.write(gr)
def fancy_specs():
os.chdir('specs')
subprocess.call('pandoc specs.md --self-contained --template template.html --toc -o specs.html --metadata pagetitle="Battlehack 2020 Specs"', shell=True)
os.chdir('..')
subprocess.call('cp specs/specs.html frontend/public/specs.html', shell=True)
def deploy_frontend():
os.chdir('frontend')
subprocess.call('./deploy.sh deploy', shell=True)
os.chdir('..')
def update_setup_py_version(version):
with open('engine/setup.py', 'r') as f:
config = f.read()
config_lines = config.split('\n')
for i in range(len(config_lines)):
if "version=" in config_lines[i]:
p = config_lines[i].split('"')
config_lines[i] = p[0] + '"' + version + '"' + p[2]
config = "\n".join(config_lines)
with open('engine/setup.py', 'w') as f:
f.write(config)
def publish_pypi():
os.chdir('engine')
subprocess.call('python3 setup.py sdist bdist_wheel', shell=True)
subprocess.call('twine upload --skip-existing dist/*', shell=True)
os.chdir('..')
def commit_tag_push(version):
subprocess.call(f'git commit -am "release {version}"', shell=True)
subprocess.call(f'git tag v{version}', shell=True)
subprocess.call('git push', shell=True)
subprocess.call('git push --tags', shell=True)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument('version', help='Version number, e.g. 0.1.1')
args = parser.parse_args()
main(args.version)