mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
重构插件商店更新逻辑&彻底修复工作流 (#1782)
* 修复bot-check工作流 * Update bot_check.yml * 修复依赖问题 * 修复戳一戳自检鉴权 * 🚨 auto fix by pre-commit hooks * 优化工作流执行顺序 * 更新插件测试 * 更新插件商店 * 🚨 auto fix by pre-commit hooks * Update bot_check.yml * Update bot_check.yml * Update bot_check.yml * 请求 @ThelevenFD 修复测试 * 🚨 auto fix by pre-commit hooks * Update zhenxun/builtin_plugins/plugin_store/data_source.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * 修复代码过长的问题 * 🚨 auto fix by pre-commit hooks * 同步check.py * Update test_check.py * 🚨 auto fix by pre-commit hooks --------- Co-authored-by: ThelevenFD <104363913+ThelevenFD@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
This commit is contained in:
parent
ccf043d670
commit
a15303a891
6
.github/workflows/bot_check.yml
vendored
6
.github/workflows/bot_check.yml
vendored
@ -6,12 +6,14 @@ on:
|
|||||||
paths:
|
paths:
|
||||||
- zhenxun/**
|
- zhenxun/**
|
||||||
- tests/**
|
- tests/**
|
||||||
|
- .github/workflows/bot_check.yml
|
||||||
- bot.py
|
- bot.py
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: ["main"]
|
branches: ["main"]
|
||||||
paths:
|
paths:
|
||||||
- zhenxun/**
|
- zhenxun/**
|
||||||
- tests/**
|
- tests/**
|
||||||
|
- .github/workflows/bot_check.yml
|
||||||
- bot.py
|
- bot.py
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@ -63,9 +65,9 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
poetry run sudo apt-get update
|
poetry run sudo apt-get update
|
||||||
poetry run sudo apt-get install -y libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-libav flite x264 libx264-dev
|
poetry run sudo apt-get install -y libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-libav flite x264 libx264-dev
|
||||||
poetry run sudo playwright install-deps
|
|
||||||
poetry run pip install playwright
|
poetry run pip install playwright
|
||||||
poetry run sudo playwright install
|
poetry run playwright install-deps
|
||||||
|
poetry run playwright install
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: poetry run pytest --cov=zhenxun --cov-report xml
|
run: poetry run pytest --cov=zhenxun --cov-report xml
|
||||||
|
|||||||
@ -67,7 +67,7 @@ async def test_check(
|
|||||||
"""
|
"""
|
||||||
测试自检
|
测试自检
|
||||||
"""
|
"""
|
||||||
from zhenxun.builtin_plugins.check import _matcher
|
from zhenxun.builtin_plugins.check import _self_check_matcher
|
||||||
from zhenxun.builtin_plugins.check.data_source import __get_version
|
from zhenxun.builtin_plugins.check.data_source import __get_version
|
||||||
from zhenxun.configs.config import BotConfig
|
from zhenxun.configs.config import BotConfig
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ async def test_check(
|
|||||||
mock_build_message_return,
|
mock_build_message_return,
|
||||||
mock_template_path_new,
|
mock_template_path_new,
|
||||||
) = init_mocker(mocker, tmp_path)
|
) = init_mocker(mocker, tmp_path)
|
||||||
async with app.test_matcher(_matcher) as ctx:
|
async with app.test_matcher(_self_check_matcher) as ctx:
|
||||||
bot = create_bot(ctx)
|
bot = create_bot(ctx)
|
||||||
bot: Bot = cast(Bot, bot)
|
bot: Bot = cast(Bot, bot)
|
||||||
raw_message = "自检"
|
raw_message = "自检"
|
||||||
@ -137,7 +137,7 @@ async def test_check_arm(
|
|||||||
"""
|
"""
|
||||||
测试自检(arm)
|
测试自检(arm)
|
||||||
"""
|
"""
|
||||||
from zhenxun.builtin_plugins.check import _matcher
|
from zhenxun.builtin_plugins.check import _self_check_matcher
|
||||||
from zhenxun.builtin_plugins.check.data_source import __get_version
|
from zhenxun.builtin_plugins.check.data_source import __get_version
|
||||||
from zhenxun.configs.config import BotConfig
|
from zhenxun.configs.config import BotConfig
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ async def test_check_arm(
|
|||||||
mock_cpuinfo.get_cpu_info.return_value = {}
|
mock_cpuinfo.get_cpu_info.return_value = {}
|
||||||
mock_psutil.cpu_freq.return_value = {}
|
mock_psutil.cpu_freq.return_value = {}
|
||||||
|
|
||||||
async with app.test_matcher(_matcher) as ctx:
|
async with app.test_matcher(_self_check_matcher) as ctx:
|
||||||
bot = create_bot(ctx)
|
bot = create_bot(ctx)
|
||||||
bot: Bot = cast(Bot, bot)
|
bot: Bot = cast(Bot, bot)
|
||||||
raw_message = "自检"
|
raw_message = "自检"
|
||||||
|
|||||||
@ -57,7 +57,9 @@ async def test_update_all_plugin_basic_need_update(
|
|||||||
)
|
)
|
||||||
ctx.should_call_send(
|
ctx.should_call_send(
|
||||||
event=event,
|
event=event,
|
||||||
message=Message(message="已更新插件 识图\n共计1个插件! 重启后生效"),
|
message=Message(
|
||||||
|
message="--已更新1个插件 0个失败 1个成功--\n* 以下插件更新成功:\n\t- 识图\n重启后生效" # noqa: E501
|
||||||
|
),
|
||||||
result=None,
|
result=None,
|
||||||
bot=bot,
|
bot=bot,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -256,10 +256,9 @@ class ShopManage:
|
|||||||
result = await AsyncHttpx.gather_download_file(
|
result = await AsyncHttpx.gather_download_file(
|
||||||
req_download_urls, req_paths
|
req_download_urls, req_paths
|
||||||
)
|
)
|
||||||
for _id, success in enumerate(result):
|
for success in result:
|
||||||
if not success:
|
if not success:
|
||||||
raise Exception("插件依赖文件下载失败")
|
raise Exception("插件依赖文件下载失败")
|
||||||
else:
|
|
||||||
logger.debug(f"插件依赖文件列表: {req_paths}", "插件管理")
|
logger.debug(f"插件依赖文件列表: {req_paths}", "插件管理")
|
||||||
install_requirement(plugin_path)
|
install_requirement(plugin_path)
|
||||||
return True
|
return True
|
||||||
@ -389,9 +388,12 @@ class ShopManage:
|
|||||||
"""
|
"""
|
||||||
data: dict[str, StorePluginInfo] = await cls.get_data()
|
data: dict[str, StorePluginInfo] = await cls.get_data()
|
||||||
plugin_list = list(data.keys())
|
plugin_list = list(data.keys())
|
||||||
update_list = []
|
update_failed_list = []
|
||||||
|
update_success_list = []
|
||||||
|
result = "--已更新{}个插件 {}个失败 {}个成功--"
|
||||||
logger.info(f"尝试更新全部插件 {plugin_list}", "插件管理")
|
logger.info(f"尝试更新全部插件 {plugin_list}", "插件管理")
|
||||||
for plugin_key in plugin_list:
|
for plugin_key in plugin_list:
|
||||||
|
try:
|
||||||
plugin_info = data[plugin_key]
|
plugin_info = data[plugin_key]
|
||||||
plugin_list = await cls.get_loaded_plugins("module", "version")
|
plugin_list = await cls.get_loaded_plugins("module", "version")
|
||||||
suc_plugin = {p[0]: (p[1] or "Unknown") for p in plugin_list}
|
suc_plugin = {p[0]: (p[1] or "Unknown") for p in plugin_list}
|
||||||
@ -412,11 +414,27 @@ class ShopManage:
|
|||||||
plugin_info.is_dir,
|
plugin_info.is_dir,
|
||||||
is_external,
|
is_external,
|
||||||
)
|
)
|
||||||
update_list.append(plugin_key)
|
update_success_list.append(plugin_key)
|
||||||
if len(update_list) == 0:
|
except Exception as e:
|
||||||
|
logger.error(f"更新插件 {plugin_key} 失败: {e}", "插件管理")
|
||||||
|
update_failed_list.append(plugin_key)
|
||||||
|
if not update_success_list and not update_failed_list:
|
||||||
return "全部插件已是最新版本"
|
return "全部插件已是最新版本"
|
||||||
return "已更新插件 {}\n共计{}个插件! 重启后生效".format(
|
if update_success_list:
|
||||||
"\n- ".join(update_list), len(update_list)
|
result += "\n* 以下插件更新成功:\n\t- {}".format(
|
||||||
|
"\n\t- ".join(update_success_list)
|
||||||
|
)
|
||||||
|
if update_failed_list:
|
||||||
|
result += "\n* 以下插件更新失败:\n\t- {}".format(
|
||||||
|
"\n\t- ".join(update_failed_list)
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
result.format(
|
||||||
|
len(update_success_list) + len(update_failed_list),
|
||||||
|
len(update_failed_list),
|
||||||
|
len(update_success_list),
|
||||||
|
)
|
||||||
|
+ "\n重启后生效"
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user