b255fdfb4e
ci.yml 跑在自建 gitea 的 mac-pangolin-2 runner 上,该 runner 不稳:重 job (go/flutter/golden/integration/e2e)频繁整体超时/失败(run 233、236 复现:所有 runs-on=mac 的 job 全挂、runs-on=ubuntu 的 nas 快扫描全过,证明是 mac runner 掉线而非代码)。既然开发就在 mac 上、原生工具齐全,把校验迁回本地。 - 新增 ci/check-local.sh:与 ci.yml 各 job 一一对应,dev mac 原生跑(仅 golden 因 Linux 权威基线走 docker)。分档:默认=静态闸+go build/test+flutter analyze/test (各带覆盖率闸 Go30%/Flutter28%);--full 加 golden/go-integration/e2e; --only <名> 单跑;--list 列项。缺工具标 SKIP 不算失败。shellcheck-clean。 - 删 .gitea/workflows/ci.yml(部署流水线 deploy-server/client/site 保留,发版 仍过 go test)。 - .githooks/pre-commit:秒级快闸不变,指引改指 ci/check-local.sh(原指 CI)。 - CLAUDE.md CI/CD 段重写 + ds-flow 闸表「CI」触发点改「check-local」。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A79VtQA1BwTuQN1ThpvYpo
170 lines
7.6 KiB
Bash
Executable File
170 lines
7.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# ci/check-local.sh — 本地跑完整 CI 校验闸(取代已删的 .gitea/workflows/ci.yml)。
|
|
#
|
|
# 背景:CI 校验原先跑在自建 gitea 的 mac-pangolin-2 runner 上,该 runner 不稳定
|
|
# (重 job 频繁超时/整体失败)。既然开发就在 mac 上、原生工具齐全,把校验迁回本地:
|
|
# 提交前 / 发版前手动跑本脚本,取代 pipeline 上那套 ci.yml。
|
|
# 部署流水线(.gitea/workflows/deploy-*.yml,tag 触发)保留 —— 发版时仍过 go test。
|
|
#
|
|
# 用法:
|
|
# bash ci/check-local.sh # 默认档(快,原生):静态闸 + go build/test + flutter analyze/test
|
|
# bash ci/check-local.sh --full # 追加重档:golden(docker) + go integration(docker) + e2e
|
|
# bash ci/check-local.sh --only go # 只跑某一项(名字见下方 CHECK 列表,可用前缀)
|
|
# bash ci/check-local.sh --list # 列出所有检查项
|
|
#
|
|
# 各检查与 .gitea/workflows/ci.yml 的 job 一一对应;命令尽量原生(dev mac 有
|
|
# go/node/flutter/python/shellcheck),仅 golden 因 Linux 权威基线仍走 docker。
|
|
# 缺工具的检查标 SKIP(不算失败,但会在汇总里提示「未验证」)。
|
|
#
|
|
set -uo pipefail
|
|
|
|
SRC="${BASH_SOURCE[0]}"
|
|
DIR="${SRC%/*}"; [ "$DIR" = "$SRC" ] && DIR="."
|
|
cd "$DIR/.." || exit 1; REPO="$PWD"
|
|
|
|
# ── 颜色 / 汇总 ───────────────────────────────────────────────────────────
|
|
G=$'\033[0;32m'; R=$'\033[0;31m'; Y=$'\033[1;33m'; B=$'\033[1;34m'; Z=$'\033[0m'
|
|
PASS=(); FAIL=(); SKIP=()
|
|
|
|
have(){ command -v "$1" >/dev/null 2>&1; }
|
|
|
|
# run_check <名称> <命令...> —— 跑一项检查,记录结果,失败也继续(最后汇总)。
|
|
run_check(){
|
|
local name="$1"; shift
|
|
printf '%s▶ %s%s\n' "$B" "$name" "$Z"
|
|
if "$@"; then PASS+=("$name"); printf '%s ✓ %s%s\n\n' "$G" "$name" "$Z"
|
|
else FAIL+=("$name"); printf '%s ✗ %s%s\n\n' "$R" "$name" "$Z"; fi
|
|
}
|
|
skip(){ SKIP+=("$1"); printf '%s⏭ SKIP %s(%s)%s\n\n' "$Y" "$1" "$2" "$Z"; }
|
|
|
|
# ── 各检查(与 ci.yml job 对应)──────────────────────────────────────────
|
|
|
|
check_shellcheck(){
|
|
have shellcheck || { skip "shellcheck" "未装 shellcheck(brew install shellcheck)"; return 0; }
|
|
shellcheck -S warning \
|
|
deploy/bootstrap/init.sh \
|
|
deploy/bootstrap/monitor/pangolin-monitor.sh \
|
|
deploy/bootstrap/monitor/deadman-watch.sh \
|
|
deploy/single-node/deploy.sh \
|
|
scripts/ci/*.sh \
|
|
ci/*.sh
|
|
}
|
|
|
|
check_openapi(){
|
|
# 原生优先;缺模块就跳过并提示一次性安装(不走 docker+pip:每次拉镜像装包太慢)。
|
|
if have python3 && python3 -c "import openapi_spec_validator" 2>/dev/null; then
|
|
python3 -m openapi_spec_validator design/server/openapi.yaml
|
|
else
|
|
skip "openapi" "缺模块,一次性装:pip3 install openapi-spec-validator"; return 0
|
|
fi
|
|
}
|
|
|
|
check_redline(){ bash ci/scan-redline.sh; }
|
|
check_cleartext(){ bash ci/scan-cleartext.sh; }
|
|
check_portable_sql(){ bash ci/scan-portable-sql.sh; }
|
|
|
|
check_codegen_drift(){ have node || { skip "codegen-drift" "未装 node"; return 0; }; bash ci/check-codegen-drift.sh; }
|
|
|
|
check_ds_flow(){
|
|
have node || { skip "ds-flow" "未装 node"; return 0; }
|
|
node design/prototype/tools/check-ds.mjs \
|
|
&& node tools/check-l1-sync.mjs \
|
|
&& ( cd client && node tool/check_ds_code.mjs --strict )
|
|
}
|
|
|
|
check_go(){
|
|
have go || { skip "go build+test" "未装 go"; return 0; }
|
|
( cd server \
|
|
&& go build ./... \
|
|
&& go vet ./... \
|
|
&& go test -coverprofile=cover.out ./... \
|
|
&& go tool cover -func=cover.out > coverage.txt \
|
|
&& tail -1 coverage.txt \
|
|
&& awk '/^total:/{c=$3; sub(/%/,"",c); if(c+0<30){print "❌ Go 覆盖率 "c"% < 30%"; exit 1} print "✅ Go 覆盖率 "c"% ≥ 30%"}' coverage.txt )
|
|
}
|
|
|
|
check_flutter(){
|
|
have flutter || { skip "flutter analyze+test" "未装 flutter"; return 0; }
|
|
( cd client \
|
|
&& flutter pub get \
|
|
&& flutter analyze --no-fatal-infos \
|
|
&& flutter test --coverage test/unit test/widget test/contract \
|
|
&& awk -F: '/^LF:/{f+=$2} /^LH:/{h+=$2} END{c=(f>0)?h/f*100:0; if(c<28){printf "❌ flutter 覆盖率 %.1f%% < 28%%\n",c; exit 1} printf "✅ flutter 覆盖率 %.1f%% ≥ 28%%\n",c}' coverage/lcov.info )
|
|
}
|
|
|
|
# ── 重档(--full):需 docker / 更慢 ──────────────────────────────────────
|
|
check_golden(){
|
|
# Linux 权威基线(mac 原生渲染像素对不上),必须 docker Linux flutter。
|
|
have docker || { skip "golden" "未装 docker(golden 需 Linux 容器)"; return 0; }
|
|
mkdir -p "$HOME/.cache/pangolin-ci/pubcache"
|
|
docker run --rm -v "$REPO/client:/app" -w /app \
|
|
-v "$HOME/.cache/pangolin-ci/pubcache:/root/.pub-cache" \
|
|
ghcr.io/cirruslabs/flutter:stable \
|
|
bash -c "flutter pub get && flutter test test/golden"
|
|
}
|
|
|
|
check_go_integration(){
|
|
have go || { skip "go integration" "未装 go"; return 0; }
|
|
have docker || { skip "go integration" "未装 docker(testcontainers 需 docker)"; return 0; }
|
|
( cd server && go test -tags integration -count=1 -p 1 ./... )
|
|
}
|
|
|
|
check_e2e(){
|
|
have go || { skip "e2e-smoke" "未装 go"; return 0; }
|
|
bash scripts/e2e-smoke.sh
|
|
}
|
|
|
|
# 检查登记表:名字 → 档位(fast|full)。名字→函数用 case 分发(避开关联数组的
|
|
# bash4+ 依赖与 set -u subscript 求值坑)。
|
|
FAST=(shellcheck openapi redline cleartext portable-sql codegen-drift ds-flow go flutter)
|
|
FULL=(golden go-integration e2e)
|
|
dispatch(){
|
|
case "$1" in
|
|
shellcheck) check_shellcheck ;;
|
|
openapi) check_openapi ;;
|
|
redline) check_redline ;;
|
|
cleartext) check_cleartext ;;
|
|
portable-sql) check_portable_sql ;;
|
|
codegen-drift) check_codegen_drift ;;
|
|
ds-flow) check_ds_flow ;;
|
|
go) check_go ;;
|
|
flutter) check_flutter ;;
|
|
golden) check_golden ;;
|
|
go-integration) check_go_integration ;;
|
|
e2e) check_e2e ;;
|
|
*) echo "未知检查:$1"; return 2 ;;
|
|
esac
|
|
}
|
|
|
|
# ── 参数 ────────────────────────────────────────────────────────────────
|
|
MODE=fast; ONLY=""
|
|
for a in "$@"; do
|
|
case "$a" in
|
|
--full) MODE=full ;;
|
|
--fast) MODE=fast ;;
|
|
--list) printf 'fast: %s\nfull: %s\n' "${FAST[*]}" "${FULL[*]}"; exit 0 ;;
|
|
--only=*) ONLY="${a#--only=}" ;;
|
|
--only) MODE=only ;; # 兼容 `--only go`(下一个 token 当名字)
|
|
-h|--help) sed -n '2,26p' "$SRC"; exit 0 ;;
|
|
*) [ "$MODE" = only ] && ONLY="$a" ;;
|
|
esac
|
|
done
|
|
|
|
if [ -n "$ONLY" ]; then
|
|
ORDER=()
|
|
for k in "${FAST[@]}" "${FULL[@]}"; do [[ "$k" == "$ONLY"* ]] && ORDER+=("$k"); done
|
|
[ ${#ORDER[@]} -eq 0 ] && { echo "无匹配 '$ONLY';可选:${FAST[*]} ${FULL[*]}"; exit 2; }
|
|
elif [ "$MODE" = full ]; then ORDER=("${FAST[@]}" "${FULL[@]}")
|
|
else ORDER=("${FAST[@]}"); fi
|
|
|
|
printf '%s== 本地 CI 校验(%s档,%d 项)==%s\n\n' "$B" "$MODE" "${#ORDER[@]}" "$Z"
|
|
for k in "${ORDER[@]}"; do run_check "$k" dispatch "$k"; done
|
|
|
|
# ── 汇总 ────────────────────────────────────────────────────────────────
|
|
printf '%s══════ 汇总 ══════%s\n' "$B" "$Z"
|
|
printf '%s通过 %d%s | %s失败 %d%s | %s跳过 %d%s\n' "$G" "${#PASS[@]}" "$Z" "$R" "${#FAIL[@]}" "$Z" "$Y" "${#SKIP[@]}" "$Z"
|
|
[ ${#SKIP[@]} -gt 0 ] && printf '%s跳过(未验证):%s%s\n' "$Y" "${SKIP[*]}" "$Z"
|
|
if [ ${#FAIL[@]} -gt 0 ]; then printf '%s失败:%s%s\n' "$R" "${FAIL[*]}" "$Z"; exit 1; fi
|
|
printf '%s全部通过 ✓%s\n' "$G" "$Z"
|