fix:调整出现Could not find的问题,显式指定

This commit is contained in:
liyi 2025-05-16 18:18:10 +08:00
parent 84b821b6eb
commit 5ddfbe46d1
3 changed files with 130 additions and 2 deletions

View File

@ -76,7 +76,7 @@ variables:
- bundle -v || gem install bundler --source https://gems.ruby-china.com/
- ls -li
- export NEXT_VERSION="$(cat app_new.version)"
- bash scripts/bundle_install_retry.sh android/Gemfile vendor/bundle_android
- bash scripts/bundle_install_and_auto_add.sh android/Gemfile vendor/bundle_android "bundle exec fastlane -v"
- gem pristine --all || true # 修复所有未编译的gem扩展
script:
# 输出调试信息,便于后续排查环境问题
@ -107,7 +107,7 @@ variables:
- bundle -v || gem install bundler --source https://gems.ruby-china.com/
- ls -li
- export NEXT_VERSION="$(cat app_new.version)"
- bash scripts/bundle_install_retry.sh ios/Gemfile vendor/bundle_ios
- bash scripts/bundle_install_and_auto_add.sh ios/Gemfile vendor/bundle_ios "bundle exec fastlane -v"
- gem pristine --all || true # 修复所有未编译的gem扩展
script:
# 输出调试信息,便于后续排查环境问题

View File

@ -0,0 +1,79 @@
#!/bin/bash
# 用法: bash scripts/bundle_install_and_auto_add.sh <gemfile_path> <bundle_path> <main_cmd>
# 例如: bash scripts/bundle_install_and_auto_add.sh ios/Gemfile vendor/bundle_ios "bundle exec fastlane -v"
GEMFILE_PATH="$1"
BUNDLE_PATH="$2"
MAIN_CMD="$3"
if [ -z "$GEMFILE_PATH" ] || [ -z "$BUNDLE_PATH" ] || [ -z "$MAIN_CMD" ]; then
echo "用法: $0 <gemfile_path> <bundle_path> <main_cmd>"
exit 1
fi
max_auto_add=3
add_count=0
success=0
# 1. 检查并自动补全Gemfile缺失依赖
while [ $add_count -lt $max_auto_add ]; do
echo "[INFO] 第$((add_count+1))次尝试运行主命令: $MAIN_CMD (仅捕获缺失gem)"
$MAIN_CMD > bundle_missing_gem.log 2>&1 && success=1 && break
missing_gem=$(grep -o "Could not find [^ ]*" bundle_missing_gem.log | awk '{print $4}' | head -n1)
if [ -n "$missing_gem" ]; then
if ! grep -q "gem '$missing_gem'" "$GEMFILE_PATH"; then
echo "gem '$missing_gem'" >> "$GEMFILE_PATH"
echo "[AUTO] Gemfile已自动补全: $missing_gem"
else
echo "[WARN] Gemfile已包含 $missing_gem,但依然缺失,可能是平台或缓存问题"
fi
else
echo "[INFO] 未检测到缺失gem或主命令已成功。"
break
fi
add_count=$((add_count+1))
sleep 2
echo "[WARN] 第$add_count 次自动补全后重试..."
done
if [ $success -eq 1 ]; then
echo "[SUCCESS] 所有依赖已补全,主命令执行成功。"
exit 0
fi
# 2. 统一执行镜像切换和重试的bundle install
try_count=0
max_try=3
success=0
bundle config mirror.https://rubygems.org https://mirrors.aliyun.com/rubygems/
while [ $try_count -lt $max_try ]; do
echo "[INFO] 第$((try_count+1))次尝试使用阿里云镜像 bundle install..."
bundle config set --local path "$BUNDLE_PATH"
bundle install --gemfile "$GEMFILE_PATH"
if [ $? -eq 0 ]; then
echo "[SUCCESS] 使用阿里云镜像 bundle install 成功"
success=1
break
fi
try_count=$((try_count+1))
sleep 2
echo "[WARN] 阿里云镜像 bundle install 第$try_count 次失败,准备重试..."
done
if [ $success -eq 0 ]; then
echo "[ERROR] 阿里云镜像 bundle install 失败$max_try次,切换为官方源重试..."
bundle config mirror.https://rubygems.org https://rubygems.org
bundle config set --local path "$BUNDLE_PATH"
bundle install --gemfile "$GEMFILE_PATH"
if [ $? -eq 0 ]; then
echo "[SUCCESS] 官方源 bundle install 成功"
else
echo "[FATAL] 官方源 bundle install 依然失败请检查网络或Gemfile配置。"
exit 2
fi
fi
# 3. 最后再执行一次主命令校验
$MAIN_CMD || { echo "[FATAL] 主命令依然失败请人工检查Gemfile和依赖环境。"; exit 3; }
echo "[SUCCESS] 所有依赖已补全,主命令执行成功。"
exit 0

View File

@ -0,0 +1,49 @@
#!/bin/bash
# 用法: bash scripts/bundle_missing_gem_auto_add.sh <gemfile_path> <bundle_path> <main_cmd>
# 例如: bash scripts/bundle_missing_gem_auto_add.sh ios/Gemfile vendor/bundle_ios "bundle exec fastlane -v"
GEMFILE_PATH="$1"
BUNDLE_PATH="$2"
MAIN_CMD="$3"
if [ -z "$GEMFILE_PATH" ] || [ -z "$BUNDLE_PATH" ] || [ -z "$MAIN_CMD" ]; then
echo "用法: $0 <gemfile_path> <bundle_path> <main_cmd>"
exit 1
fi
max_try=3
try_count=0
success=0
bundle check --path "$BUNDLE_PATH" || bundle install --gemfile "$GEMFILE_PATH" --path "$BUNDLE_PATH"
while [ $try_count -lt $max_try ]; do
echo "[INFO] 第$((try_count+1))次尝试运行主命令: $MAIN_CMD"
$MAIN_CMD > bundle_missing_gem.log 2>&1 && success=1 && break
# 捕获缺失gem
missing_gem=$(grep -o "Could not find [^ ]*" bundle_missing_gem.log | awk '{print $4}' | head -n1)
if [ -n "$missing_gem" ]; then
if ! grep -q "gem '$missing_gem'" "$GEMFILE_PATH"; then
echo "gem '$missing_gem'" >> "$GEMFILE_PATH"
echo "[AUTO] Gemfile已自动补全: $missing_gem"
else
echo "[WARN] Gemfile已包含 $missing_gem,但依然缺失,可能是平台或缓存问题"
fi
bundle install --gemfile "$GEMFILE_PATH" --path "$BUNDLE_PATH"
else
echo "[FATAL] 未检测到缺失gem需人工介入。日志如下"
cat bundle_missing_gem.log
exit 2
fi
try_count=$((try_count+1))
sleep 2
echo "[WARN] 第$try_count 次自动补全后重试..."
done
if [ $success -eq 1 ]; then
echo "[SUCCESS] 所有依赖已补全,主命令执行成功。"
exit 0
else
echo "[FATAL] 自动补全$max_try次后依然失败请人工检查Gemfile和依赖环境。"
exit 3
fi