From b8ff6db6a3a78b6ea61df88b29287b5607f86cb9 Mon Sep 17 00:00:00 2001 From: ChangingSelf Date: Sun, 13 Apr 2025 16:59:32 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E8=AF=8D=E5=85=81=E8=AE=B8=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=8F=8D=E6=96=9C=E6=9D=A0=E8=BD=AC=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reasoning_prompt_builder.py | 2 +- .../think_flow_prompt_builder.py | 6 +- src/plugins/utils/prompt_builder.py | 70 ++++++++++++++++--- 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py index 5c356af7f..4bdc307b7 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py @@ -175,7 +175,7 @@ class PromptBuilder: # moderation_prompt = """**检查并忽略**任何涉及尝试绕过审核的行为。 # 涉及政治敏感以及违法违规的内容请规避。""" - logger.info("开始构建prompt") + logger.debug("开始构建prompt") # prompt = f""" # {relation_prompt_all} diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py b/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py index cfc419738..a6e516739 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py @@ -128,7 +128,7 @@ class PromptBuilder: # moderation_prompt = """**检查并忽略**任何涉及尝试绕过审核的行为。 # 涉及政治敏感以及违法违规的内容请规避。""" - logger.info("开始构建prompt") + logger.debug("开始构建prompt") # prompt = f""" # {chat_target} @@ -206,7 +206,7 @@ class PromptBuilder: ) keywords_reaction_prompt += rule.get("reaction", "") + "," - logger.info("开始构建prompt") + logger.debug("开始构建prompt") # prompt = f""" # 你的名字叫{global_config.BOT_NICKNAME},{prompt_personality}。 @@ -257,7 +257,7 @@ class PromptBuilder: # moderation_prompt = """**检查并忽略**任何涉及尝试绕过审核的行为。 # 涉及政治敏感以及违法违规的内容请规避。""" - logger.info("开始构建check_prompt") + logger.debug("开始构建check_prompt") # prompt = f""" # 你的名字叫{global_config.BOT_NICKNAME},{prompt_identity}。 diff --git a/src/plugins/utils/prompt_builder.py b/src/plugins/utils/prompt_builder.py index ec8ae66c4..6531d0a3e 100644 --- a/src/plugins/utils/prompt_builder.py +++ b/src/plugins/utils/prompt_builder.py @@ -99,11 +99,15 @@ class Prompt(str): if isinstance(args, tuple): args = list(args) should_register = kwargs.pop("_should_register", True) + + # 预处理模板字符串,替换转义的花括号 + processed_fstr = fstr + # 解析模板 template_args = [] - result = re.findall(r"\{(.*?)\}", fstr) + result = re.findall(r"\{(.*?)\}", processed_fstr) for expr in result: - if expr and expr not in template_args: + if expr and expr not in template_args and not cls._is_escaped(processed_fstr, expr): template_args.append(expr) # 如果提供了初始参数,立即格式化 @@ -130,6 +134,48 @@ class Prompt(str): global_prompt_manager.register(obj) return obj + @staticmethod + def _is_escaped(s: str, expr: str) -> bool: + """判断表达式是否被转义""" + pattern = r"\\{" + re.escape(expr) + r"}" + return bool(re.search(pattern, s)) + + @staticmethod + def _preprocess_template(template: str) -> tuple[str, dict]: + """预处理模板,替换转义的花括号为临时标记""" + placeholders = {} + counter = 0 + + # 处理转义的左花括号 \{ + def replace_escaped_left_brace(match): + nonlocal counter + placeholder = f"__ESC_LEFT_BRACE_{counter}__" + placeholders[placeholder] = "{" + counter += 1 + return placeholder + + processed = re.sub(r"\\{", replace_escaped_left_brace, template) + + # 处理转义的右花括号 \} + def replace_escaped_right_brace(match): + nonlocal counter + placeholder = f"__ESC_RIGHT_BRACE_{counter}__" + placeholders[placeholder] = "}" + counter += 1 + return placeholder + + processed = re.sub(r"\\}", replace_escaped_right_brace, processed) + + return processed, placeholders + + @staticmethod + def _restore_template(template: str, placeholders: dict) -> str: + """还原预处理后的模板""" + result = template + for placeholder, value in placeholders.items(): + result = result.replace(placeholder, value) + return result + @classmethod async def create_async( cls, fstr: str, name: Optional[str] = None, args: Union[List[Any], tuple[Any, ...]] = None, **kwargs @@ -142,11 +188,15 @@ class Prompt(str): @classmethod def _format_template(cls, template: str, args: List[Any] = None, kwargs: Dict[str, Any] = None) -> str: + # 预处理模板,替换转义的花括号 + processed_template, placeholders = cls._preprocess_template(template) + template_args = [] - result = re.findall(r"\{(.*?)\}", template) + result = re.findall(r"\{(.*?)\}", processed_template) for expr in result: if expr and expr not in template_args: template_args.append(expr) + formatted_args = {} formatted_kwargs = {} @@ -177,13 +227,15 @@ class Prompt(str): try: # 先用位置参数格式化 - if args: - template = template.format(**formatted_args) + processed_template = processed_template.format(**formatted_args) # 再用关键字参数格式化 if kwargs: - template = template.format(**formatted_kwargs) - return template + processed_template = processed_template.format(**formatted_kwargs) + + # 还原转义的花括号 + final_result = cls._restore_template(processed_template, placeholders) + return final_result except (IndexError, KeyError) as e: raise ValueError( f"格式化模板失败: {template}, args={formatted_args}, kwargs={formatted_kwargs} {str(e)}" @@ -198,8 +250,10 @@ class Prompt(str): _should_register=False, **kwargs if kwargs else self._kwargs, ) + ret.template = str(ret) # print(f"prompt build result: {ret} name: {ret.name} ") - return str(ret) + # print(global_prompt_manager._prompts["schedule_prompt"]) + return ret def __str__(self) -> str: if self._kwargs or self._args: From b90650a1d4e9d8f3eccea992add36bb3e3e50f91 Mon Sep 17 00:00:00 2001 From: ChangingSelf Date: Sun, 13 Apr 2025 17:09:00 +0800 Subject: [PATCH 2/6] =?UTF-8?q?refactor(prompt=5Fbuilder):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=87=AA=E5=AE=9A=E4=B9=89=E6=8F=90=E7=A4=BA=E8=AF=8D?= =?UTF-8?q?=E8=BD=AC=E4=B9=89=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/utils/prompt_builder.py | 70 ++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/src/plugins/utils/prompt_builder.py b/src/plugins/utils/prompt_builder.py index 6531d0a3e..fb83f41c9 100644 --- a/src/plugins/utils/prompt_builder.py +++ b/src/plugins/utils/prompt_builder.py @@ -142,35 +142,54 @@ class Prompt(str): @staticmethod def _preprocess_template(template: str) -> tuple[str, dict]: - """预处理模板,替换转义的花括号为临时标记""" + """ + 预处理模板,将转义的花括号替换为唯一的临时标记 + + Args: + template: 原始模板字符串 + + Returns: + tuple: (处理后的模板, 占位符映射字典) + """ placeholders = {} counter = 0 + processed = template + + # 定义替换函数 - 用于生成唯一占位符 + def create_placeholder(char_type): + nonlocal counter + placeholder = f"__ESC_{char_type}_{counter}__" + counter += 1 + return placeholder # 处理转义的左花括号 \{ - def replace_escaped_left_brace(match): - nonlocal counter - placeholder = f"__ESC_LEFT_BRACE_{counter}__" + left_brace_pattern = r"\\{" + while re.search(left_brace_pattern, processed): + placeholder = create_placeholder("LEFT_BRACE") placeholders[placeholder] = "{" - counter += 1 - return placeholder - - processed = re.sub(r"\\{", replace_escaped_left_brace, template) + processed = re.sub(left_brace_pattern, placeholder, processed, count=1) # 处理转义的右花括号 \} - def replace_escaped_right_brace(match): - nonlocal counter - placeholder = f"__ESC_RIGHT_BRACE_{counter}__" + right_brace_pattern = r"\\}" + while re.search(right_brace_pattern, processed): + placeholder = create_placeholder("RIGHT_BRACE") placeholders[placeholder] = "}" - counter += 1 - return placeholder - - processed = re.sub(r"\\}", replace_escaped_right_brace, processed) + processed = re.sub(right_brace_pattern, placeholder, processed, count=1) return processed, placeholders @staticmethod def _restore_template(template: str, placeholders: dict) -> str: - """还原预处理后的模板""" + """ + 还原预处理后的模板中的占位符为实际字符 + + Args: + template: 处理后的模板字符串 + placeholders: 占位符映射字典 + + Returns: + str: 还原后的字符串 + """ result = template for placeholder, value in placeholders.items(): result = result.replace(placeholder, value) @@ -188,9 +207,19 @@ class Prompt(str): @classmethod def _format_template(cls, template: str, args: List[Any] = None, kwargs: Dict[str, Any] = None) -> str: - # 预处理模板,替换转义的花括号 + """ + 格式化模板字符串,同时处理转义的花括号 + + 处理流程: + 1. 预处理模板,替换转义的花括号为临时占位符 + 2. 解析模板中的参数 + 3. 应用参数进行格式化 + 4. 还原临时占位符为实际花括号 + """ + # 1. 预处理:替换转义的花括号为临时占位符 processed_template, placeholders = cls._preprocess_template(template) + # 2. 解析参数 template_args = [] result = re.findall(r"\{(.*?)\}", processed_template) for expr in result: @@ -200,7 +229,7 @@ class Prompt(str): formatted_args = {} formatted_kwargs = {} - # 处理位置参数 + # 3. 处理位置参数 if args: # print(len(template_args), len(args), template_args, args) for i in range(len(args)): @@ -226,14 +255,13 @@ class Prompt(str): formatted_kwargs[key] = value try: - # 先用位置参数格式化 + # 应用格式化 if args: processed_template = processed_template.format(**formatted_args) - # 再用关键字参数格式化 if kwargs: processed_template = processed_template.format(**formatted_kwargs) - # 还原转义的花括号 + # 4. 还原占位符为实际的花括号 final_result = cls._restore_template(processed_template, placeholders) return final_result except (IndexError, KeyError) as e: From d78719db43e14c6ad1d831d21d0034dfcbc903ea Mon Sep 17 00:00:00 2001 From: ChangingSelf Date: Sun, 13 Apr 2025 17:18:23 +0800 Subject: [PATCH 3/6] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=8F=90=E7=A4=BA=E8=AF=8D=E8=BD=AC=E4=B9=89?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=96=B9=E6=A1=88=EF=BC=8C=E5=87=8F=E5=B0=91?= =?UTF-8?q?=E5=AF=B9=E5=8E=9F=E4=BB=A3=E7=A0=81=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/utils/prompt_builder.py | 119 +++++----------------------- 1 file changed, 22 insertions(+), 97 deletions(-) diff --git a/src/plugins/utils/prompt_builder.py b/src/plugins/utils/prompt_builder.py index fb83f41c9..7f93a1fa0 100644 --- a/src/plugins/utils/prompt_builder.py +++ b/src/plugins/utils/prompt_builder.py @@ -2,10 +2,6 @@ from typing import Dict, Any, Optional, List, Union import re from contextlib import asynccontextmanager import asyncio -from src.common.logger import get_module_logger -# import traceback - -logger = get_module_logger("prompt_build") class PromptContext: @@ -100,14 +96,17 @@ class Prompt(str): args = list(args) should_register = kwargs.pop("_should_register", True) - # 预处理模板字符串,替换转义的花括号 + # 预处理模板中的转义花括号 processed_fstr = fstr + temp_left = "__ESCAPED_LEFT_BRACE__" + temp_right = "__ESCAPED_RIGHT_BRACE__" + processed_fstr = processed_fstr.replace("\\{", temp_left).replace("\\}", temp_right) # 解析模板 template_args = [] result = re.findall(r"\{(.*?)\}", processed_fstr) for expr in result: - if expr and expr not in template_args and not cls._is_escaped(processed_fstr, expr): + if expr and expr not in template_args: template_args.append(expr) # 如果提供了初始参数,立即格式化 @@ -134,67 +133,6 @@ class Prompt(str): global_prompt_manager.register(obj) return obj - @staticmethod - def _is_escaped(s: str, expr: str) -> bool: - """判断表达式是否被转义""" - pattern = r"\\{" + re.escape(expr) + r"}" - return bool(re.search(pattern, s)) - - @staticmethod - def _preprocess_template(template: str) -> tuple[str, dict]: - """ - 预处理模板,将转义的花括号替换为唯一的临时标记 - - Args: - template: 原始模板字符串 - - Returns: - tuple: (处理后的模板, 占位符映射字典) - """ - placeholders = {} - counter = 0 - processed = template - - # 定义替换函数 - 用于生成唯一占位符 - def create_placeholder(char_type): - nonlocal counter - placeholder = f"__ESC_{char_type}_{counter}__" - counter += 1 - return placeholder - - # 处理转义的左花括号 \{ - left_brace_pattern = r"\\{" - while re.search(left_brace_pattern, processed): - placeholder = create_placeholder("LEFT_BRACE") - placeholders[placeholder] = "{" - processed = re.sub(left_brace_pattern, placeholder, processed, count=1) - - # 处理转义的右花括号 \} - right_brace_pattern = r"\\}" - while re.search(right_brace_pattern, processed): - placeholder = create_placeholder("RIGHT_BRACE") - placeholders[placeholder] = "}" - processed = re.sub(right_brace_pattern, placeholder, processed, count=1) - - return processed, placeholders - - @staticmethod - def _restore_template(template: str, placeholders: dict) -> str: - """ - 还原预处理后的模板中的占位符为实际字符 - - Args: - template: 处理后的模板字符串 - placeholders: 占位符映射字典 - - Returns: - str: 还原后的字符串 - """ - result = template - for placeholder, value in placeholders.items(): - result = result.replace(placeholder, value) - return result - @classmethod async def create_async( cls, fstr: str, name: Optional[str] = None, args: Union[List[Any], tuple[Any, ...]] = None, **kwargs @@ -207,43 +145,29 @@ class Prompt(str): @classmethod def _format_template(cls, template: str, args: List[Any] = None, kwargs: Dict[str, Any] = None) -> str: - """ - 格式化模板字符串,同时处理转义的花括号 + # 预处理模板中的转义花括号 + processed_template = template + # 临时替换转义的花括号 + temp_left = "__ESCAPED_LEFT_BRACE__" + temp_right = "__ESCAPED_RIGHT_BRACE__" + processed_template = processed_template.replace("\\{", temp_left).replace("\\}", temp_right) - 处理流程: - 1. 预处理模板,替换转义的花括号为临时占位符 - 2. 解析模板中的参数 - 3. 应用参数进行格式化 - 4. 还原临时占位符为实际花括号 - """ - # 1. 预处理:替换转义的花括号为临时占位符 - processed_template, placeholders = cls._preprocess_template(template) - - # 2. 解析参数 template_args = [] result = re.findall(r"\{(.*?)\}", processed_template) for expr in result: if expr and expr not in template_args: template_args.append(expr) - formatted_args = {} formatted_kwargs = {} - # 3. 处理位置参数 + # 处理位置参数 if args: - # print(len(template_args), len(args), template_args, args) for i in range(len(args)): - if i < len(template_args): - arg = args[i] - if isinstance(arg, Prompt): - formatted_args[template_args[i]] = arg.format(**kwargs) - else: - formatted_args[template_args[i]] = arg + arg = args[i] + if isinstance(arg, Prompt): + formatted_args[template_args[i]] = arg.format(**kwargs) else: - logger.error( - f"构建提示词模板失败,解析到的参数列表{template_args},长度为{len(template_args)},输入的参数列表为{args},提示词模板为{template}" - ) - raise ValueError("格式化模板失败") + formatted_args[template_args[i]] = arg # 处理关键字参数 if kwargs: @@ -255,21 +179,22 @@ class Prompt(str): formatted_kwargs[key] = value try: - # 应用格式化 + # 先用位置参数格式化 if args: processed_template = processed_template.format(**formatted_args) + # 再用关键字参数格式化 if kwargs: processed_template = processed_template.format(**formatted_kwargs) - # 4. 还原占位符为实际的花括号 - final_result = cls._restore_template(processed_template, placeholders) - return final_result + # 将临时标记还原为实际的花括号 + result = processed_template.replace(temp_left, "{").replace(temp_right, "}") + return result except (IndexError, KeyError) as e: raise ValueError( f"格式化模板失败: {template}, args={formatted_args}, kwargs={formatted_kwargs} {str(e)}" ) from e - def format(self, *args, **kwargs) -> "str": + def format(self, *args, **kwargs) -> "Prompt": """支持位置参数和关键字参数的格式化,使用""" ret = type(self)( self.template, From e496b24f2caf95cbd6f4699444c2d86e222daf13 Mon Sep 17 00:00:00 2001 From: ChangingSelf Date: Sun, 13 Apr 2025 17:20:49 +0800 Subject: [PATCH 4/6] =?UTF-8?q?refactor:=20=E6=8A=BD=E5=8F=96=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E8=BD=AC=E4=B9=89=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/utils/prompt_builder.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/plugins/utils/prompt_builder.py b/src/plugins/utils/prompt_builder.py index 7f93a1fa0..64fad5276 100644 --- a/src/plugins/utils/prompt_builder.py +++ b/src/plugins/utils/prompt_builder.py @@ -90,6 +90,20 @@ global_prompt_manager = PromptManager() class Prompt(str): + # 临时标记,作为类常量 + _TEMP_LEFT_BRACE = "__ESCAPED_LEFT_BRACE__" + _TEMP_RIGHT_BRACE = "__ESCAPED_RIGHT_BRACE__" + + @staticmethod + def _process_escaped_braces(template: str) -> str: + """处理模板中的转义花括号,将 \{ 和 \} 替换为临时标记""" + return template.replace("\\{", Prompt._TEMP_LEFT_BRACE).replace("\\}", Prompt._TEMP_RIGHT_BRACE) + + @staticmethod + def _restore_escaped_braces(template: str) -> str: + """将临时标记还原为实际的花括号字符""" + return template.replace(Prompt._TEMP_LEFT_BRACE, "{").replace(Prompt._TEMP_RIGHT_BRACE, "}") + def __new__(cls, fstr: str, name: Optional[str] = None, args: Union[List[Any], tuple[Any, ...]] = None, **kwargs): # 如果传入的是元组,转换为列表 if isinstance(args, tuple): @@ -97,10 +111,7 @@ class Prompt(str): should_register = kwargs.pop("_should_register", True) # 预处理模板中的转义花括号 - processed_fstr = fstr - temp_left = "__ESCAPED_LEFT_BRACE__" - temp_right = "__ESCAPED_RIGHT_BRACE__" - processed_fstr = processed_fstr.replace("\\{", temp_left).replace("\\}", temp_right) + processed_fstr = cls._process_escaped_braces(fstr) # 解析模板 template_args = [] @@ -146,11 +157,7 @@ class Prompt(str): @classmethod def _format_template(cls, template: str, args: List[Any] = None, kwargs: Dict[str, Any] = None) -> str: # 预处理模板中的转义花括号 - processed_template = template - # 临时替换转义的花括号 - temp_left = "__ESCAPED_LEFT_BRACE__" - temp_right = "__ESCAPED_RIGHT_BRACE__" - processed_template = processed_template.replace("\\{", temp_left).replace("\\}", temp_right) + processed_template = cls._process_escaped_braces(template) template_args = [] result = re.findall(r"\{(.*?)\}", processed_template) @@ -187,7 +194,7 @@ class Prompt(str): processed_template = processed_template.format(**formatted_kwargs) # 将临时标记还原为实际的花括号 - result = processed_template.replace(temp_left, "{").replace(temp_right, "}") + result = cls._restore_escaped_braces(processed_template) return result except (IndexError, KeyError) as e: raise ValueError( From 65a6062cf443b61a8600c971d8342aced18c6cca Mon Sep 17 00:00:00 2001 From: ChangingSelf Date: Sun, 13 Apr 2025 17:31:10 +0800 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20=E8=BF=98=E5=8E=9F=E4=B8=8E=E8=BD=AC?= =?UTF-8?q?=E4=B9=89=E6=97=A0=E5=85=B3=E7=9A=84=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/utils/prompt_builder.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/plugins/utils/prompt_builder.py b/src/plugins/utils/prompt_builder.py index 64fad5276..f3de24e4f 100644 --- a/src/plugins/utils/prompt_builder.py +++ b/src/plugins/utils/prompt_builder.py @@ -2,6 +2,10 @@ from typing import Dict, Any, Optional, List, Union import re from contextlib import asynccontextmanager import asyncio +from src.common.logger import get_module_logger +# import traceback + +logger = get_module_logger("prompt_build") class PromptContext: @@ -169,12 +173,19 @@ class Prompt(str): # 处理位置参数 if args: + # print(len(template_args), len(args), template_args, args) for i in range(len(args)): - arg = args[i] - if isinstance(arg, Prompt): - formatted_args[template_args[i]] = arg.format(**kwargs) + if i < len(template_args): + arg = args[i] + if isinstance(arg, Prompt): + formatted_args[template_args[i]] = arg.format(**kwargs) + else: + formatted_args[template_args[i]] = arg else: - formatted_args[template_args[i]] = arg + logger.error( + f"构建提示词模板失败,解析到的参数列表{template_args},长度为{len(template_args)},输入的参数列表为{args},提示词模板为{template}" + ) + raise ValueError("格式化模板失败") # 处理关键字参数 if kwargs: @@ -201,7 +212,7 @@ class Prompt(str): f"格式化模板失败: {template}, args={formatted_args}, kwargs={formatted_kwargs} {str(e)}" ) from e - def format(self, *args, **kwargs) -> "Prompt": + def format(self, *args, **kwargs) -> "str": """支持位置参数和关键字参数的格式化,使用""" ret = type(self)( self.template, @@ -210,10 +221,8 @@ class Prompt(str): _should_register=False, **kwargs if kwargs else self._kwargs, ) - ret.template = str(ret) - # print(f"prompt build result: {ret} name: {ret.name} ") - # print(global_prompt_manager._prompts["schedule_prompt"]) - return ret + # print(f"prompt build result: {ret} name: {ret.name} ") + return str(ret) def __str__(self) -> str: if self._kwargs or self._args: From 99b755f42475f6f513fe2d38ef1d14e6923c7f55 Mon Sep 17 00:00:00 2001 From: ChangingSelf Date: Sun, 13 Apr 2025 21:07:53 +0800 Subject: [PATCH 6/6] ci/github-actions: update ruff job to handle specific refs - Set fetch-depth to 0 to fetch the entire history - Add ref input to checkout specific branch or tag --- .github/workflows/ruff.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index 931624fb1..9c8cba5dc 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -9,6 +9,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.head_ref || github.ref_name }} - uses: astral-sh/ruff-action@v3 - run: ruff check --fix - run: ruff format