check-upstream.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435
  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. # 若自建 runner 走镜像源如 npmmirror,dist-tags 可能有分钟级同步延迟,检测会略滞后但不误报)
  16. #
  17. # npm view returns dist-tags.latest; the registry follows npm config (npmjs by default on CI, no sync delay;
  18. # self-hosted runners behind mirrors like npmmirror may see minute-level dist-tags lag — detection lags, never false-positives)
  19. LATEST="$(npm view @deepseek-ai/dsh version)"
  20. [ -n "$LATEST" ] || { echo "错误:npm view 未返回版本" >&2; exit 1; }
  21. SHOULD="$("$SCRIPT_DIR/should-upgrade.sh" "$CURRENT" "$LATEST")"
  22. # 转为布尔字符串输出:workflow 的 if 条件按 'true'/'false' 比较(此前输出 1/0 导致条件恒 false,自动升级永不触发)
  23. #
  24. # Emit a boolean string: the workflow's if conditions compare against 'true'/'false'
  25. # (previously emitting 1/0 made the conditions always false, so auto-upgrade never ran)
  26. SHOULD_BOOL=false
  27. [ "$SHOULD" = "1" ] && SHOULD_BOOL=true
  28. echo "current=$CURRENT"
  29. echo "latest=$LATEST"
  30. echo "should_upgrade=$SHOULD_BOOL"