ci: fix the failed-test retry (wildcard filter, ignore zero-test exit code, two attempts) [CI]
ci/woodpecker/push/web-build Pipeline was successful
ci/woodpecker/push/verify Pipeline was successful
ci/woodpecker/push/dev-image Pipeline was successful

This commit is contained in:
justme committed 2026-10-09 14:09:54 +08:00
1 parent b2b63c065d
commit c9c21f8056
1 file changed
+12 -6
+12 -6
View File
@@ -61,7 +61,7 @@ status=0
(cd "$src/backend" && dotnet test --solution MoShiro.slnx -c Release --no-build) 2>&1 | tee "$log" || status=${PIPESTATUS[0]}
[[ "$status" == 0 ]] && exit 0
# 个别端到端测试在机器忙的时候会偶发失败(比如探针 5 秒内没连上):失败的测试单独重跑一次,重跑通过就当通过(日志里留着第一次的失败);
# 个别端到端测试会偶发失败(比如 Hy2 阶梯测试里探针掉线):失败的测试单独重跑(最多两次),重跑通过就当通过(日志里留着第一次的失败);
# 失败太多说明是真的坏了,不重跑
mapfile -t failed < <(grep -E '^(failed|失败) ' "$log" | awk '{print $2}' | awk -F. '{print $NF}' | sort -u)
if ((${#failed[@]} == 0 || ${#failed[@]} > 3)); then
@@ -69,10 +69,16 @@ if ((${#failed[@]} == 0 || ${#failed[@]} > 3)); then
exit "$status"
fi
for name in "${failed[@]}"; do
echo "retrying $name once"
(cd "$src/backend" && dotnet test --solution MoShiro.slnx -c Release --no-build --filter-method "$name") || {
echo "$name failed again" >&2
exit 1
}
passed=false
# 最多重跑两次:这个端到端测试在 CI 主机上不稳,一次重跑不一定够
for attempt in 1 2; do
echo "retrying $name (attempt $attempt of 2)"
# 过滤要带通配符;别的程序集里没有匹配的测试,会因为「零个测试」返回 8,忽略它
if (cd "$src/backend" && dotnet test --solution MoShiro.slnx -c Release --no-build --filter-method "*$name*" --ignore-exit-code 8); then
passed=true
break
fi
done
[[ "$passed" == true ]] || { echo "$name failed again" >&2; exit 1; }
done
echo "the failed tests passed on retry"