-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.py
More file actions
160 lines (146 loc) · 4.42 KB
/
script.py
File metadata and controls
160 lines (146 loc) · 4.42 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
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
# coding: utf-8
import json
import os
import shutil
import glob
import subprocess
import hashlib
import urllib.request
import urllib.error
def file_sha256(file_path: str) -> str:
sha256 = hashlib.sha256()
with open(file_path, "rb") as file:
for chunk in iter(lambda: file.read(4096), b""):
sha256.update(chunk)
return sha256.hexdigest()
def get_latest_release(repo: str) -> str | None:
if not isinstance(repo, str): raise TypeError("repo must be a string")
try:
with urllib.request.urlopen(f"https://api.github.com/repos/{repo}/releases/latest") as response:
return json.loads(response.read().decode('utf-8'))["tag_name"]
except urllib.error.HTTPError: return None
except urllib.error.URLError as e: raise e
except Exception: return None
def main() -> None:
node_version: str = get_latest_release("nodejs/node")
print(f"当前nodejs/node版本: {node_version}")
local_version: str = get_latest_release(os.environ.get("GITHUB_REPOSITORY") or "ZMBlocks/node")
print(f"当前仓库版本: {local_version}")
if node_version == local_version:
return print("最新版本的nodejs节点与本地存储库中的最新标签相同")
print("克隆最新版本的nodejs节点...")
subprocess.run(
[
"git",
"clone",
"--depth",
"1",
"--branch",
node_version,
"https://github.com/nodejs/node.git",
"nodejs"
],
shell=True,
check=True
)
print("安装nasm...")
subprocess.run(
[
"choco",
"install",
"nasm",
"-y"
],
shell=True,
check=True
)
print("开始编译...")
subprocess.run(
[
"vcbuild.bat",
"release",
"x64",
"static",
"dll",
"package"
],
shell=True,
cwd="nodejs"
)
print("编译成功,开始打包...")
print(f"7zip信息: {subprocess.run(["7z", "--help"], capture_output=True, text=True).stdout.split("\n")[1]}")
os.makedirs("bin", exist_ok=True)
os.makedirs("temp/lib", exist_ok=True)
shutil.copy("nodejs/Release/libnode.dll", "bin/libnode.dll")
subprocess.run(
[
"7z",
"a",
"-mm=Deflate",
"-t7z",
"../../bin/pdb.7z",
"*.pdb"
],
check=True,
shell=True,
cwd="nodejs/Release"
)
for file_path in glob.glob("nodejs/Release/**.lib", recursive=True):
shutil.copy(file_path, "temp/lib")
shutil.copytree(f"nodejs/Release/lib", "temp/lib", dirs_exist_ok=True)
shutil.copytree(f"nodejs/Release/node-{node_version}-win-x64/include/node", "temp/include", dirs_exist_ok=True)
subprocess.run(
[
"7z",
"a",
"-mm=Deflate",
"-t7z",
"../bin/sdk.7z",
"*"
],
check=True,
shell=True,
cwd="temp"
)
subprocess.run(
[
"7z",
"a",
"-mm=Deflate",
"-t7z",
"../../../../bin/node_modules.7z",
f"*"
],
check=True,
shell=True,
cwd=f"nodejs/Release/node-{node_version}-win-x64/node_modules"
)
print("打包成功,开始创建发行版")
with open("content.txt", "w", encoding="utf-8") as file:
file.write("\n".join([
f"**Full Changelog**: https://github.com/nodejs/node/commits/{node_version}",
f"",
f"| file | sha256 |",
f"| --------------- | ---------------------------------------------------------------- |",
f"| libnode.dll | {file_sha256("bin/libnode.dll")} |",
f"| pdb.7z | {file_sha256("bin/pdb.7z")} |",
f"| sdk.7z | {file_sha256("bin/sdk.7z")} |",
f"| node_modules.7z | {file_sha256("bin/node_modules.7z")} |"
]))
subprocess.run(
[
"gh",
"release",
"create",
node_version,
"--title",
f"Release {node_version}",
"--notes-file",
"content.txt",
"./bin/*"
],
check=True,
shell=True
)
if __name__ == "__main__":
main()