common-workflows/actions/frontend-test/action.yml
2025-12-19 10:38:41 +00:00

57 lines
1.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: 'Reusable Frontend Availability Test'
description: '通用的前端首页可访问性检查逻辑,可在各仓库中复用,支持传入完整 URL'
inputs:
urls:
description: '要检查的前端 URL 列表,每行一个完整 URL例如 http://127.0.0.1:5373 或 https://frontend-service'
required: true
runs:
using: 'composite'
steps:
- name: Check frontend
shell: bash
env:
URLS: ${{ inputs.urls }}
run: |
echo "====== 开始检查前端首页可访问性 ======"
frontend_failed=0
# 按行读取 URL每行是一个完整的前端访问地址
while IFS= read -r url; do
# 跳过空行
if [ -z "$url" ]; then
continue
fi
echo ""
echo "------ 检查前端 ${url} ------"
success=0
for i in {1..10}; do
if curl -fsS "${url}" > /dev/null; then
echo "✓ 前端首页可访问: ${url}"
success=1
break
fi
echo "第 ${i} 次重试,等待 5 秒..."
sleep 5
done
if [ "${success}" -ne 1 ]; then
echo "✗ 前端首页访问失败: ${url}"
frontend_failed=1
fi
done <<< "$URLS"
if [ "${frontend_failed}" -ne 0 ]; then
echo ""
echo "✗ 前端检查存在失败,详见上方日志"
exit 1
fi
echo ""
echo "✓ 所有前端检查通过"