-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle_release.py
90 lines (63 loc) · 2.05 KB
/
bundle_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
#!/usr/bin/python3
"""Release Bundler
This script assists with creating proper bundles for release
"""
import pathlib
import shutil
import subprocess
import xml.etree.ElementTree as ET
PACKAGE_NAME = "PersonalityVectorExample"
PROJECT_ROOT = pathlib.Path(__file__).parent
BUILD_DIR = (
PROJECT_ROOT
/ "src"
/ "PersonalityVectorExample"
/ "bin"
/ "Release"
/ "netstandard2.1"
)
RELEASE_DIR = PROJECT_ROOT / "src" / "PersonalityVectorExample" / "bin" / "Release"
LICENSE_PATH = PROJECT_ROOT / "LICENSE.md"
README_PATH = PROJECT_ROOT / "README.md"
CSPROJ_PATH = (
PROJECT_ROOT
/ "src"
/ "PersonalityVectorExample"
/ "PersonalityVectorExample.csproj"
)
OUTPUT_DIR = pathlib.Path("dist")
def get_project_version() -> str:
"""Read the project version number from the csproj file."""
tree = ET.parse(CSPROJ_PATH)
root = tree.getroot()
try:
version_elem = root.findall(".//Version")[0]
except IndexError as exc:
raise RuntimeError(
f"Could not find <Version> element in: {CSPROJ_PATH}."
) from exc
version_text = version_elem.text
if not isinstance(version_text, str):
raise TypeError(f"Version element in '{CSPROJ_PATH}' missing inner text.")
return version_text
def main():
"""The main entry point for the script."""
# Clean out the previous release
if RELEASE_DIR.exists():
shutil.rmtree(str(RELEASE_DIR))
# Create a new build
try:
subprocess.run(["dotnet", "build", "--configuration", "Release"], check=True)
except subprocess.CalledProcessError:
print("An error occurred during build")
return
# Copy the license and readme to the built distribution
shutil.copyfile(LICENSE_PATH, RELEASE_DIR / "LICENSE.md")
shutil.copyfile(README_PATH, RELEASE_DIR / "README.md")
# Zip the build directory
project_version = get_project_version()
shutil.make_archive(
str(OUTPUT_DIR / f"{PACKAGE_NAME}_{project_version}"), "zip", RELEASE_DIR
)
if __name__ == "__main__":
main()