forked from Krappa322/arcdps_healing_stats
-
Notifications
You must be signed in to change notification settings - Fork 2
/
release.py
162 lines (133 loc) · 5.76 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
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
import asyncio
import datetime
import os
import re
import shutil
import string
import subprocess
from typing import List
MSBUILD_PATH = r"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\msbuild.exe"
SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
RELEASES_PATH = os.path.join(SCRIPT_PATH, "..", "arcdps_personal_stats_releases")
BUILD_PATH = os.path.join(SCRIPT_PATH, "x64") # Gets cleaned automatically, be careful what path you put in
BUILD_ALL_PROJECT = "arcdps_personal_stats_build_all.proj"
ARCHVING_TARGETS = ["arcdps_healing_stats.dll", "arcdps_healing_stats.pdb"]
TEST_BINARY_NAME = "test.exe"
CONFIGURATIONS = ["Debug", "Release"]
START = datetime.datetime.now()
def Progress(pStatus: str):
time_diff = datetime.datetime.now() - START
print("{:03}.{:06} {}".format(int(time_diff.total_seconds()), time_diff.microseconds, pStatus))
def ExtractInternalVersion(pVersionString: str) -> List[int]:
result: List[int] = []
for token_raw in pVersionString.split("."):
token = "".join([char for char in token_raw if char in string.digits])
result.append(int(token))
assert len(result) == 3, "Version must include 3 tokens"
Progress("Parsed version")
return result
def ChangeResourceVersion(pVersion: List[int]) -> None:
with open(os.path.join(SCRIPT_PATH, "arcdps_personal_stats.rc"), "r+") as file:
fulldata = file.read()
fulldata, replace_count = re.subn(
r" FILEVERSION \d+,\d+,\d+,\d+",
r" FILEVERSION {},{},{},1".format(pVersion[0], pVersion[1], pVersion[2]),
fulldata)
assert replace_count == 1
fulldata, replace_count = re.subn(
r" PRODUCTVERSION \d+,\d+,\d+,\d+",
r" PRODUCTVERSION {},{},{},1".format(pVersion[0], pVersion[1], pVersion[2]),
fulldata)
assert replace_count == 1
fulldata, replace_count = re.subn(
r' VALUE "FileVersion", "\d+.\d+.\d+.\d+"',
r' VALUE "FileVersion", "{}.{}.{}.1"'.format(pVersion[0], pVersion[1], pVersion[2]),
fulldata)
assert replace_count == 1
fulldata, replace_count = re.subn(
r' VALUE "ProductVersion", "\d+.\d+.\d+.\d+"',
r' VALUE "ProductVersion", "{}.{}.{}.1"'.format(pVersion[0], pVersion[1], pVersion[2]),
fulldata)
assert replace_count == 1
file.seek(0)
file.write(fulldata)
file.truncate()
Progress("Changed version in resource file")
# Returns an absolute path to the newly created directory
def CreateReleaseDirectory(pVersionString: str) -> str:
path = os.path.join(RELEASES_PATH, pVersionString)
os.mkdir(path)
return path
def Build(pReleaseDirectory: str, pRebuild: bool):
if pRebuild == True:
Progress("Cleaning build")
try:
shutil.rmtree(BUILD_PATH)
except FileNotFoundError:
pass
Progress("Starting build")
build_output = subprocess.run(
[MSBUILD_PATH, os.path.join(SCRIPT_PATH, BUILD_ALL_PROJECT), "-maxCpuCount", "-verbosity:diagnostic", "-consoleLoggerParameters:PerformanceSummary"],
capture_output=True)
Progress("Finished build")
os.makedirs(os.path.join(pReleaseDirectory, "BuildLogs"), exist_ok=True)
with open(os.path.join(pReleaseDirectory, "BuildLogs", "release_build_stdout.log"), "wb") as file:
file.write(build_output.stdout)
with open(os.path.join(pReleaseDirectory, "BuildLogs", "release_build_stderr.log"), "wb") as file:
file.write(build_output.stderr)
if (len(build_output.stderr) > 0):
print(build_output.stderr.decode("utf8"))
assert build_output.returncode == 0, "Build failed"
Progress("Finished saving build logs")
def SetupTestDirectory(pConfiguration: str):
shutil.copytree(
os.path.join(SCRIPT_PATH, "test", "xevtc_logs"),
os.path.join(BUILD_PATH, pConfiguration, "xevtc_logs"),
dirs_exist_ok=True
)
Progress("Setup test directory for {}".format(pConfiguration))
async def _RunTests(pReleaseDirectory: str, pConfiguration: str):
process = await asyncio.create_subprocess_exec(
os.path.join(BUILD_PATH, pConfiguration, TEST_BINARY_NAME),
cwd=os.path.join(BUILD_PATH, pConfiguration),
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE)
Progress("Started tests for {}".format(pConfiguration))
stdout, stderr = await process.communicate()
Progress("Finished tests for {}".format(pConfiguration))
with open(os.path.join(pReleaseDirectory, "TestLogs", "{}_tests_stdout.log".format(pConfiguration)), "wb") as file:
file.write(stdout)
with open(os.path.join(pReleaseDirectory, "TestLogs", "{}_tests_stderr.log".format(pConfiguration)), "wb") as file:
file.write(stderr)
Progress("Finished saving test logs for {}".format(pConfiguration))
assert process.returncode == 0, "Tests failed for {}".format(pConfiguration)
async def Test(pReleaseDirectory: str):
os.makedirs(os.path.join(pReleaseDirectory, "TestLogs"), exist_ok=True)
for configuration in CONFIGURATIONS:
SetupTestDirectory(configuration)
await _RunTests(pReleaseDirectory, configuration)
# Can't run in parallel since the tests bind to ports and thus interfere with eachother
#await asyncio.gather(*[_RunTests(pReleaseDirectory, configuration) for configuration in CONFIGURATIONS])
def Archive(pReleaseDirectory: str):
Progress("Archiving binaries")
for configuration in CONFIGURATIONS:
os.mkdir(os.path.join(pReleaseDirectory, configuration))
for target in ARCHVING_TARGETS:
shutil.copy2(
os.path.join(BUILD_PATH, configuration, target),
os.path.join(pReleaseDirectory, configuration, target))
Progress("Archiving complete")
def Do_Release(pVersionString: str):
version_internal = ExtractInternalVersion(pVersionString)
release_directory = CreateReleaseDirectory(pVersionString)
ChangeResourceVersion(version_internal)
Build(release_directory, True)
asyncio.run(Test(release_directory))
Archive(release_directory)
Progress("Release done")
def Do_Test():
Build(BUILD_PATH, False)
asyncio.run(Test(BUILD_PATH))
Progress("Do_Test done")
#Do_Test()
Do_Release("v2.9.rc1")