From 4b136cb876df3163b97433bf93244081ad06a345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=91=E8=BD=BB=E7=8B=82?= <1677568218@qq.com> Date: Mon, 28 Aug 2023 00:41:03 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/actions_scripts/file.py | 14 +++++++++++--- .github/actions_scripts/plugin_test.py | 9 +++++++-- .github/actions_scripts/test.py | 10 +++++++--- .github/actions_scripts/utils.py | 16 ++++++++-------- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/.github/actions_scripts/file.py b/.github/actions_scripts/file.py index edd4447..b3cc89f 100644 --- a/.github/actions_scripts/file.py +++ b/.github/actions_scripts/file.py @@ -17,7 +17,15 @@ author = os.environ["AUTHOR"] license_info = os.environ["LICENSE"] homepage = os.environ["HOMEPAGE"] -tags = os.environ["TAGS"].replace("[", "").replace("]", "").replace("'", "").replace('"', "").split(",") +tags = ( + os.environ["TAGS"] + .replace("[", "") + .replace("]", "") + .replace("'", "") + .replace('"', "") + .split(",") +) + def get_json() -> dict[str, Any]: """获取对应json文件并解析.""" @@ -36,7 +44,7 @@ def add_info(json_data: list[dict[str, str]], infos: dict[str, Any]) -> bool: i["license"] = infos["license"] i["homepage"] = infos["homepage"] i["tags"] = infos["tags"] - i["time"] = infos["time"] + i["time"] = infos["time"] return True json_data.append(infos) return False @@ -71,7 +79,7 @@ def main() -> None: "homepage": homepage, "tags": tags, "is_official": False, - "time":formatted_time + "time": formatted_time, } if add_info(data_list, info): set_action_outputs( diff --git a/.github/actions_scripts/plugin_test.py b/.github/actions_scripts/plugin_test.py index 51e543c..30a2562 100644 --- a/.github/actions_scripts/plugin_test.py +++ b/.github/actions_scripts/plugin_test.py @@ -10,18 +10,23 @@ sys.exit(1) if TYPE not in {"plugin", "adapter", "bot"}: - sys.stdout.write("Invalid TYPE value. Must be one of 'plugin', 'adapter', or 'bot'.") + sys.stdout.write( + "Invalid TYPE value. Must be one of 'plugin', 'adapter', or 'bot'." + ) sys.exit(1) bot = Bot(config_file=None) old_error_or_exception = Bot.error_or_exception + + def error_or_exception(self: Bot, message: str, exception: Exception) -> None: """出现错误直接退出.""" old_error_or_exception(self, message, exception) sys.stdout.write(message) sys.exit(1) + Bot.error_or_exception = error_or_exception if TYPE == "plugin": @@ -31,6 +36,7 @@ def error_or_exception(self: Bot, message: str, exception: Exception) -> None: if TYPE == "bot": sys.exit(0) + @bot.bot_run_hook async def bot_run_hook(bot: Bot) -> None: """在 Bot 启动后直接退出。.""" @@ -41,4 +47,3 @@ async def bot_run_hook(bot: Bot) -> None: if __name__ == "__main__": bot.run() - diff --git a/.github/actions_scripts/test.py b/.github/actions_scripts/test.py index 6ced76b..084e8cd 100644 --- a/.github/actions_scripts/test.py +++ b/.github/actions_scripts/test.py @@ -10,9 +10,11 @@ MODULE_NAME = os.environ["MODULE_NAME"] TYPE = os.environ["TYPE"] + def check_module(module_name: str) -> bool: """Check module name.""" import importlib + if module_name == "null": return False if "-" in module_name: @@ -26,15 +28,17 @@ def check_module(module_name: str) -> bool: else: return True + def alicebot_test() -> None: """验证插件是否能在 alicebot 中正常运行.""" try: - # 要执行的 Python 脚本路径 python_script_path = ".github/actions_scripts/plugin_test.py" # 整个命令 command = f"python {python_script_path} {MODULE_NAME} {TYPE}" - result = subprocess.run(command, timeout=10, check=True, shell=True,capture_output=True) # noqa: S602 + result = subprocess.run( + command, timeout=10, check=True, shell=True, capture_output=True + ) # noqa: S602 if result.returncode != 0: msg = f"脚本执行失败: {result.stdout}" raise ValueError(msg) from None @@ -62,7 +66,7 @@ def get_meta_info() -> None: author = metadata.get_all("Author") if author is None: email = metadata.get_all("Author-email") - if email is not None and "<" in email[0]: # PDM发包问题 + if email is not None and "<" in email[0]: # PDM发包问题 author = [email[0].split("<")[0].strip()] else: set_action_outputs({"result": "error", "output": "作者信息获取失败"}) diff --git a/.github/actions_scripts/utils.py b/.github/actions_scripts/utils.py index 44d73e7..5d0523a 100644 --- a/.github/actions_scripts/utils.py +++ b/.github/actions_scripts/utils.py @@ -6,11 +6,11 @@ def set_action_outputs(output_pairs: dict[str, str]) -> None: - """Sets the GitHub Action outputs, with backwards compatibility for self-hosted runners without a GITHUB_OUTPUT environment file. Keyword arguments: output_pairs - Dictionary of outputs with values.""" - if "GITHUB_OUTPUT" in os.environ : - with Path(os.environ["GITHUB_OUTPUT"]).open(mode="a") as f : - for key, value in output_pairs.items() : - f.write(f"{key}={value}\n") - else : - for key, value in output_pairs.items() : - print(f"::set-output name={key}::{value}") # noqa: T201 + """Sets the GitHub Action outputs, with backwards compatibility for self-hosted runners without a GITHUB_OUTPUT environment file. Keyword arguments: output_pairs - Dictionary of outputs with values.""" + if "GITHUB_OUTPUT" in os.environ: + with Path(os.environ["GITHUB_OUTPUT"]).open(mode="a") as f: + for key, value in output_pairs.items(): + f.write(f"{key}={value}\n") + else: + for key, value in output_pairs.items(): + print(f"::set-output name={key}::{value}") # noqa: T201