generated from Valheim-Modding/JotunnModStub
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
set_new_version.py
executable file
·65 lines (53 loc) · 2.05 KB
/
set_new_version.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
#!/usr/bin/env python3
# There's too many places where the version has to be set, so I've made a little script to do it for me each time.
#
# Locations (why):
# - AssemblyInfo.cs (for assembly versioning):
# + AssemblyVersion("2.0.0.0")
# + AssemblyFileVersion("2.0.0.0")
#
# - manifest.json (for Thunderstore):
# + "version_number": "2.0.0"
#
# - BasePlugin.cs (plugin version)
# + PluginVersion = "2.0.0"
import argparse
import os.path
import re
import sys
class FilePatternReplacement:
def __init__(self, file, pattern, replacement):
self.file = file
self.pattern = pattern
self.replacement = replacement
def replace(self):
if not os.path.exists(self.file):
return f"{self.file} does not exist"
with open(self.file, 'r', encoding='utf-8') as f:
content = f.read()
modified_content = re.sub(self.pattern, self.replacement, content)
with open(self.file, 'w', encoding='utf-8') as f:
f.write(modified_content)
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog='Set new version')
parser.add_argument('version', nargs='?', type=str)
args = parser.parse_args()
version = args.version
if version is None or version == "":
parser.print_help()
sys.exit(1)
file_pattern_replacements = [
FilePatternReplacement('ChebsMercenaries/ChebsMercenaries.csproj',
'<Version>[0-9.]+<\/Version>',
f'<Version>{version}.0</Version>'),
FilePatternReplacement('ChebsMercenaries/BasePlugin.cs',
'PluginVersion = [".0-9]+',
f'PluginVersion = "{version}"'),
FilePatternReplacement('ChebsMercenaries/Package/manifest.json',
'"version_number": [".0-9]+',
f'"version_number": "{version}"'),
]
errors = [x.replace() for x in file_pattern_replacements]
for error in errors:
if error is not None:
print(error)