forked from ahodges9/LedFx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.py
76 lines (59 loc) · 2.35 KB
/
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
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
import argparse
import sys
import re
import subprocess
import shutil
from ledfx.consts import MAJOR_VERSION, MINOR_VERSION
def write_version(major, minor):
with open('ledfx/consts.py') as fil:
content = fil.read()
content = re.sub('MAJOR_VERSION = .*\n',
'MAJOR_VERSION = {}\n'.format(major),
content)
content = re.sub('MINOR_VERSION = .*\n',
'MINOR_VERSION = {}\n'.format(minor),
content)
with open('ledfx/consts.py', 'wt') as fil:
content = fil.write(content)
def execute_command(command):
return subprocess.check_output(command.split(' ')).decode('UTF-8').rstrip()
def main():
parser = argparse.ArgumentParser(
description="Release a new version of LedFx")
parser.add_argument('type', help="The type of release",
choices=['major', 'minor'])
parser.add_argument('--no_bump', action='store_true',
help='Create a version bump commit.')
arguments = parser.parse_args()
branch = execute_command("git rev-parse --abbrev-ref HEAD")
if branch != "master":
print("Releases must be pushed from the master branch.")
return
current_commit = execute_command("git rev-parse HEAD")
master_commit = execute_command("git rev-parse master@{upstream}")
if current_commit != master_commit:
print("Release must be pushed when up-to-date with origin.")
return
git_diff = execute_command("git diff HEAD")
if git_diff:
print("Release must be pushed without any staged changes.")
return
if not arguments.no_bump:
# Bump the version based on the release type
major = MAJOR_VERSION
minor = MINOR_VERSION
if arguments.type == 'major':
major += 1
elif arguments.type == 'minor':
minor += 1
# Write the new version to consts.py
write_version(major, minor)
subprocess.run([
'git', 'commit', '-am', 'Version Bump for Release {}.{}'.format(major, minor)])
subprocess.run(['git', 'push', 'origin', 'master'])
shutil.rmtree("dist", ignore_errors=True)
subprocess.run(['python', 'setup.py', 'sdist', 'bdist_wheel'])
subprocess.run(['python', '-m', 'twine', 'upload', 'dist/*', '--skip-existing'])
if __name__ == '__main__':
main()