forked from Battle-Brothers-Legends/Legends-public
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_patch.py
More file actions
82 lines (62 loc) · 2.52 KB
/
Copy pathupload_patch.py
File metadata and controls
82 lines (62 loc) · 2.52 KB
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
from pathlib import Path
from buildscript.lib import VersionExtractor, load_config
from buildscript.python.upload import NexusUploadTask, GithubUploadTask, ApiError
import subprocess
import build_patch
def commits(tag: str) -> str:
if tag.endswith(".-1"):
return "\n"
messages = subprocess.check_output(["git", "log", f"{tag}..HEAD", "--no-merges", "--format=%s", "--reverse"], encoding="utf-8").strip()
lines = [m.split(" ")[0] for m in messages.split("\n")]
return "\n".join([f"- {m}" for m in lines])
def main():
config = load_config(Path(__file__).parent / ".build_config.py")
version_extractor = VersionExtractor(Path.cwd())
base_version = version_extractor.get_base_version()
current_version = version_extractor.extract_version()
bb_dir = Path(config.BB_DIR)
file = bb_dir / version_extractor.artifact_name_mod()
build_patch.main()
if config.NEXUS_TOKEN is not None:
nexus_task = NexusUploadTask(config.NEXUS_TOKEN, 60)
try:
nexus_task.run(file, f"""
REQUIRES VERSION 1.5.2.2+ OF VANILLA GAME
SAVE COMPATIBLE WITH {base_version}+
DO NOT UNZIP YOUR MOD FILES
You need {version_extractor.artifact_name_assets()} to play!
To install: drop into 'data' Battle Brothers folder
""".strip())
except ApiError as e:
print(e.message)
else:
print("NEXUS_TOKEN not found in config, skipping upload")
if config.GITHUB_TOKEN is not None:
build_name = version_extractor.extract_build_name()
parts = current_version.split(".")
previous_version = f"{'.'.join(parts[:-1])}.{int(parts[-1]) - 1}"
desc = f"""
# {current_version} - {build_name}
`SAVE COMPATIBLE WITH {base_version}+`
`DO NOT UNZIP YOUR MOD FILES`
`REMOVE ALL YOUR PREVIOUS OFFICIAL LEGENDS PATCHES AND VERSIONS`
Replace the `mod_legends-{previous_version}.zip` with `{version_extractor.artifact_name_mod()}`
You need `{version_extractor.artifact_name_assets()}` to play. If you don't have it - download it from [here](https://github.com/Battle-Brothers-Legends/Legends-public/releases/tag/{version_extractor.get_legends_assets_version()}).
## Fixes
{commits(previous_version)}
""".strip()
github_task = GithubUploadTask(config.GITHUB_TOKEN, owner="Battle-Brothers-Legends", repo="Legends-public")
try:
github_task.run(
files=[file],
description=desc,
branch=f"release/{base_version}",
releaseName=f"{build_name} {current_version}",
openBrowserWithRelease=config.GITHUB_OPEN_RELEASE
)
except ApiError as e:
print(e.message)
else:
print("GITHUB_TOKEN not found in config, skipping upload")
if __name__ == "__main__":
main()