upgrade-dsh.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env bash
  2. # 升级脚本:将仓库中 dsh 上游版本号提升到指定版本
  3. # 更新范围:Dockerfile(ARG + 注释示例)、docker-compose.yml(默认值)、README.md / README.zh.md(示例与变量表)
  4. # DESIGN.md 为历史设计稿,不在自动升级范围(差异由 §10 实现差异记录人工维护)
  5. #
  6. # Upgrade script: bump the dsh upstream version in the repo to the given version
  7. # Updated files: Dockerfile (ARG + comment example), docker-compose.yml (default), README.md / README.zh.md (examples and variable tables)
  8. # DESIGN.md is a historical design doc, out of scope for auto-upgrade (differences are maintained manually in §10)
  9. # Usage: upgrade-dsh.sh <new-version> [repo-dir](默认当前目录)
  10. set -euo pipefail
  11. NEW="$1"
  12. DIR="${2:-.}"
  13. # 从 Dockerfile 提取当前版本(仅带值的 ARG 声明行)
  14. #
  15. # Extract the current version from the Dockerfile (only the ARG line with a value)
  16. OLD="$(grep -E '^ARG DSH_VERSION=' "$DIR/Dockerfile" | head -n1 | cut -d= -f2)"
  17. [ -n "$OLD" ] || { echo "错误:未能在 Dockerfile 找到 ARG DSH_VERSION" >&2; exit 1; }
  18. [ "$NEW" != "$OLD" ] || { echo "新版本与当前版本相同($NEW),无需升级" >&2; exit 0; }
  19. FILES=(Dockerfile docker-compose.yml README.md README.zh.md)
  20. for f in "${FILES[@]}"; do
  21. [ -f "$DIR/$f" ] || { echo "错误:缺少 $f" >&2; exit 1; }
  22. # npm 版本号仅含 [0-9a-zA-Z.-],无 sed 特殊字符,可安全作替换串
  23. #
  24. # npm versions only contain [0-9a-zA-Z.-], no sed metacharacters, safe as a replacement string
  25. sed -i "s/${OLD}/${NEW}/g" "$DIR/$f"
  26. done
  27. # 原子验证:旧版本号必须全部消失,新版本号已写入
  28. #
  29. # Atomic verification: the old version must be fully gone and the new version written
  30. LEFT="$(grep -l "$OLD" "$DIR"/Dockerfile "$DIR"/docker-compose.yml "$DIR"/README.md "$DIR"/README.zh.md 2>/dev/null || true)"
  31. [ -z "$LEFT" ] || { echo "错误:旧版本仍残留于 $LEFT" >&2; exit 1; }
  32. grep -q "$NEW" "$DIR/Dockerfile" || { echo "错误:新版本未写入" >&2; exit 1; }
  33. echo "已升级:$OLD → $NEW(Dockerfile / docker-compose.yml / README.md / README.zh.md)"