纳入管理: Justfile(30+任务), 5个Playwright脚本, BackstopJS配置, Blueprint(中/英), 报告生成器, staging监控, pa11y配置 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
79 lines
2.4 KiB
Bash
Executable file
79 lines
2.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
||
# staging watcher — 监控 NAS staging 目录,检测到新 zip 自动跑验收
|
||
# 用法: ./scripts/staging-watcher.sh [--once]
|
||
# --once: 只检查一次(适合 cron),不加则持续轮询
|
||
|
||
set -uo pipefail
|
||
|
||
STAGING="/mnt/shared-context/staging/elementary"
|
||
RESULTS_OUT="/mnt/shared-context/staging/fedora-devops/test-results"
|
||
LOCAL_RESULTS="$HOME/test-results"
|
||
PROCESSED="$STAGING/.processed"
|
||
INTERVAL=30
|
||
|
||
mkdir -p "$STAGING" "$RESULTS_OUT" "$PROCESSED"
|
||
|
||
check_and_run() {
|
||
for zip in "$STAGING"/*.zip; do
|
||
[ -f "$zip" ] || continue
|
||
name=$(basename "$zip" .zip)
|
||
marker="$PROCESSED/$name.done"
|
||
|
||
# 跳过已处理的
|
||
if [ -f "$marker" ] && [ "$marker" -nt "$zip" ]; then
|
||
continue
|
||
fi
|
||
|
||
echo "[watcher] 发现新插件: $name"
|
||
date_str=$(date +%Y-%m-%d)
|
||
result_dir="$LOCAL_RESULTS/$date_str/$name"
|
||
|
||
# 确保 Playground 在跑
|
||
if ! ss -tlnp | grep -q ':9400'; then
|
||
echo "[watcher] 启动 Playground..."
|
||
npx @wp-playground/cli@3.0.52 server --port=9400 --login \
|
||
--blueprint="$HOME/blueprints/zh-cn-base.json" &
|
||
sleep 10
|
||
fi
|
||
|
||
# 检查是否有配套 Blueprint
|
||
bp="$STAGING/${name}.blueprint.json"
|
||
if [ -f "$bp" ]; then
|
||
echo "[watcher] 使用自定义 Blueprint: $bp"
|
||
# 重启 Playground 用自定义 Blueprint
|
||
pkill -f "@wp-playground/cli" 2>/dev/null || true
|
||
sleep 2
|
||
npx @wp-playground/cli@3.0.52 server --port=9400 --login \
|
||
--blueprint="$bp" &
|
||
sleep 10
|
||
fi
|
||
|
||
# 安装插件
|
||
echo "[watcher] 安装插件..."
|
||
node "$HOME/scripts/playwright/plugin-install.js" "$zip" "http://localhost:9400" || true
|
||
|
||
# 跑完整验收
|
||
echo "[watcher] 开始验收..."
|
||
just test-plugin "$name" || true
|
||
|
||
# 复制结果到 NAS
|
||
if [ -d "$result_dir" ]; then
|
||
cp -r "$result_dir" "$RESULTS_OUT/"
|
||
echo "[watcher] 结果已复制到 $RESULTS_OUT/$name/"
|
||
fi
|
||
|
||
# 标记已处理
|
||
date > "$marker"
|
||
echo "[watcher] $name 验收完成"
|
||
done
|
||
}
|
||
|
||
if [ "${1:-}" = "--once" ]; then
|
||
check_and_run
|
||
else
|
||
echo "[watcher] 监控 $STAGING (每 ${INTERVAL}s 轮询)"
|
||
while true; do
|
||
check_and_run
|
||
sleep "$INTERVAL"
|
||
done
|
||
fi
|