-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
198 lines (196 loc) · 6.42 KB
/
run.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import asyncio
from getopt import getopt
from json import dumps, loads
from pathlib import Path
from shutil import rmtree
from sys import argv
from utils import (
Plugin,
commit_changes,
get_commit_hash_from_registry,
get_git_head_hash,
get_pypi_version,
get_runtime_version_latest,
git_add,
load_plugins_from_registry,
pdm_create_project_from_git,
pdm_create_project_from_pypi,
pdm_run_project_from_git,
pdm_run_project_from_pypi,
)
opts, args = getopt(argv[1:], "l:", ["limit=", "no-commit"])
limit = 0
no_commit = False
for opt, arg in opts:
if opt in ("-l", "--limit"):
if not arg.isdigit():
print("limit 必须是数字")
exit(1)
limit = int(arg)
elif opt == "--no-commit":
print("不提交测试结果")
no_commit = True
print("从 nonebot/registry 获取提交哈希")
commit = asyncio.run(get_commit_hash_from_registry())
print("从 nonebot/registry 获取插件列表")
plugins: list[dict] = load_plugins_from_registry(commit)
STATE = Path("state.json")
state: dict[str, str | dict] = {}
if STATE.exists():
print("加载历史记录")
state = loads(STATE.read_bytes())
modified = False
print("正在检查更新 nonebot2")
version = get_runtime_version_latest()
VER_KEY = "__nonebot2.version__"
if not state.get(VER_KEY):
modified = True
elif version != state.get(VER_KEY):
print(f"nonebot2 {state.get(VER_KEY)} -> {version}")
modified = True
state[VER_KEY] = version or state.get(VER_KEY)
for data in plugins:
plugin = Plugin(data)
if not state.get(plugin.project_link):
state[plugin.project_link] = {}
print("正在检查更新", plugin.module_name)
get_pypi_version(plugin)
plugin.new_from_pypi = plugin.pypi_version and (
not state.get(plugin.project_link)
or plugin.pypi_version != state[plugin.project_link].get("pypi_version")
)
if plugin.pypi_version != state[plugin.project_link].get("pypi_version"):
print(
plugin.module_name,
"PyPI:",
state[plugin.project_link].get("pypi_version"),
"->",
plugin.pypi_version,
)
asyncio.run(get_git_head_hash(plugin))
plugin.new_from_git = plugin.git_hash and (
not state.get(plugin.project_link)
or plugin.git_hash != state[plugin.project_link].get("git_hash")
)
if plugin.git_hash != state[plugin.project_link].get("git_hash"):
print(
plugin.module_name,
"Git: ",
state[plugin.project_link].get("git_hash"),
"->",
plugin.git_hash,
)
d = {
VER_KEY: version or state[plugin.project_link].get(VER_KEY),
"first_seen": state[plugin.project_link].get("first_seen") or commit,
"module_name": plugin.module_name,
"project_link": plugin.project_link,
"display_name": plugin.name.strip(),
"desc": plugin.desc,
"author": plugin.author,
"homepage": plugin.homepage,
"pypi_version": plugin.pypi_version,
"pypi_create": state[plugin.project_link].get("pypi_create") or False,
"pypi_run": state[plugin.project_link].get("pypi_run") or False,
"git_hash": plugin.git_hash,
"git_create": state[plugin.project_link].get("git_create") or False,
"git_run": state[plugin.project_link].get("git_run") or False,
"last_seen": commit,
"stderr_pypi": state[plugin.project_link].get("stderr_pypi"),
"stderr_git": state[plugin.project_link].get("stderr_git"),
}
if version != state[plugin.project_link].get(VER_KEY) or (
plugin.pypi_version and plugin.new_from_pypi
):
modified = True
asyncio.run(pdm_create_project_from_pypi(plugin))
if plugin.created_from_pypi:
d["pypi_create"] = True
asyncio.run(pdm_run_project_from_pypi(plugin, d))
if plugin.booted_from_pypi:
d["pypi_run"] = True
plugin.clear()
if version != state[plugin.project_link].get(VER_KEY) or (
plugin.git_hash and plugin.new_from_git
):
modified = True
asyncio.run(pdm_create_project_from_git(plugin))
if plugin.created_from_git:
d["git_create"] = True
asyncio.run(pdm_run_project_from_git(plugin, d))
if plugin.booted_from_git:
d["git_run"] = True
plugin.clear()
plugin.unlink()
if not d.get("stderr_pypi"):
d.pop("stderr_pypi", None)
if not d.get("stderr_git"):
d.pop("stderr_git", None)
state[plugin.project_link] = d
if plugin.new_from_pypi or plugin.new_from_git:
limit -= 1
if not limit:
break
if modified:
print("保存历史记录")
STATE.write_bytes(dumps(state, ensure_ascii=False, indent="\t").encode())
print("生成测试报告")
RESULTS = Path("RESULTS.md")
P = "✅"
F = "❌"
p, r, c = [], [], []
for k, v in state.items():
if k == VER_KEY:
continue
if v[VER_KEY] != version:
continue
if v["pypi_run"] or v["git_run"]:
p.append(k)
elif v["pypi_create"] or v["git_create"]:
r.append(k)
else:
c.append(k)
s = ""
if not limit:
s += "已达到限制,结束测试。\n\n"
s += f"`nonebot2 == {version}`\n"
if p:
s += f"## {P} 满足基础可靠性\n"
for i in p:
s += (
f"- `{state[i]['module_name']}` {state[i]['display_name']}\n"
+ " - `PyPI "
+ (P if state[i]["pypi_run"] else F)
+ "` `Git "
+ (P if state[i]["git_run"] else F)
+ "`\n"
)
if r:
s += f"\n## {F} 运行时错误\n"
for i in r:
s += (
f"- `{state[i]['module_name']}` {state[i]['display_name']}\n"
+ " - `PyPI "
+ (P if state[i]["pypi_run"] else F)
+ "` `Git "
+ (P if state[i]["git_run"] else F)
+ "`\n"
)
if c:
s += f"\n## {F} 创建时错误\n"
for i in c:
s += (
f"- `{state[i]['module_name']}` {state[i]['display_name']}\n"
+ " - `PyPI "
+ (P if state[i]["pypi_run"] else F)
+ "` `Git "
+ (P if state[i]["git_run"] else F)
+ "`\n"
)
RESULTS.write_text(s, encoding="utf-8")
if not no_commit:
print("提交测试结果")
asyncio.run(git_add(RESULTS))
asyncio.run(git_add(STATE))
asyncio.run(commit_changes())
rmtree("__pycache__")