修改pr评论与测试报告可读性
This commit is contained in:
@@ -87,7 +87,7 @@
|
||||
name: e2e-test-report
|
||||
path: tests/e2e/reports/
|
||||
|
||||
- name: 📊 生成 质量报告
|
||||
- name: Post PR Test Comments
|
||||
if: always() && github.event_name == 'pull_request'
|
||||
uses: actions/github-script@v6
|
||||
env:
|
||||
@@ -98,7 +98,7 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// 1. 定义基础变量(确保所有变量都已初始化)
|
||||
// 定义变量,,仓库,url等
|
||||
const testResult = process.env.TEST_RESULT || '未知';
|
||||
const isSuccess = testResult === 'success';
|
||||
const serverUrl = process.env.GITHUB_SERVER_URL;
|
||||
@@ -109,7 +109,7 @@
|
||||
const reportTypes = ['smoke', 'E2E'];
|
||||
let combinedErrorTable = "";
|
||||
|
||||
// 2. 解析函数:使用 HTML 标签代替反引号,防止语法冲突
|
||||
// 2. 解析失败日至
|
||||
const findFailures = (suites, failedSpecs) => {
|
||||
suites.forEach(suite => {
|
||||
if (suite.specs) {
|
||||
@@ -119,26 +119,18 @@
|
||||
const result = test.results[0];
|
||||
const errorObj = result?.error;
|
||||
const rawMsg = errorObj?.message || '未知错误';
|
||||
|
||||
// 提取位置
|
||||
const filePos = errorObj?.location
|
||||
? errorObj.location.file.split('/').pop() + ":" + errorObj.location.line
|
||||
: '未知位置';
|
||||
|
||||
// 提取中文日志
|
||||
const logTrace = (result.stdout || [])
|
||||
.map(i => i.text || i).join('').split('\n')
|
||||
.filter(l => l.includes('正在') || l.includes('成功'))
|
||||
.map(l => "<li>" + l.trim() + "</li>").join('');
|
||||
|
||||
// 清洗错误摘要
|
||||
const cleanSummary = rawMsg.replace(/\u001b\[\d+m/g, '').split('\n')[0];
|
||||
// 提取堆栈
|
||||
const stackTrace = errorObj?.stack
|
||||
? errorObj.stack.replace(/\u001b\[\d+m/g, '').split('\n').slice(0, 5).join('\n')
|
||||
: '无堆栈信息';
|
||||
|
||||
// 使用 HTML 拼装,避开反引号嵌套陷阱
|
||||
failedSpecs.push(
|
||||
"| " + spec.title + " | <code>" + filePos + "</code> | " + cleanSummary + " <br><details><summary>展开执行轨迹</summary><ul>" + logTrace + "</ul><pre>" + stackTrace + "</pre></details> |"
|
||||
);
|
||||
@@ -150,7 +142,7 @@
|
||||
});
|
||||
};
|
||||
|
||||
// 3. 遍历报告
|
||||
// 3. 生成测试报告
|
||||
reportTypes.forEach(type => {
|
||||
const resultsPath = path.join(process.env.GITHUB_WORKSPACE, "tests/e2e/reports/" + type + "/results.json");
|
||||
if (fs.existsSync(resultsPath)) {
|
||||
@@ -165,22 +157,22 @@
|
||||
combinedErrorTable += "\n#### ✅ " + (type === 'smoke' ? '冒烟门禁' : '功能回归') + " 测试通过\n";
|
||||
}
|
||||
} catch (e) {
|
||||
combinedErrorTable += "\n⚠️ 解析 " + type + " 报告异常: " + e.message;
|
||||
combinedErrorTable += "\n 解析 " + type + " 报告异常: " + e.message;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const summaryTitle = "🧪 DevStar 自动化测试深度报告";
|
||||
const summaryStatus = isSuccess ? "✅ 总体结论:通过" : "❌ 总体结论:失败";
|
||||
|
||||
// 这一步好像我们的devstar不支持,后续再想其他办法
|
||||
core.summary
|
||||
.addHeading(summaryTitle, 2)
|
||||
.addRaw(summaryStatus)
|
||||
.addRaw(combinedErrorTable)
|
||||
.addRaw("\n\n---\n🔍 [查看全量网页版报告](" + runUrl + ")")
|
||||
.write(); // 必须调用 write() 才会生效写到界面上
|
||||
.write();
|
||||
|
||||
const commentBody = "### 🧪 自动化测试反馈 - " + (isSuccess ? "✅ 通过" : "❌ 失败") + "\n\n" + combinedErrorTable + "\n\n---\n🔍 [查看全量网页版报告](" + runUrl + ")\n> *此评论由 CI 机器人解析 results.json 自动生成*";
|
||||
const commentBody = "### 🧪 自动化测试反馈 - " + (isSuccess ? "✅ 通过" : "❌ 失败") + "\n\n" + combinedErrorTable + "\n\n---\n🔍 [查看全量网页版报告](" + runUrl + ")\n> *此评论由Devstar Actions 机器人自动生成*";
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
issue_number: context.issue.number,
|
||||
|
||||
Reference in New Issue
Block a user