-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo-release.py
63 lines (54 loc) · 1.95 KB
/
do-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
import re
import subprocess
import sys
VERSION_PATTERN = re.compile(r'^\d+\.\d+\.\d+$')
USAGE = "USAGE: do-release.py VERSION"
def main(argv):
if len(argv) != 2 or not VERSION_PATTERN.match(argv[1]):
print(USAGE)
return 1
if is_working_tree_dirty():
print("error: cannot release with dirty working tree")
return 1
version = argv[1]
with open('Sources/ConvexMobile/VersionInfo.swift', 'w') as outfile:
outfile.write("""\
// File generated by {} - do not edit, but do check-in.
let convexMobileVersion = "{}"
""".format(argv[0], version))
if not commit_release(version):
print("error: failed to commit VersionInfo.swift")
return 1
if not tag_release(version):
print("error: failed to tag release")
return 1
print("ok: release created")
should_push = input("option: push release to origin [y]/n? ").lower() in ['', 'y']
if not should_push:
print("ok: manual push of commit and tag required")
return 0
if not push_commit():
print("error: pushing commit failed")
return 1
if not push_tag(version):
print("error: pushing tag failed")
return 1
print("ok: release {} published".format(version))
return 0
def is_working_tree_dirty():
status_result = subprocess.run('git status --porcelain', shell=True, text=True, capture_output=True)
return status_result.stdout.strip() != ''
def commit_release(version):
commit_result = subprocess.run('git commit -aem "Generated VersionInfo file for {}"'.format(version), shell=True)
return commit_result.returncode == 0
def tag_release(version):
tag_result = subprocess.run('git tag {}'.format(version), shell=True)
return tag_result.returncode == 0
def push_commit():
push_result = subprocess.run('git push origin main', shell=True)
return push_result.returncode == 0
def push_tag(version):
push_result = subprocess.run('git push origin {}'.format(version), shell=True)
return push_result.returncode == 0
if __name__ == "__main__":
main(sys.argv)