Skip to content

Commit 1e6ccec

Browse files
authored
fix(ci): 修复CI流程中测试失败但返回成功状态的问题 (#1403)
- 移除syscall测试的continue-on-error配置,确保测试失败时CI流程正确失败 - 优化上传步骤的条件判断,使用always()确保上传步骤始终执行 - 改进dry-run模式输出,添加verbose选项显示详细信息 - 修复API密钥检查逻辑,在密钥不存在时使用dry-run模式继续执行 Signed-off-by: longjin <[email protected]>
1 parent b99a544 commit 1e6ccec

File tree

2 files changed

+77
-47
lines changed

2 files changed

+77
-47
lines changed

.github/workflows/test-x86.yml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ jobs:
3232
make -j$(nproc) all
3333
3434
- name: Run syscall test
35+
id: test-syscall
3536
shell: bash -ileo pipefail {0}
36-
continue-on-error: true
3737
env:
3838
DISK_SAVE_MODE: "1"
3939
run: |
4040
make test-syscall
4141
4242
- name: Upload test results
43-
if: github.repository == 'DragonOS-Community/DragonOS'
43+
if: always() && github.repository == 'DragonOS-Community/DragonOS'
4444
shell: bash -ileo pipefail {0}
4545
env:
4646
API_KEY: ${{ secrets.CI_DASHBOARD_UPLOAD_API_KEY }}
@@ -69,22 +69,28 @@ jobs:
6969
BRANCH_NAME="${{ github.head_ref }}"
7070
fi
7171
72-
# 检查API_KEY是否存在
73-
if [ -z "$API_KEY" ]; then
74-
echo "警告: CI_DASHBOARD_UPLOAD_API_KEY secret未设置,跳过上传"
75-
exit 0
76-
fi
77-
7872
# 检查日志文件是否存在
7973
if [ ! -f "serial_opt.txt" ]; then
8074
echo "警告: serial_opt.txt文件不存在,跳过上传"
8175
exit 0
8276
fi
8377
84-
# 上传测试结果
85-
python3 tools/test-upload/parse_and_upload.py \
86-
serial_opt.txt \
87-
"$API_URL" \
88-
--branch "$BRANCH_NAME" \
89-
--commit "$COMMIT_ID" \
90-
--test-type "gvisor"
78+
# 检查API_KEY是否存在,如果不存在则使用dry-run模式
79+
if [ -z "$API_KEY" ]; then
80+
echo "警告: CI_DASHBOARD_UPLOAD_API_KEY secret未设置,使用dry-run模式"
81+
python3 tools/test-upload/parse_and_upload.py \
82+
serial_opt.txt \
83+
"$API_URL" \
84+
--branch "$BRANCH_NAME" \
85+
--commit "$COMMIT_ID" \
86+
--test-type "gvisor" \
87+
--dry-run
88+
else
89+
# 上传测试结果
90+
python3 tools/test-upload/parse_and_upload.py \
91+
serial_opt.txt \
92+
"$API_URL" \
93+
--branch "$BRANCH_NAME" \
94+
--commit "$COMMIT_ID" \
95+
--test-type "gvisor"
96+
fi

tools/test-upload/parse_and_upload.py

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
解析 serial_opt.txt 日志文件并上报测试结果到后端API
44
55
用法:
6-
python parse_and_upload.py <log_file> <api_url> --branch <branch_name> --commit <commit_id> [--test-type <test_type>] [--dry-run]
6+
python parse_and_upload.py <log_file> <api_url> --branch <branch_name> --commit <commit_id> [--test-type <test_type>] [--dry-run] [--verbose]
77
88
环境变量:
99
API_KEY: 后端API的认证密钥(非dry-run模式需要)
@@ -13,8 +13,11 @@
1313
export API_KEY=your_api_key_here
1414
python parse_and_upload.py serial_opt.txt http://localhost:8080/api/v1 --branch main --commit abc123def456
1515
16-
# Dry-run模式(调试用,不需要API_KEY)
16+
# Dry-run模式(默认只显示统计信息,不需要API_KEY)
1717
python parse_and_upload.py serial_opt.txt http://localhost:8080/api/v1 --branch main --commit abc123def456 --dry-run
18+
19+
# Dry-run模式(显示完整详细信息,包括测试用例详情和JSON数据)
20+
python parse_and_upload.py serial_opt.txt http://localhost:8080/api/v1 --branch main --commit abc123def456 --dry-run --verbose
1821
"""
1922

2023
import os
@@ -572,6 +575,14 @@ def main():
572575
help='干运行模式:只解析并显示结果,不上传到服务器'
573576
)
574577

578+
parser.add_argument(
579+
'--verbose',
580+
'--full-output',
581+
dest='verbose',
582+
action='store_true',
583+
help='详细输出模式:在dry-run模式下显示完整的测试用例详情和JSON数据(默认只显示统计信息)'
584+
)
585+
575586
args = parser.parse_args()
576587

577588
# 在dry-run模式下,不需要API Key
@@ -600,27 +611,19 @@ def main():
600611
print("警告: 未找到任何测试用例", file=sys.stderr)
601612
sys.exit(1)
602613

603-
print(f"✓ 找到 {len(test_cases)} 个测试用例")
604-
605-
# 显示解析结果摘要
614+
# 统计测试用例状态
606615
status_count = {}
607616
for tc in test_cases:
608617
status = tc.get('status', 'unknown')
609618
status_count[status] = status_count.get(status, 0) + 1
610619

611-
print("\n测试用例状态统计:")
612-
for status, count in sorted(status_count.items()):
613-
print(f" {status}: {count}")
614-
615620
# 根据测试用例状态确定整体状态
616621
overall_status = "passed"
617622
for tc in test_cases:
618623
if tc.get('status') == 'failed':
619624
overall_status = "failed"
620625
break
621626

622-
print(f"\n整体状态: {overall_status}")
623-
624627
# 构建将要上传的payload
625628
payload = {
626629
"branch_name": args.branch_name,
@@ -630,31 +633,52 @@ def main():
630633
"test_cases": test_cases
631634
}
632635

633-
# 在dry-run模式下,显示详细信息
636+
# 在dry-run模式下,显示信息
634637
if args.dry_run:
635-
# 显示测试用例详情
636-
print_test_cases_details(test_cases)
637-
638-
# 显示将要上传的JSON
639-
print("\n" + "="*80)
640-
print("将要上传的JSON数据:")
641-
print("="*80)
642-
print(json.dumps(payload, indent=2, ensure_ascii=False))
643-
644-
# 显示API信息
645-
if not args.api_url.endswith('/test-runs'):
646-
if args.api_url.endswith('/'):
647-
url = f"{args.api_url}test-runs"
638+
# 非verbose模式:只显示简洁的统计信息
639+
if not args.verbose:
640+
passed_count = status_count.get('passed', 0)
641+
failed_count = status_count.get('failed', 0)
642+
skipped_count = status_count.get('skipped', 0)
643+
print(f"测试通过 {passed_count} 个,失败 {failed_count} 个", end="")
644+
if skipped_count > 0:
645+
print(f",跳过 {skipped_count} 个")
648646
else:
649-
url = f"{args.api_url}/test-runs"
647+
print()
650648
else:
651-
url = args.api_url
649+
# verbose模式:显示详细信息
650+
print(f"✓ 找到 {len(test_cases)} 个测试用例")
651+
652+
print("\n测试用例状态统计:")
653+
for status, count in sorted(status_count.items()):
654+
print(f" {status}: {count}")
655+
656+
print(f"\n整体状态: {overall_status}")
657+
658+
# 显示测试用例详情
659+
print_test_cases_details(test_cases)
660+
661+
# 显示将要上传的JSON
662+
print("\n" + "="*80)
663+
print("将要上传的JSON数据:")
664+
print("="*80)
665+
print(json.dumps(payload, indent=2, ensure_ascii=False))
666+
667+
# 显示API信息
668+
if not args.api_url.endswith('/test-runs'):
669+
if args.api_url.endswith('/'):
670+
url = f"{args.api_url}test-runs"
671+
else:
672+
url = f"{args.api_url}/test-runs"
673+
else:
674+
url = args.api_url
675+
676+
print("\n" + "="*80)
677+
print(f"目标API地址: {url}")
678+
print(f"请求方法: POST")
679+
print(f"Content-Type: application/json")
680+
print("="*80)
652681

653-
print("\n" + "="*80)
654-
print(f"目标API地址: {url}")
655-
print(f"请求方法: POST")
656-
print(f"Content-Type: application/json")
657-
print("="*80)
658682
print("\n✓ Dry-run 完成,未实际上传数据")
659683
return
660684

0 commit comments

Comments
 (0)