This repository has been archived by the owner on May 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
150 lines (107 loc) · 4.31 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
#!/usr/bin/python
import os
import subprocess
from os import path
from zipfile import ZIP_DEFLATED, ZIP_STORED, ZipFile
from pynt import main, task
AUTHOR = "lgfrbcsgo"
NAME = "Async Server"
DESCRIPTION = "A single threaded, non blocking TCP server for WoT mods which makes use of the `async` / `await`."
RELEASE_DEPENDENCIES = [
"https://github.com/lgfrbcsgo/wot-async/releases/download/v0.3.3/lgfrbcsgo.async_0.3.3.wotmod",
]
@task()
def clean():
subprocess.check_call(["rm", "-rf", "dist"])
@task(clean)
def wotmod():
# clean dist directory
subprocess.check_call(["rm", "-rf", "dist/wotmod"])
source_dst = "dist/wotmod/unpacked/res/scripts/client"
# make source directory
subprocess.check_call(["mkdir", "-p", source_dst])
# copy sources
subprocess.check_call(["cp", "-r", "src/.", source_dst])
# compile sources
subprocess.check_call(["python2.7", "-m", "compileall", source_dst])
unpacked_dst = "dist/wotmod/unpacked"
# copy license and readme
subprocess.check_call(["cp", "-r", "LICENSE", unpacked_dst])
subprocess.check_call(["cp", "-r", "README.md", unpacked_dst])
# create meta.xml content
metadata = """
<root>
<id>{id}</id>
<version>{version}</version>
<name>{name}</name>
<description>{description}</description>
</root>
""".format(
id=get_id(), version=get_version(), name=NAME, description=DESCRIPTION
)
# write meta.xml
with open("dist/wotmod/unpacked/meta.xml", "w") as meta_file:
meta_file.write(metadata.strip())
# create wotmod file
wotmod_dst = path.join("dist/wotmod", get_wotmod_name())
with ZipFile(wotmod_dst, "w", ZIP_STORED) as wotmod_file:
for file_path in get_files(unpacked_dst):
zipped_path = path.relpath(file_path, unpacked_dst)
with open(file_path, "rb") as unzipped_file:
wotmod_file.writestr(zipped_path, unzipped_file.read())
@task(wotmod)
def release():
# clean dist directory
subprocess.check_call(["rm", "-rf", "dist/release"])
# make release directory
unpacked_dst = "dist/release/unpacked"
subprocess.check_call(["mkdir", "-p", unpacked_dst])
# copy wotmod
wotmod_dst = path.join("dist/wotmod", get_wotmod_name())
subprocess.check_call(["cp", wotmod_dst, unpacked_dst])
# fetch dependencies
for dependency in RELEASE_DEPENDENCIES:
subprocess.check_call(["wget", "-nv", "-P", unpacked_dst, dependency])
# create release archive
release_dst = path.join("dist/release", get_release_name())
with ZipFile(release_dst, "w", ZIP_DEFLATED) as release_file:
for file_path in get_files(unpacked_dst):
zipped_path = path.relpath(file_path, unpacked_dst)
with open(file_path, "rb") as unzipped_file:
release_file.writestr(zipped_path, unzipped_file.read())
@task(release)
def github_actions_release():
set_github_actions_output("version", get_version())
wotmod_path = path.join("dist/wotmod", get_wotmod_name())
set_github_actions_output("wotmod_path", wotmod_path)
set_github_actions_output("wotmod_name", get_wotmod_name())
release_path = path.join("dist/release", get_release_name())
set_github_actions_output("release_path", release_path)
set_github_actions_output("release_name", get_release_name())
@task(wotmod)
def install(dst):
wotmod_dst = path.join("dist/wotmod", get_wotmod_name())
subprocess.check_call(["cp", wotmod_dst, dst])
def get_id():
return "{author}.{name}".format(author=AUTHOR, name=NAME.lower().replace(" ", "-"))
def get_version():
try:
tag = subprocess.check_output(["git", "describe", "--tags"]).strip()
return tag.lstrip("v")
except subprocess.CalledProcessError:
return "unknown"
def get_wotmod_name():
return "{id}_{version}.wotmod".format(id=get_id(), version=get_version())
def get_release_name():
return "{name}-{version}.zip".format(
name=NAME.lower().replace(" ", "-"), version=get_version()
)
def get_files(directory):
for root, _, files in os.walk(directory):
for file_name in files:
yield path.join(root, file_name)
def set_github_actions_output(name, value):
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write("{}={}\n".format(name, value))
if __name__ == "__main__":
main()