fix: 修复 workflow YAML 语法错误,移除 heredoc 格式

- 将 Python 脚本的 heredoc 格式改为使用多个 echo 命令
- 避免 GitHub Actions YAML 解析器将 heredoc 误判为 YAML 语法
- 确保 workflow 文件符合 GitHub Actions 语法规范
This commit is contained in:
WrBug
2026-01-02 05:04:02 +08:00
parent 1de9b5e958
commit 00f0898d98
+23 -43
View File
@@ -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('&', '&amp;')
text = text.replace('<', '&lt;')
text = text.replace('>', '&gt;')
# 代码块:```code``` → <pre><code>code</code></pre>
text = re.sub(r'```([^`]+)```', r'<pre><code>\1</code></pre>', text, flags=re.DOTALL)
# 行内代码:`code` → <code>code</code>(不在代码块中)
text = re.sub(r'`([^`]+)`', r'<code>\1</code>', text)
# 粗体:**text** → <b>text</b>
text = re.sub(r'\*\*([^*]+)\*\*', r'<b>\1</b>', text)
# 斜体:*text* → <i>text</i>(不在粗体或代码中)
text = re.sub(r'(?<!<[^>]*)\*([^*<>]+)\*(?![^<]*>)', r'<i>\1</i>', text)
# 链接:[text](url) → <a href="url">text</a>
text = re.sub(r'\[([^\]]+)\]\(([^)]+)\)', r'<a href="\2">\1</a>', text)
# 标题:# Heading → <b>Heading</b>
text = re.sub(r'^### (.+)$', r'<b>\1</b>', text, flags=re.MULTILINE)
text = re.sub(r'^## (.+)$', r'<b>\1</b>', text, flags=re.MULTILINE)
text = re.sub(r'^# (.+)$', r'<b>\1</b>', 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<i>(内容已截断)</i>'
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("&", "&amp;")' >> /tmp/markdown_to_html.py
echo 'text = text.replace("<", "&lt;")' >> /tmp/markdown_to_html.py
echo 'text = text.replace(">", "&gt;")' >> /tmp/markdown_to_html.py
echo 'text = re.sub(r"```([^`]+)```", r"<pre><code>\\1</code></pre>", text, flags=re.DOTALL)' >> /tmp/markdown_to_html.py
echo 'text = re.sub(r"`([^`]+)`", r"<code>\\1</code>", text)' >> /tmp/markdown_to_html.py
echo 'text = re.sub(r"\\*\\*([^*]+)\\*\\*", r"<b>\\1</b>", text)' >> /tmp/markdown_to_html.py
echo 'text = re.sub(r"(?<!<[^>]*)\\*([^*<>]+)\\*(?![^<]*>)", r"<i>\\1</i>", text)' >> /tmp/markdown_to_html.py
echo 'text = re.sub(r"\\[([^\\]]+)\\]\\(([^)]+)\\)", r"<a href=\\"\\2\\">\\1</a>", text)' >> /tmp/markdown_to_html.py
echo 'text = re.sub(r"^### (.+)$", r"<b>\\1</b>", text, flags=re.MULTILINE)' >> /tmp/markdown_to_html.py
echo 'text = re.sub(r"^## (.+)$", r"<b>\\1</b>", text, flags=re.MULTILINE)' >> /tmp/markdown_to_html.py
echo 'text = re.sub(r"^# (.+)$", r"<b>\\1</b>", 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<i>(内容已截断)</i>"' >> /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'"📄 <b>PR 描述:</b>"$'\n'"${PR_BODY_HTML}"