Files
zszq-trs/YLErpWeb/fe-tests/run-ci-checks.sh
T

97 lines
3.6 KiB
Bash
Executable File
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.
#!/usr/bin/env bash
# =============================================================================
# run-ci-checks.sh — CI 守卫入口脚本
# =============================================================================
# Jenkins / GitLab CI / GitHub Actions 等任一 CI 系统调用本脚本即可。
#
# 做三件事(任一失败即 exit 1,阻断 CI):
# 1. guard_arch.js — 架构闸门:禁止新增内联金额计算
# 2. jest — 前端单测:防止回归
# 3. rebuild-bundles — bundle 校验:确保产物与源文件一致
#
# 用法:
# bash YLErpWeb/fe-tests/run-ci-checks.sh
#
# 前置条件:
# - Node.js 18+ 已安装(CI 环境通常自带)
# - cd YLErpWeb/fe-tests && npm install 已执行
# =============================================================================
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
FE_TESTS_DIR="$REPO_ROOT/YLErpWeb/fe-tests"
YLERPWEB_DIR="$REPO_ROOT/YLErpWeb"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
FAILED=0
run_check() {
local name="$1"
local cmd="$2"
echo -e "\n${YELLOW}========================================${NC}"
echo -e "${YELLOW}CI Check: ${name}${NC}"
echo -e "${YELLOW}========================================${NC}"
if eval "$cmd"; then
echo -e "${GREEN}${name} PASSED${NC}"
else
echo -e "${RED}${name} FAILED${NC}"
FAILED=$((FAILED + 1))
fi
}
# -----------------------------------------------------------------------------
# Check 1: 架构闸门
# -----------------------------------------------------------------------------
if command -v node &>/dev/null; then
run_check "guard_arch.js (架构闸门)" \
"node '$FE_TESTS_DIR/guard_arch.js'"
else
echo -e "${YELLOW}⚠️ node 未安装,跳过架构闸门${NC}"
fi
# -----------------------------------------------------------------------------
# Check 2: 前端单测
# -----------------------------------------------------------------------------
if [ -f "$FE_TESTS_DIR/node_modules/.bin/jest" ]; then
run_check "jest (前端单测)" \
"cd '$FE_TESTS_DIR' && npx jest --no-coverage --silent"
else
echo -e "${YELLOW}⚠️ jest 未安装,尝试自动安装...${NC}"
if command -v npm &>/dev/null; then
(cd "$FE_TESTS_DIR" && npm install --silent)
run_check "jest (前端单测)" \
"cd '$FE_TESTS_DIR' && npx jest --no-coverage --silent"
else
echo -e "${RED}❌ npm 不可用,无法运行前端单测${NC}"
FAILED=$((FAILED + 1))
fi
fi
# -----------------------------------------------------------------------------
# Check 3: Bundle 校验(可选,需要 python3
# -----------------------------------------------------------------------------
if [ -f "$YLERPWEB_DIR/rebuild-bundles.py" ] && command -v python3 &>/dev/null; then
run_check "bundle 校验 (rebuild-bundles.py --verify)" \
"cd '$YLERPWEB_DIR' && python3 rebuild-bundles.py --verify"
else
echo -e "${YELLOW}⚠️ python3 或 rebuild-bundles.py 不可用,跳过 bundle 校验${NC}"
fi
# -----------------------------------------------------------------------------
# 汇总
# -----------------------------------------------------------------------------
echo -e "\n${YELLOW}========================================${NC}"
echo -e "${YELLOW}CI Checks Summary${NC}"
echo -e "${YELLOW}========================================${NC}"
if [ "$FAILED" -eq 0 ]; then
echo -e "${GREEN}✅ All checks passed${NC}"
exit 0
else
echo -e "${RED}${FAILED} check(s) failed${NC}"
exit 1
fi