check-upstream.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233
  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. # 转为布尔字符串输出:workflow 的 if 条件按 'true'/'false' 比较(此前输出 1/0 导致条件恒 false,自动升级永不触发)
  21. #
  22. # Emit a boolean string: the workflow's if conditions compare against 'true'/'false'
  23. # (previously emitting 1/0 made the conditions always false, so auto-upgrade never ran)
  24. SHOULD_BOOL=false
  25. [ "$SHOULD" = "1" ] && SHOULD_BOOL=true
  26. echo "current=$CURRENT"
  27. echo "latest=$LATEST"
  28. echo "should_upgrade=$SHOULD_BOOL"