check-upstream.sh 1.1 KB

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env bash
  2. # 检查 dsh 上游版本,输出 current / latest / should_upgrade(GITHUB_OUTPUT 兼容格式)
  3. #
  4. # Check the dsh upstream version; outputs current / latest / should_upgrade (GITHUB_OUTPUT-compatible)
  5. # Usage: check-upstream.sh [repo-dir](默认当前目录)
  6. set -euo pipefail
  7. DIR="${1:-.}"
  8. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  9. # 从 Dockerfile 提取当前版本(仅带值的 ARG 声明行)
  10. #
  11. # Extract the current version from the Dockerfile (only the ARG line with a value)
  12. CURRENT="$(grep -E '^ARG DSH_VERSION=' "$DIR/Dockerfile" | head -n1 | cut -d= -f2)"
  13. [ -n "$CURRENT" ] || { echo "错误:未能在 Dockerfile 找到 ARG DSH_VERSION" >&2; exit 1; }
  14. # npm view 返回 dist-tags.latest;registry 由 npm 配置决定(CI 默认 npmjs)
  15. #
  16. # npm view returns dist-tags.latest; the registry follows npm config (npmjs by default on CI)
  17. LATEST="$(npm view @deepseek-ai/dsh version)"
  18. [ -n "$LATEST" ] || { echo "错误:npm view 未返回版本" >&2; exit 1; }
  19. SHOULD="$("$SCRIPT_DIR/should-upgrade.sh" "$CURRENT" "$LATEST")"
  20. echo "current=$CURRENT"
  21. echo "latest=$LATEST"
  22. echo "should_upgrade=$SHOULD"