Class: Pindo::BuildInfoManager
- Inherits:
-
Object
- Object
- Pindo::BuildInfoManager
- Includes:
- Pindoconfig::Mixin, Singleton
- Defined in:
- lib/pindo/config/build_info_manager.rb
Overview
构建信息管理器负责管理应用配置仓库的拉取、更新等操作
Class Method Summary collapse
Instance Method Summary collapse
-
#create_appconfig_with_bundleid(bundle_id:, test_flag: false) ⇒ String?
创建应用配置仓库.
-
#get_deploy_repo_with_modul_name(module_name:) ⇒ String?
根据模块名称获取部署仓库名称.
-
#pull_appconfig_with_reponame(repo_name:, target_dir: nil) ⇒ Boolean
拉取应用配置仓库.
Methods included from Pindoconfig::Mixin
Class Method Details
.share_instance ⇒ Object
15 16 17 |
# File 'lib/pindo/config/build_info_manager.rb', line 15 def share_instance instance end |
Instance Method Details
#create_appconfig_with_bundleid(bundle_id:, test_flag: false) ⇒ String?
创建应用配置仓库
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/pindo/config/build_info_manager.rb', line 64 def create_appconfig_with_bundleid(bundle_id:, test_flag: false) return nil if bundle_id.nil? || bundle_id.empty? require_relative '../client/giteeclient' # 获取 Gitee 客户端 gitee_client = GiteeClient.new(access_token: pindo_single_config.gitee_api_key) # 获取模板配置仓库目录 demo_dir = Pindo::GitHandler.clong_buildconfig_repo(repo_name: pindo_single_config.demo_bundle_id) # 确定仓库公开类型和所有者组织 public_type = 0 owner_org = pindo_single_config.build_deploy_org repo_name = bundle_id if test_flag owner_org = pindo_single_config.build_test_org public_type = 2 end # 创建 Gitee 仓库 success = gitee_client.gitee_create_repo( owner: owner_org, repo_name: repo_name, public_type: public_type ) if success # 如果是测试环境,修改仓库设置 if test_flag modify_repo_setting(repo_name: repo_name, owner_org: owner_org) end # Gitee 仓库创建后需要短暂延迟,等待仓库完全初始化 Funlog.instance.("等待 Gitee 仓库初始化...") sleep 2 # 克隆配置仓库,带重试机制 app_config_dir = nil max_retries = 3 retry_count = 0 while retry_count < max_retries begin app_config_dir = Pindo::GitHandler.clong_buildconfig_repo(repo_name: repo_name) break if app_config_dir && File.exist?(app_config_dir) rescue StandardError => e retry_count += 1 if retry_count < max_retries Funlog.instance.("克隆失败 (#{retry_count}/#{max_retries}),#{3}秒后重试...") sleep 3 else Funlog.instance.("克隆仓库失败: #{e.message}") return nil end end end system "open #{app_config_dir}" if app_config_dir if app_config_dir && File.exist?(app_config_dir) # 从模板仓库复制配置文件 update_appconfig_repo( bundle_id: bundle_id, demo_dir: demo_dir, app_config_dir: app_config_dir ) Funlog.instance.("配置仓库创建成功: #{app_config_dir}") return app_config_dir else Funlog.instance.("创建应用配置仓库失败") return nil end else # 仓库已存在,直接打开 app_config_dir = Pindo::GitHandler.clong_buildconfig_repo(repo_name: repo_name) system "open #{app_config_dir}" Funlog.instance.("配置仓库已存在: #{app_config_dir}") return app_config_dir end end |
#get_deploy_repo_with_modul_name(module_name:) ⇒ String?
根据模块名称获取部署仓库名称
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/pindo/config/build_info_manager.rb', line 150 def get_deploy_repo_with_modul_name(module_name:) return nil if module_name.nil? || module_name.empty? # 读取 deploy_build_setting.json setting_file = File.join(pindo_single_config.pindo_env_configdir, 'deploy_build_setting.json') unless File.exist?(setting_file) Funlog.instance.("deploy_build_setting.json 不存在: #{setting_file}") return nil end begin setting_json = JSON.parse(File.read(setting_file)) repo_name = setting_json.dig(module_name, 'git_repo_name') if repo_name.nil? || repo_name.empty? raise Informative, "config.json app_type is error!!!" end return repo_name rescue JSON::ParserError => e Funlog.instance.("解析 deploy_build_setting.json 失败: #{e.message}") return nil rescue => e raise Informative, "config.json app_type is error!!!" end end |
#pull_appconfig_with_reponame(repo_name:, target_dir: nil) ⇒ Boolean
拉取应用配置仓库
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pindo/config/build_info_manager.rb', line 24 def pull_appconfig_with_reponame(repo_name:, target_dir: nil) return false if repo_name.nil? || repo_name.empty? # 规范化仓库名称:去除尾部的 .* (通配符转换) normalized_repo_name = repo_name.end_with?('.*') ? repo_name.chomp('.*') : repo_name # 获取配置仓库目录 begin app_config_dir = Pindo::GitHandler.clong_buildconfig_repo(repo_name: normalized_repo_name) rescue StandardError => e Funlog.instance.("拉取配置仓库失败: #{e.message}") return false end # 确定目标目录 target_dir ||= Dir.pwd # 如果配置仓库目录与目标目录不同,且存在 config.json,则复制 if !app_config_dir.eql?(target_dir) && File.exist?(File.join(app_config_dir, 'config.json')) begin FileUtils.cp_r(File.join(app_config_dir, "config.json"), target_dir) Funlog.instance.("配置文件已复制到: #{target_dir}") return true rescue StandardError => e Funlog.instance.("复制配置文件失败: #{e.message}") return false end elsif app_config_dir.eql?(target_dir) Funlog.instance.("配置文件已存在于目标目录") return true else Funlog.instance.("配置仓库中未找到 config.json") return false end end |