-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
update-check.py
64 lines (52 loc) · 2 KB
/
update-check.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
import sys
import os
import requests
import json
import re
is_pull_request = sys.argv[1] == "true"
print(f"is_pull_request={is_pull_request}")
def check_version(directory, new_version):
print(f"Checking version for {directory}")
if not new_version:
print("Failed to get new version. Exiting.")
exit(1)
with open(f"{directory}/VERSION", "r") as f:
old_version = f.read().rstrip()
print(f"Up-to-date version {new_version}")
print(f"Current version: {old_version}")
if old_version != new_version:
print(f"New release found: {new_version}")
# bump up to new release
with open(f"{directory}/VERSION", "w") as f:
f.write(new_version)
# commit
result = os.system(f"git config --local user.email 'actions@github.com' \
&& git config --local user.name 'GitHub Actions' \
&& git add {directory}/VERSION \
&& git commit -m 'Bump {directory} version to {new_version}'")
if result != 0:
print("Failed to commit the bump. Exiting")
exit(1)
if is_pull_request:
print("Action triggered by pull request. Do not push.")
else:
result = os.system("git push")
if result != 0:
print("Failed to push. Exiting")
exit(1)
else:
print(f"Already newest version {old_version}")
# check deb version
response = requests.get("https://protonmail.com/download/current_version_linux.json")
content = json.loads(response.content)
version = re.match(".*_([0-9.-]+)_amd64\.deb", content["DebFile"]).group(1)
check_version("deb", version)
# check build version
response = requests.get(
"https://api.github.com/repos/ProtonMail/proton-bridge/tags",
headers={"Accept": "application/vnd.github.v3+json"},
)
tags = json.loads(response.content)
version_re = re.compile("v\d+\.\d+\.\d+")
releases = [tag["name"][1:] for tag in tags if version_re.match(tag["name"])]
check_version("build", releases[0])