-
Notifications
You must be signed in to change notification settings - Fork 18
/
build.py
executable file
·219 lines (181 loc) · 7.14 KB
/
build.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/usr/bin/env python3
import os
import shutil
import subprocess
import sys
import fileinput
import re
'''
This program accepts optional command line options:
-r
--release
Do not include commit hash in directory/zip/version names
-a
--all
Included files for all expansions
-c
--classic
Include Classic/Era files
-t
--tbc
Include TBC files
-w
--wotlk
Include WotLK files
-v <versionString>
--version <versionString>
Disregard git and toc versions, and use <versionString> instead
'''
addonDir = 'ExtendedCharacterStats'
includedExpansions = []
tocs = ['', 'ExtendedCharacterStats-Classic.toc', 'ExtendedCharacterStats-BCC.toc', 'ExtendedCharacterStats-WOTLKC.toc']
def main():
isReleaseBuild = False
versionOverride = ''
if len(sys.argv) > 1:
ver = False
for arg in sys.argv[1:]:
if ver:
versionOverride = arg
ver = False
elif arg in ['-r', '--release']:
isReleaseBuild = True
print("Creating a release build")
elif arg in ['-v', '--version']:
ver = True
elif arg in ['-a', '--all']:
if 1 not in includedExpansions:
includedExpansions.append(1)
if 2 not in includedExpansions:
includedExpansions.append(2)
if 3 not in includedExpansions:
includedExpansions.append(3)
elif arg in ['-c', '--classic'] and 1 not in includedExpansions:
includedExpansions.append(1)
elif arg in ['-t', '--tbc'] and 2 not in includedExpansions:
includedExpansions.append(2)
elif arg in ['-w', '--wotlk'] and 3 not in includedExpansions:
includedExpansions.append(3)
if len(includedExpansions) == 0:
# If expansions go online/offline their major version needs to be added/removed here
includedExpansions.append(1)
includedExpansions.append(3)
release_dir = get_version_dir(isReleaseBuild, versionOverride)
if os.path.isdir('releases/%s' % release_dir):
print("Warning: Folder already exists, removing!")
shutil.rmtree('releases/%s' % release_dir)
release_folder_path = 'releases/%s' % release_dir
release_addon_folder_path = release_folder_path + ('/%s' % addonDir)
copy_content_to(release_addon_folder_path)
if versionOverride != '':
for tocN in includedExpansions:
toc = tocs[tocN]
toc_path = release_addon_folder_path + toc
with fileinput.FileInput(toc_path, inplace=True) as file:
for line in file:
if line[:10] == '## Version':
print('## Version: ' + versionOverride)
else:
print(line, end='')
zip_name = '%s-%s' % (addonDir, release_dir)
zip_release_folder(zip_name, release_dir, addonDir)
interface_classic = get_interface_version()
interface_bcc = get_interface_version('BCC')
interface_wotlk = get_interface_version('WOTLKC')
flavorString = ""
if 1 in includedExpansions:
flavorString += """
{
"flavor": "classic",
"interface": %s
},""" % interface_classic
if 2 in includedExpansions:
flavorString += """
{
"flavor": "bcc",
"interface": %s
},""" % interface_bcc
if 3 in includedExpansions:
flavorString += """
{
"flavor": "wrath",
"interface": %s
},""" % interface_wotlk
with open(release_folder_path + '/release.json', 'w') as rf:
rf.write('''{
"releases": [
{
"filename": "%s.zip",
"nolib": false,
"metadata": [%s
]
}
]
}''' % (zip_name, flavorString[:-1]))
print('New release "%s" created successfully' % release_dir)
def get_version_dir(is_release_build, versionOverride):
version, nr_of_commits, recent_commit = get_git_information()
if versionOverride != '':
version = versionOverride
print("Tag: " + version)
if is_release_build:
release_dir = "%s" % version
else:
release_dir = "%s-%s" % (version, recent_commit)
print("Number of commits since tag: " + nr_of_commits)
print("Most Recent commit: " + recent_commit)
branch = get_branch()
if branch != "master" and branch != "HEAD":
release_dir += "-%s" % branch
print("Current branch: " + branch)
return release_dir
directoriesToInclude = ['Icons', 'Libs', 'Modules']
filesToInclude = ['embeds.xml', 'ECS.lua', 'ExtendedCharacterStats.toc']
expansionStrings = ['', 'Classic', 'TBC', 'Wotlk']
ignorePatterns = []
def copy_content_to(release_folder_path):
for i in [1,2,3]:
if i in includedExpansions:
filesToInclude.append(tocs[i])
else:
ignorePatterns.append(f'{expansionStrings[i]}')
for _, directories, files in os.walk('.'):
for directory in directories:
if directory in directoriesToInclude:
shutil.copytree(directory, '%s/%s' % (release_folder_path, directory), ignore=shutil.ignore_patterns(*ignorePatterns))
for file in files:
if file in filesToInclude:
shutil.copy2(file, '%s/%s' % (release_folder_path, file))
break
def zip_release_folder(zip_name, version_dir, addon_dir):
root = os.getcwd()
os.chdir('releases/%s' % version_dir)
print("Zipping %s" % zip_name)
shutil.make_archive(zip_name, "zip", ".", addon_dir)
os.chdir(root)
def get_git_information():
if is_tool("git"):
script_dir = os.path.dirname(os.path.realpath(__file__))
p = subprocess.check_output(["git", "describe", "--tags", "--long"], cwd=script_dir, stderr=subprocess.STDOUT)
tag_string = str(p).rstrip("\\n'").lstrip("b'")
# versiontag (v4.1.1) from git, number of additional commits on top of the tagged object and most recent commit.
version_tag, nr_of_commits, recent_commit = tag_string.rsplit("-", maxsplit=2)
recent_commit = recent_commit.lstrip("g") # There is a "g" before all the commits.
return version_tag, nr_of_commits, recent_commit
else:
raise RuntimeError("Warning: Git not found on the computer, using fallback to get a version.")
def get_branch():
if is_tool("git"):
script_dir = os.path.dirname(os.path.realpath(__file__))
# git rev-parse --abbrev-ref HEAD
p = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=script_dir)
branch = str(p).rstrip("\\n'").lstrip("b'")
return branch
def get_interface_version(expansion='Classic'):
with open('ExtendedCharacterStats-%s.toc' % expansion, 'r') as toc:
return re.match('## Interface: (.*?)\n', toc.read(), re.DOTALL).group(1)
def is_tool(name):
"""Check whether `name` is on PATH and marked as executable."""
return shutil.which(name) is not None
if __name__ == "__main__":
main()