-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease_tools.py
49 lines (41 loc) · 1.66 KB
/
release_tools.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
import argparse
import json
import urllib.request
from subprocess import check_output
def main() -> None:
parser = argparse.ArgumentParser(description="Some small utility to create releases")
parser.add_argument("task", type=str, default="version", choices=["version", "check_tag"])
args = parser.parse_args()
if args.task == "version":
print(get_version())
elif args.task == "check_tag":
check_tag()
else:
raise Exception("Unknown option")
def check_tag() -> None:
"""
This is a very naive way of checkin if we already have a release with that
tag. We want to avoid overwriting already existing releases, so this
function will raise an exception when urllib does a successful request or
when it receives an error differently to a 404.
In this case a 404 is what we expect.
"""
# HACK: We explicitly check for the zip file because if there's a tag
# there's an automatic release page.
base_url = "https://github.com/etra0/litcher/releases/download/{}/the_litcher.zip"
current_ver = get_version()
final_url = base_url.format(current_ver)
try:
with urllib.request.urlopen(final_url) as req:
if req.status == 200:
raise Exception("There's already a release {}".format(current_ver))
except urllib.error.HTTPError as e:
if e.status != 404:
raise e
print("No release was detected with the tag", current_ver)
return
def get_version() -> None:
manifest = json.loads(check_output(["cargo", "read-manifest", "--manifest-path", "Cargo.toml"]))
return "v{}".format(manifest['version'])
if __name__ == "__main__":
main()