ci:log-report.sh

This commit is contained in:
2026-04-17 15:24:50 +08:00
parent d1026583f9
commit 44dcfde756
3 changed files with 46 additions and 1 deletions

43
.github/workflows/scripts/log-report.sh vendored Normal file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
# 1. 定义根目录路径 (请根据实际情况修改)
ROOT_DIR="${1:-$(pwd)/logs}"
# 2. 检查目录是否存在
if [ ! -d "$ROOT_DIR" ]; then
echo "错误: 目录 $ROOT_DIR 不存在"
exit 1
fi
echo "正在分析目录: $ROOT_DIR"
echo "----------------------------------------"
# 3. 遍历根目录下的所有一级子目录
# 使用 -mindepth 1 -maxdepth 1 确保只遍历第一层子目录
# 使用 -type d 确保只处理目录
for subdir in "$ROOT_DIR"/*/; do
# 如果没有子目录,循环可能会直接跳过,这里做一个安全检查
[ -d "$subdir" ] || continue
# 4. 查找该子目录下最大的 .log 文件
# ls -1 列出文件
# sort 按名称排序 (因为你要的是"按名称排序最大",即字母顺序最后)
# tail -n 1 取最后一行,即最大的那个
max_log_file=$(ls -1 "$subdir"*.log 2>/dev/null | sort | tail -n 1)
# 5. 检查是否找到了 log 文件
if [ -n "$max_log_file" ] && [ -f "$max_log_file" ]; then
echo ">>> 正在分析文件: $max_log_file"
# 6. 使用 grep 获取 warn 和 error 信息及其前后 5 行
# -i : 忽略大小写 (匹配 Warn, WARN, warn)
# -E : 使用扩展正则表达式 (匹配 warn 或 error)
# -C 5 : 显示匹配行的前后 5 行 (Context)
# --color=auto : 高亮显示关键词 (可选,方便查看)
grep -n -E -C 5 --color=auto "Failed |Error:" "$max_log_file" | sed 's/^--$/----------------------------------------/'
echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
else
echo ">>> 在 $subdir 中未找到 .log 文件"
fi
done

View File

@@ -73,7 +73,7 @@ def get_os_autotest_testsuite_result_data(testsuite):
log.warning(f"{case_name}.sh not found in {script_dir}")
continue
if case_name not in all_cases:
if testsuite == "smoke_pkg_install" and "case_name" == "test_pkg_install_uninstall":
if testsuite == "smoke_pkg_install" and case_name == "test_pkg_install_uninstall":
continue
temp = [testsuite, case_name, "not run or exception in running, please run manual"]
data.append(temp)

View File

@@ -32,6 +32,8 @@ jobs:
exit 0
fi
bash .github/workflows/scripts/log-report.sh "${RESULT_DIR}/logs"
python .github/workflows/scripts/summary.py --testsuits ".os-autotest/testsuite" --result "${RESULT_DIR}" --source "${RESULT_DIR}/source"
sshpass -p "${{ secrets.IMAGE_BACKUP_HOST_PWD }}" rsync -av -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" "${RESULT_DIR}" "${{ secrets.IMAGE_BACKUP_HOST_USER }}@${{ secrets.IMAGE_BACKUP_HOST }}:${{ secrets.IMAGE_BACKUP_DIR }}"
TITLE="os-autotest"