From 00f0898d985c2bcad8c2d92a285af5d9b7661a7b Mon Sep 17 00:00:00 2001 From: WrBug Date: Fri, 2 Jan 2026 05:04:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20workflow=20YAML=20?= =?UTF-8?q?=E8=AF=AD=E6=B3=95=E9=94=99=E8=AF=AF=EF=BC=8C=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=20heredoc=20=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 Python 脚本的 heredoc 格式改为使用多个 echo 命令 - 避免 GitHub Actions YAML 解析器将 heredoc 误判为 YAML 语法 - 确保 workflow 文件符合 GitHub Actions 语法规范 --- .github/workflows/telegram-notify.yml | 66 ++++++++++----------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/.github/workflows/telegram-notify.yml b/.github/workflows/telegram-notify.yml index 21c4be1..7a66de7 100644 --- a/.github/workflows/telegram-notify.yml +++ b/.github/workflows/telegram-notify.yml @@ -82,49 +82,29 @@ jobs: # 添加 PR 描述(如果有) if [ -n "$PR_BODY" ] && [ "$PR_BODY" != "null" ] && [ "$PR_BODY" != "" ]; then # 使用 Python 将 Markdown 转换为 HTML(更可靠) - # 创建临时 Python 脚本 - cat > /tmp/markdown_to_html.py << 'PYEOF' -import sys -import re - -text = sys.stdin.read() - -# 转义 HTML 特殊字符(先转义,避免破坏后续的转换) -text = text.replace('&', '&') -text = text.replace('<', '<') -text = text.replace('>', '>') - -# 代码块:```code``` →
code
-text = re.sub(r'```([^`]+)```', r'
\1
', text, flags=re.DOTALL) - -# 行内代码:`code` → code(不在代码块中) -text = re.sub(r'`([^`]+)`', r'\1', text) - -# 粗体:**text** → text -text = re.sub(r'\*\*([^*]+)\*\*', r'\1', text) - -# 斜体:*text* → text(不在粗体或代码中) -text = re.sub(r'(?]*)\*([^*<>]+)\*(?![^<]*>)', r'\1', text) - -# 链接:[text](url) → text -text = re.sub(r'\[([^\]]+)\]\(([^)]+)\)', r'\1', text) - -# 标题:# Heading → Heading -text = re.sub(r'^### (.+)$', r'\1', text, flags=re.MULTILINE) -text = re.sub(r'^## (.+)$', r'\1', text, flags=re.MULTILINE) -text = re.sub(r'^# (.+)$', r'\1', text, flags=re.MULTILINE) - -# 列表项:- item → • item -text = re.sub(r'^- (.+)$', r'• \1', text, flags=re.MULTILINE) -text = re.sub(r'^ - (.+)$', r' • \1', text, flags=re.MULTILINE) -text = re.sub(r'^ - (.+)$', r' • \1', text, flags=re.MULTILINE) - -# 限制长度 -if len(text) > 1000: - text = text[:1000] + '...\n(内容已截断)' - -print(text, end='') -PYEOF + # 使用 echo 创建临时 Python 脚本,避免 heredoc 导致的 YAML 解析问题 + echo 'import sys' > /tmp/markdown_to_html.py + echo 'import re' >> /tmp/markdown_to_html.py + echo '' >> /tmp/markdown_to_html.py + echo 'text = sys.stdin.read()' >> /tmp/markdown_to_html.py + echo '' >> /tmp/markdown_to_html.py + echo 'text = text.replace("&", "&")' >> /tmp/markdown_to_html.py + echo 'text = text.replace("<", "<")' >> /tmp/markdown_to_html.py + echo 'text = text.replace(">", ">")' >> /tmp/markdown_to_html.py + echo 'text = re.sub(r"```([^`]+)```", r"
\\1
", text, flags=re.DOTALL)' >> /tmp/markdown_to_html.py + echo 'text = re.sub(r"`([^`]+)`", r"\\1", text)' >> /tmp/markdown_to_html.py + echo 'text = re.sub(r"\\*\\*([^*]+)\\*\\*", r"\\1", text)' >> /tmp/markdown_to_html.py + echo 'text = re.sub(r"(?]*)\\*([^*<>]+)\\*(?![^<]*>)", r"\\1", text)' >> /tmp/markdown_to_html.py + echo 'text = re.sub(r"\\[([^\\]]+)\\]\\(([^)]+)\\)", r"\\1", text)' >> /tmp/markdown_to_html.py + echo 'text = re.sub(r"^### (.+)$", r"\\1", text, flags=re.MULTILINE)' >> /tmp/markdown_to_html.py + echo 'text = re.sub(r"^## (.+)$", r"\\1", text, flags=re.MULTILINE)' >> /tmp/markdown_to_html.py + echo 'text = re.sub(r"^# (.+)$", r"\\1", text, flags=re.MULTILINE)' >> /tmp/markdown_to_html.py + echo 'text = re.sub(r"^- (.+)$", r"• \\1", text, flags=re.MULTILINE)' >> /tmp/markdown_to_html.py + echo 'text = re.sub(r"^ - (.+)$", r" • \\1", text, flags=re.MULTILINE)' >> /tmp/markdown_to_html.py + echo 'text = re.sub(r"^ - (.+)$", r" • \\1", text, flags=re.MULTILINE)' >> /tmp/markdown_to_html.py + echo 'if len(text) > 1000:' >> /tmp/markdown_to_html.py + echo ' text = text[:1000] + "...\\n(内容已截断)"' >> /tmp/markdown_to_html.py + echo 'print(text, end="")' >> /tmp/markdown_to_html.py PR_BODY_HTML=$(echo "$PR_BODY" | python3 /tmp/markdown_to_html.py) MESSAGE="${MESSAGE}"$'\n'$'\n'"📄 PR 描述:"$'\n'"${PR_BODY_HTML}"