Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrelease_python.py
More file actions
Latest commit
executable file
·142 lines (114 loc) · 4.44 KB
/
Copy pathrelease_python.py
File metadata and controls
executable file
·142 lines (114 loc) · 4.44 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
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.
"""
importargparse
importsubprocess
importos
importdatetime
defmain(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)
defgenerate_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: ")
whileresponse!='y':
response=input("enter 'y' to proceed with the release: ")
defspecs(version):
withopen('specs/specs.md', 'r') asf:
gr=f.read()
# prompt for changelog in specs, engine
l= ['spec', 'engine']
d= {i: [] foriinl}
foriinl:
whileTrue:
x=input(i+" change: ")
ifx=="":
break
d[i].append(x)
now=datetime.datetime.now()
changelogstring="- "+version+" ("+str(now.month) +"/"+str(now.day) +"/"+str(now.year)[2:] +")\n"
foriinl:
changelogstring+=" - "+i+" changes:"
iflen(d[i]) ==0:
changelogstring+=" none\n"
else:
changelogstring+="\n"
forddind[i]:
changelogstring+=" - "+dd+'\n'
g=gr.split('\n')
foriinrange(len(g)):
if"# Changelog"ing[i]:
g.insert(i+2, changelogstring.rstrip())
if"Current version: "ing[i]:
g[i] ="Current version: "+version
gr="\n".join(g)
withopen('specs/specs.md', 'w') asf:
f.write(gr)
deffancy_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)
defdeploy_frontend():
os.chdir('frontend')
subprocess.call('./deploy.sh deploy', shell=True)
os.chdir('..')
defupdate_setup_py_version(version):
withopen('engine/setup.py', 'r') asf:
config=f.read()
config_lines=config.split('\n')
foriinrange(len(config_lines)):
if"version="inconfig_lines[i]:
p=config_lines[i].split('"')
config_lines[i] =p[0] +'"'+version+'"'+p[2]
config="\n".join(config_lines)
withopen('engine/setup.py', 'w') asf:
f.write(config)
defpublish_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('..')
defcommit_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)