play.wenpai.net/scripts/play-upgrade-wp
elementary-qa 1310c0d718 chore: add play-upgrade-wp batch version update script
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-12 17:24:39 +08:00

77 lines
2.1 KiB
Bash
Executable file
Raw Permalink 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
# play-upgrade-wp — 一键升级 play.wenpai.net 所有 blueprint 的 WordPress 版本
# 用法: play-upgrade-wp <version>
# play-upgrade-wp 6.9 # 锁定到 6.9
# play-upgrade-wp latest # 恢复为 latest
#
# 注意: Playground 引擎只支持大版本号 (6.3/6.9/latest/nightly)
# 不支持 6.9.4 这样的小版本号
set -euo pipefail
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
info() { echo -e "${GREEN}[✓]${NC} $*"; }
warn() { echo -e "${YELLOW}[!]${NC} $*"; }
fail() { echo -e "${RED}[✗]${NC} $*"; exit 1; }
PLAY_DIR="$HOME/play"
BP_DIR="$PLAY_DIR/blueprints"
SKIP_PATTERN="wp70-beta" # nightly 不动
# ── 参数检查 ──
if [ $# -lt 1 ]; then
echo "用法: play-upgrade-wp <version>"
echo " 例: play-upgrade-wp 6.9"
echo " 例: play-upgrade-wp latest"
exit 1
fi
NEW_VER="$1"
# ── 校验版本格式 ──
if [[ "$NEW_VER" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
fail "不支持小版本号 ($NEW_VER)。Playground 只认大版本,如 6.9 或 latest"
fi
if [[ ! "$NEW_VER" =~ ^([0-9]+\.[0-9]+|latest|nightly)$ ]]; then
fail "无效版本: $NEW_VER(应为 6.9 / latest / nightly"
fi
# ── 查找需要修改的文件 ──
changed=0
for f in "$BP_DIR"/*.json; do
name=$(basename "$f" .json)
[[ "$name" == *"$SKIP_PATTERN"* ]] && continue
current=$(grep -oP '"wp":\s*"\K[^"]+' "$f" 2>/dev/null || echo "unknown")
if [ "$current" = "$NEW_VER" ]; then
continue
fi
sed -i "s/\"wp\": \"$current\"/\"wp\": \"$NEW_VER\"/" "$f"
info "$name: $current$NEW_VER"
((changed++))
done
if [ "$changed" -eq 0 ]; then
warn "所有 blueprint 已经是 $NEW_VER,无需修改"
exit 0
fi
info "已修改 $changed 个 blueprint"
# ── Git 提交 + 推送 ──
cd "$PLAY_DIR/.." # git root
git add play/blueprints/
git commit -m "chore: upgrade WordPress to $NEW_VER across $changed blueprints"
git pull --rebase origin main 2>/dev/null || true
git push origin main
info "已推送到远程"
# ── 部署 ──
bash ~/scripts/play-deploy deploy
info "已部署到生产"
# ── 冒烟测试 ──
echo ""
play-smoke --all