#!/bin/bash # 预发布全端验收(Phase 4 T4):staging 起本地服务后跑渲染/OG/微信UA/响应式/生产五面断言 # 退出码非零 = 有 FAIL;每项独立可读。c4ai 部分依赖本机 crawl4ai 容器(headless Chromium)。 set -u cd "$(dirname "$0")/.." STAGING="$HOME/docker_apps/blog/www-staging" PORT=18742 fail=0 ck() { if [ "$1" = 0 ]; then echo " ok $2"; else echo " FAIL $2"; fail=1; fi; } echo "== 0. staging 本地服务 ==" if ! curl -sf "http://127.0.0.1:$PORT/" -o /dev/null; then (cd "$STAGING" && python3 -m http.server $PORT >/dev/null 2>&1 &) sleep 1 fi curl -sf "http://127.0.0.1:$PORT/" -o /dev/null; ck $? "staging HTTP 服务 ($PORT)" echo "== 1. OG/HTML 静态断言(zh/en 首页 + 一篇书评 + 一篇技术) ==" for f in index.html en/index.html archives/mian-sha/index.html en/archives/csge-lei-pei-zhi/index.html; do test -f "$STAGING/$f"; ck $? "产物存在 $f" done grep -q 'name="description"' "$STAGING/index.html"; ck $? "meta description" grep -q 'hreflang="en"' "$STAGING/index.html" && grep -q 'hreflang="zh"' "$STAGING/en/index.html"; ck $? "hreflang 双向" grep -q 'prose-reading' "$STAGING/archives/mian-sha/index.html"; ck $? "书评衬线轨" grep -q 'prose-tech\|toc' "$STAGING/en/archives/csge-lei-pei-zhi/index.html"; ck $? "技术轨/TOC" echo "== 2. 微信内置浏览器 UA 模拟 ==" WM=$(curl -sf -A "Mozilla/5.0 (Linux; Android 14) AppleWebKit/537.36 MicroMessenger/8.0.49" \ "http://127.0.0.1:$PORT/archives/mian-sha/index.html" -o /dev/null -w '%{http_code}') [ "$WM" = "200" ]; ck $? "MicroMessenger UA 抓取 200(实际 $WM)" echo "== 3. 响应式结构断言 ==" bash scripts/check-responsive.sh >/dev/null 2>&1; ck $? "check-responsive 11 项" echo "== 4. 生产 Halo 无恙 ==" curl -sf http://127.0.0.1:18090 -o /dev/null; ck $? "halo 18090 响应" docker inspect -f '{{.State.Health.Status}}' halo-halo-1 | grep -q healthy; ck $? "halo healthy" echo "== 5. 回滚前置 ==" bash infra/deploy/rollback-dryrun.sh >/dev/null 2>&1; ck $? "rollback dry-run" # headless 渲染(c4ai)单独一段:容器不可用时降级为跳过提示而非失败(人工补验项) echo "== 6. headless 渲染(c4ai,可选面) ==" if timeout 60 curl -sf http://127.0.0.1:11235/ -o /dev/null 2>/dev/null; then echo " (crawl4ai 在线——渲染断言由 orchestrator 会话内执行,见验收记录)" else echo " skip: crawl4ai 容器不可达(人工补验:浏览器开 staging 抽查)" fi [ "$fail" = 0 ] && echo "preflight: ALL OK" || echo "preflight: FAILURES above" exit $fail