-
Notifications
You must be signed in to change notification settings - Fork 24
/
release.py
101 lines (89 loc) · 2.68 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
import sys
import json
from enum import Enum
import subprocess
from datetime import date
import os
class Action(Enum):
PATCH = 1
MINOR = 2
MAJOR = 3
# verify options
action = Action.PATCH
if (len(sys.argv) == 1):
print("Usage 'release.py [MAJOR|MINOR|PATCH]'. PATCH is default.")
print("No version element provided. Defaulting to PATCH.")
else:
action = Action[sys.argv[1].upper()]
print("Incrementing version element " + action.name)
# get current version
with open('info.json') as f:
data = json.load(f)
current = data['version']
print("Current version is " + current)
# increment according to provided option
split_version = current.split('.')
if (action == Action.PATCH):
split_version[2] = str(int(split_version[2]) + 1)
elif (action == Action.MINOR):
split_version[1] = str(int(split_version[1]) + 1)
split_version[2] = "0"
elif (action == Action.MAJOR):
split_version[0] = str(int(split_version[0]) + 1)
split_version[1] = "0"
split_version[2] = "0"
new_version = ".".join(split_version)
print("New version is " + new_version)
with open('info.json', encoding='utf8') as f:
data = json.load(f)
data['version'] = new_version
with open('info.json', 'w', encoding='utf8') as file:
json.dump(data, file, indent=2)
# generate changelog
result = subprocess.run(['git', 'log', current + '..HEAD', '--pretty=format:"%s%n %b"'], stdout=subprocess.PIPE)
commits = result.stdout.decode('utf-8').replace('"', '')
commits = os.linesep.join(["#" + s for s in commits.splitlines() if s.strip() != ""])
today = date.today()
changelog = """---------------------------------------------------------------------------------------------------
Version: {new_version}
Date: {today}
# Commits since last tag.
# Remove all lines with # in the beginning and order the content into the categories below.
{commits}
Major Features:
- sample entry
Continued
Features:
Minor Features:
Graphics:
Sounds:
Optimisations:
Balancing:
Combat Balancing:
Circuit Network:
Changes:
Bugfixes:
Modding:
Scripting:
Gui:
Control:
Translation:
Debug:
Ease of use:
Info:
Locale:
Other:
---------------------------------------------------------------------------------------------------
""".format(**locals())
with open("changelog.txt", encoding='utf8') as f:
lines = f.readlines()
lines[0] = changelog
with open("changelog.txt", "w", encoding='utf8') as f:
f.writelines(lines)
# wait for user to edit changelog
input("Please edit the changelog and then press [ENTER]")
# commit
subprocess.run(['git', 'commit', '-am"Release version ' + new_version + '"'])
# tag with new version
subprocess.run(['git', 'tag', new_version])