Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/plugins/github/plugins/publish/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import jinja2

from src.plugins.github import plugin_config
from src.providers.docker_test import DockerTestResult
from src.providers.utils import dumps_json
from src.providers.validation import ValidationDict
from src.providers.validation.models import PublishType

Expand Down Expand Up @@ -89,3 +91,19 @@ async def render_comment(result: ValidationDict, reuse: bool = False) -> str:
errors=result.errors,
skip_test=result.skip_test,
)


async def render_summary(test_result: DockerTestResult, output: str, project_link: str):
"""将测试结果转换为工作流总结"""
template = env.get_template("summary.md.jinja")

return await template.render_async(
project_link=project_link,
version=test_result.version,
load=test_result.load,
run=test_result.run,
metadata=dumps_json(test_result.metadata.model_dump(), False)
if test_result.metadata
else {},
output=output,
)
17 changes: 17 additions & 0 deletions src/plugins/github/plugins/publish/templates/summary.md.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{# 发布工作流总结 #}
# 📃 插件 {{ project_link }} ({{ version }})

> **{{ "✅ 插件已尝试运行" if run else "⚠️ 插件未开始运行"}}**
> **{{ "✅ 插件加载成功" if load else "⚠️ 插件加载失败"}}**

## 插件元数据

<pre><code>{{ metadata }}</code></pre>

## 插件输出

<pre><code>{{ output }}</code></pre>

---

💪 Powered by [NoneFlow](https://github.com/nonebot/noneflow)
13 changes: 5 additions & 8 deletions src/plugins/github/plugins/publish/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
PROJECT_LINK_PATTERN,
TAGS_PATTERN,
)
from .render import render_summary


def strip_ansi(text: str | None) -> str:
Expand Down Expand Up @@ -114,14 +115,10 @@ async def validate_plugin_info_from_issue(
raw_data["metadata"] = bool(metadata)

# 输出插件测试相关信息
test_status = f"插件 {project_link}({test_result.version}) 加载{'成功' if test_result.load else '失败'},运行{'开始' if test_result.run else '失败'}"

add_step_summary(test_status)
add_step_summary(f"插件元数据:{metadata}")
add_step_summary("插件测试输出:")
add_step_summary(test_output)

logger.info(test_status)
add_step_summary(await render_summary(test_result, test_output, project_link))
logger.info(
f"插件 {project_link}({test_result.version}) 插件加载{'成功' if test_result.load else '失败'} {'插件已尝试加载' if test_result.run else '插件并未开始运行'}"
)
logger.info(f"插件元数据:{metadata}")
logger.info("插件测试输出:")
for output in test_result.outputs:
Expand Down
1 change: 0 additions & 1 deletion src/providers/docker_test/plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ async def run(self):
# 创建测试目录
if not self.test_dir.exists():
self.test_dir.mkdir()
self._log_output(f"创建测试目录 {self.test_dir}")

# 创建插件测试项目
await self.create_poetry_project()
Expand Down
2 changes: 1 addition & 1 deletion src/providers/store_test/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def validate_plugin(

# 输出插件测试相关信息
click.echo(
f"插件 {project_link}({plugin_test_version}) 加载{'成功' if plugin_test_load else '失败'},运行{'开始' if plugin_test_result.run else '失败'}"
f"插件 {project_link}({plugin_test_version}) 加载{'成功' if plugin_test_load else '失败'} {'插件已尝试加载' if plugin_test_result.run else '插件并未开始运行'}"
)
click.echo(f"插件元数据:{plugin_metadata}")
click.echo("插件测试输出:")
Expand Down
16 changes: 12 additions & 4 deletions src/providers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,22 @@ def load_json(text: str):
return pyjson5.decode(text)


def dump_json(path: Path, data: Any, minify: bool = True) -> None:
"""保存 JSON 文件
def dumps_json(data: Any, minify: bool = True) -> str:
"""格式化对象"""
if minify:
data = json.dumps(data, ensure_ascii=False, separators=(",", ":"))
else:
data = json.dumps(data, ensure_ascii=False, indent=2)
return data

为减少文件大小,还需手动设置 separators
"""

def dump_json(path: Path, data: Any, minify: bool = True) -> None:
"""保存 JSON 文件"""
data = to_jsonable_python(data)

with open(path, "w", encoding="utf-8") as f:
if minify:
# 为减少文件大小,还需手动设置 separators
json.dump(data, f, ensure_ascii=False, separators=(",", ":"))
else:
json.dump(data, f, ensure_ascii=False, indent=2)
Expand Down
30 changes: 25 additions & 5 deletions tests/github/publish/utils/test_validate_info_from_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,31 @@ async def test_validate_info_from_issue_plugin(
assert mocked_api["homepage"].called
assert plugin_config.github_step_summary.read_text() == snapshot(
"""\
插件 project_link(1.0.0) 加载成功,运行开始
插件元数据:name='name' desc='desc' homepage='https://nonebot.dev' type='application' supported_adapters=['~onebot.v11']
插件测试输出:
require("nonebot_plugin_alconna")
test
# 📃 插件 project_link (1.0.0)

> **✅ 插件已尝试运行**
> **✅ 插件加载成功**

## 插件元数据

<pre><code>{
&#34;name&#34;: &#34;name&#34;,
&#34;desc&#34;: &#34;desc&#34;,
&#34;homepage&#34;: &#34;https://nonebot.dev&#34;,
&#34;type&#34;: &#34;application&#34;,
&#34;supported_adapters&#34;: [
&#34;~onebot.v11&#34;
]
}</code></pre>

## 插件输出

<pre><code>require(&#34;nonebot_plugin_alconna&#34;)
test</code></pre>

---

💪 Powered by [NoneFlow](https://github.com/nonebot/noneflow)
"""
)

Expand Down