pindo 5.13.7 → 5.13.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pindo/base/git_handler.rb +247 -42
  3. data/lib/pindo/command/android/autobuild.rb +104 -31
  4. data/lib/pindo/command/android/autoresign.rb +23 -322
  5. data/lib/pindo/command/android/keystore.rb +7 -130
  6. data/lib/pindo/command/appstore/adhocbuild.rb +52 -15
  7. data/lib/pindo/command/appstore/autobuild.rb +104 -8
  8. data/lib/pindo/command/appstore/autoresign.rb +3 -5
  9. data/lib/pindo/command/ios/autobuild.rb +96 -32
  10. data/lib/pindo/command/ios/build.rb +8 -186
  11. data/lib/pindo/command/jps/media.rb +146 -0
  12. data/lib/pindo/command/jps/upload.rb +49 -21
  13. data/lib/pindo/command/jps.rb +1 -0
  14. data/lib/pindo/command/unity/autobuild.rb +141 -32
  15. data/lib/pindo/command/unity/packpush.rb +5 -8
  16. data/lib/pindo/command/utils/repoinit.rb +0 -2
  17. data/lib/pindo/command/utils/tag.rb +58 -26
  18. data/lib/pindo/command/utils.rb +0 -1
  19. data/lib/pindo/command/web/autobuild.rb +98 -34
  20. data/lib/pindo/command.rb +0 -56
  21. data/lib/pindo/config/build_info_manager.rb +7 -8
  22. data/lib/pindo/module/android/android_config_helper.rb +2 -11
  23. data/lib/pindo/module/appselect.rb +15 -41
  24. data/lib/pindo/module/appstore/itcapp_helper.rb +3 -6
  25. data/lib/pindo/module/build/build_helper.rb +28 -18
  26. data/lib/pindo/module/build/git_repo_helper.rb +284 -405
  27. data/lib/pindo/module/cert/pem_helper.rb +3 -6
  28. data/lib/pindo/module/pgyer/pgyerhelper.rb +193 -25
  29. data/lib/pindo/module/task/model/appstore/appstore_task.rb +5 -0
  30. data/lib/pindo/module/task/model/build/android_build_adhoc_task.rb +13 -187
  31. data/lib/pindo/module/task/model/build/android_build_dev_task.rb +36 -34
  32. data/lib/pindo/module/task/model/build/android_build_gplay_task.rb +13 -187
  33. data/lib/pindo/module/task/model/build/ios_build_adhoc_task.rb +9 -6
  34. data/lib/pindo/module/task/model/build/ios_build_appstore_task.rb +9 -6
  35. data/lib/pindo/module/task/model/build/ios_build_dev_task.rb +37 -32
  36. data/lib/pindo/module/task/model/build/web_build_dev_task.rb +7 -5
  37. data/lib/pindo/module/task/model/build_task.rb +8 -11
  38. data/lib/pindo/module/task/model/git/git_commit_task.rb +118 -0
  39. data/lib/pindo/module/task/model/git/git_tag_task.rb +125 -0
  40. data/lib/pindo/module/task/model/git_task.rb +75 -0
  41. data/lib/pindo/module/task/model/jps/jps_message_task.rb +178 -0
  42. data/lib/pindo/module/task/model/{jps_resign_task.rb → jps/jps_resign_task.rb} +14 -23
  43. data/lib/pindo/module/task/model/jps/jps_upload_media_task.rb +248 -0
  44. data/lib/pindo/module/task/model/{jps_upload_task.rb → jps/jps_upload_task.rb} +39 -94
  45. data/lib/pindo/module/task/model/jps_task.rb +43 -0
  46. data/lib/pindo/module/task/model/{ipa_local_resign_task.rb → resign/ipa_local_resign_task.rb} +7 -2
  47. data/lib/pindo/module/task/model/unity/unity_config_task.rb +103 -0
  48. data/lib/pindo/module/task/model/{unity_export_task.rb → unity/unity_export_task.rb} +76 -78
  49. data/lib/pindo/module/task/model/unity/unity_update_task.rb +95 -0
  50. data/lib/pindo/module/task/model/unity/unity_yoo_asset_task.rb +156 -0
  51. data/lib/pindo/module/task/model/unity_task.rb +118 -0
  52. data/lib/pindo/module/task/pindo_task.rb +101 -1
  53. data/lib/pindo/module/task/task_manager.rb +29 -24
  54. data/lib/pindo/module/unity/nuget_helper.rb +7 -7
  55. data/lib/pindo/module/unity/unity_command_helper.rb +188 -0
  56. data/lib/pindo/module/unity/unity_env_helper.rb +208 -0
  57. data/lib/pindo/module/unity/unity_helper.rb +189 -746
  58. data/lib/pindo/module/unity/unity_proc_helper.rb +390 -0
  59. data/lib/pindo/options/core/global_options_state.rb +96 -26
  60. data/lib/pindo/options/core/option_configuration.rb +3 -0
  61. data/lib/pindo/options/core/option_item.rb +36 -0
  62. data/lib/pindo/options/groups/build_options.rb +23 -6
  63. data/lib/pindo/options/groups/git_options.rb +115 -0
  64. data/lib/pindo/options/groups/jps_options.rb +7 -0
  65. data/lib/pindo/options/groups/option_group.rb +15 -0
  66. data/lib/pindo/options/groups/unity_options.rb +49 -0
  67. data/lib/pindo/options/options.rb +2 -0
  68. data/lib/pindo/version.rb +2 -2
  69. metadata +25 -14
  70. data/lib/pindo/base/githelper.rb +0 -686
  71. data/lib/pindo/base/pindocontext.rb +0 -602
  72. data/lib/pindo/command/utils/feishu.rb +0 -134
  73. data/lib/pindo/module/build/version_helper.rb +0 -146
  74. data/lib/pindo/module/task/model/git_tag_task.rb +0 -80
@@ -1,209 +1,35 @@
1
1
  require_relative 'android_build_task'
2
- require 'pindo/module/build/build_helper'
3
- require 'pindo/module/build/version_helper'
4
- require 'pindo/module/build/git_repo_helper'
5
- require 'pindo/module/android/android_config_helper'
6
- require 'pindo/module/android/android_build_helper'
7
- require 'pindo/module/pgyer/pgyerhelper'
8
- require 'pindo/base/githelper'
9
2
 
10
3
  module Pindo
11
4
  module TaskSystem
12
5
  # Android Google Play 模式构建任务
13
- # 使用 Release 模式编译 Android 工程用于 Google Play 发布
6
+ # TODO: 待实现
14
7
  class AndroidBuildGPlayTask < AndroidBuildTask
15
- include Pindo::Githelper
8
+ # 任务键
9
+ def self.task_key
10
+ :android_build_gplay
11
+ end
16
12
 
17
13
  def initialize(options = {})
18
- @bundle_name = options[:bundle_name]
19
- @proj_name = options[:proj_name]
20
- @upload_flag = options[:upload] || false
21
- @send_flag = options[:send] || false
22
-
23
- # 接收外部传入的 JPS 配置
24
- @app_info_obj = options[:app_info_obj]
25
- @workflow_info = options[:workflow_info]
26
-
27
- super(:android, :release, options)
14
+ options[:platform] = :android
15
+ options[:mode] = :release
16
+ super("构建 AAB (Google Play)", options)
28
17
  end
29
18
 
30
19
  protected
31
20
 
32
- def build_task_name
33
- "构建 APK (Release)"
34
- end
35
-
36
21
  def prepare_build
37
- # 校验必需的参数
38
- Dir.chdir(@project_path)
39
- validate_workflow_info
40
- check_git_tag if @upload_flag
41
- update_project_config
42
- update_version_info
43
- handle_bundle_name_config if @bundle_name
44
- add_application_id_scheme
22
+ # TODO: 待实现
23
+ raise Informative, "AndroidBuildGPlayTask 暂未实现"
45
24
  end
46
25
 
47
26
  def execute_build
48
- build_android_project
27
+ # TODO: 待实现
49
28
  end
50
29
 
51
30
  def find_output
52
- # 搜索 APK 和 AAB 文件
53
- search_paths = []
54
- search_paths.concat(TaskConfig::BUILD_OUTPUT_PATTERNS[:apk].map { |p| File.join(@project_path, p) })
55
- search_paths.concat(TaskConfig::BUILD_OUTPUT_PATTERNS[:aab].map { |p| File.join(@project_path, p) })
56
-
57
- package_files = []
58
- search_paths.each do |pattern|
59
- package_files.concat(Dir.glob(pattern))
60
- end
61
-
62
- # 过滤测试包和未签名包
63
- package_files.reject! do |f|
64
- basename = File.basename(f).downcase
65
- TaskConfig::EXCLUDED_PATTERNS.any? { |pattern| basename.include?(pattern) }
66
- end
67
-
68
- if package_files.any?
69
- # 优先返回 AAB,其次 APK
70
- aab_files = package_files.select { |f| f.end_with?(".aab") }
71
- apk_files = package_files.select { |f| f.end_with?(".apk") }
72
-
73
- latest_package = if aab_files.any?
74
- aab_files.max_by { |f| File.mtime(f) }
75
- elsif apk_files.any?
76
- apk_files.max_by { |f| File.mtime(f) }
77
- else
78
- package_files.max_by { |f| File.mtime(f) }
79
- end
80
-
81
- puts " 找到 Android 包文件: #{latest_package}"
82
- latest_package
83
- else
84
- puts " 警告: 未找到 APK/AAB 文件"
85
- nil
86
- end
87
- end
88
-
89
- private
90
-
91
- # 校验工作流信息
92
- def validate_workflow_info
93
- unless @workflow_info && @workflow_info[:package_name]
94
- raise Informative, "未提供工作流信息,请在创建任务时传入 workflow_info 参数"
95
- end
96
- end
97
-
98
- # Git 标签检查
99
- def check_git_tag
100
- git_repo_helper = Pindo::GitRepoHelper.share_instance
101
- is_need_add_tag, tag_action_params = git_repo_helper.check_is_need_add_tag?(@project_path)
102
- if is_need_add_tag
103
- git_repo_helper.create_and_push_tag(
104
- project_dir: @project_path,
105
- mode: 'minor',
106
- force_retag: tag_action_params&.include?('--retag') || false,
107
- custom_tag: nil,
108
- release_branch: 'master'
109
- )
110
- end
111
- end
112
-
113
- # 更新工程配置
114
- def update_project_config
115
- workflow_packname = @workflow_info[:package_name]
116
-
117
- puts "\n使用工作流配置更新 Android 项目:"
118
- puts " Workflow Package Name: #{workflow_packname}"
119
-
120
- # 更新 App Name、Application ID 和 URL Schemes
121
- Pindo::AndroidConfigHelper.update_project_with_workflow(
122
- project_dir: @project_path,
123
- workflow_packname: workflow_packname
124
- )
125
-
126
- # 下载并替换 Icon
127
- if @app_info_obj && @app_info_obj["projectIcon"] && !@app_info_obj["projectIcon"].empty?
128
- icon_replace_success = Pindo::AndroidConfigHelper.download_and_replace_icon_from_url(
129
- project_dir: @project_path,
130
- icon_url: @app_info_obj["projectIcon"]
131
- )
132
-
133
- unless icon_replace_success
134
- raise Informative, "Icon 下载或替换失败,请检查 Icon URL 是否有效: #{@app_info_obj["projectIcon"]}"
135
- end
136
- else
137
- Funlog.warning("未配置 Icon URL,跳过 Icon 替换")
138
- end
139
- end
140
-
141
- # 更新版本号
142
- def update_version_info
143
- version_helper = Pindo::VersionHelper.share_instance
144
- version_info = version_helper.get_version_info(project_dir: @project_path)
145
-
146
- if version_info[:is_git_repo]
147
- Pindo::AndroidConfigHelper.update_android_project_version(
148
- project_dir: @project_path,
149
- version_name: version_info[:version],
150
- version_code: version_info[:build_number]
151
- )
152
- else
153
- Funlog.warning("非Git仓库,保持工程原有版本号")
154
- end
155
- end
156
-
157
- # 处理 Bundle Name 特殊配置
158
- def handle_bundle_name_config
159
- return unless @bundle_name && !@bundle_name.empty?
160
-
161
- puts "\n正在处理指定的 Bundle Name: #{@bundle_name}..."
162
-
163
- # 检查是否为通配符
164
- is_wildcard = @bundle_name.include?('*') ||
165
- @bundle_name.end_with?('.') ||
166
- ['com.test', 'com.example', 'com.demo'].include?(@bundle_name)
167
-
168
- if is_wildcard
169
- puts " ⚠️ 检测到通配符或通用 Bundle Name: #{@bundle_name}"
170
- puts " ⚠️ 跳过 google-services.json 和 Application ID 更新"
171
- else
172
- # 拉取配置仓库
173
- config_repo_dir = clong_buildconfig_repo(repo_name: @bundle_name)
174
-
175
- if config_repo_dir && File.exist?(config_repo_dir)
176
- # 拷贝 google-services.json
177
- Pindo::AndroidConfigHelper.copy_google_services_from_config_repo(
178
- config_repo_dir: config_repo_dir,
179
- project_dir: @project_path
180
- )
181
-
182
- # 更新 Application ID
183
- Pindo::AndroidConfigHelper.update_application_id(
184
- project_dir: @project_path,
185
- application_id: @bundle_name
186
- )
187
-
188
- puts " ✓ Bundle Name 配置处理完成"
189
- else
190
- raise Informative, "无法获取配置仓库"
191
- end
192
- end
193
- end
194
-
195
- # 添加基于 Application ID 的 Scheme
196
- def add_application_id_scheme
197
- Pindo::AndroidConfigHelper.add_application_id_based_scheme(
198
- project_dir: @project_path
199
- )
200
- end
201
-
202
- # 构建 Android 工程
203
- def build_android_project
204
- android_build_helper = Pindo::AndroidBuildHelper.share_instance
205
- # 第二个参数 false 表示 release 模式
206
- android_build_helper.auto_build_apk(@project_path, false)
31
+ # TODO: 待实现
32
+ nil
207
33
  end
208
34
  end
209
35
  end
@@ -1,6 +1,6 @@
1
1
  require_relative 'ios_build_task'
2
2
  require 'pindo/module/build/build_helper'
3
- require 'pindo/module/build/version_helper'
3
+ require 'pindo/module/build/git_repo_helper'
4
4
  require 'pindo/module/build/git_repo_helper'
5
5
  require 'pindo/module/xcode/xcode_build_config'
6
6
  require 'pindo/module/xcode/xcode_build_helper'
@@ -17,6 +17,11 @@ module Pindo
17
17
  # 使用 AdHoc 证书编译 iOS 工程
18
18
  # 包含 AdHoc 特有的准备工作(版本号增加、Tag 创建、Quark/Swark 处理等)
19
19
  class IosBuildAdhocTask < IosBuildTask
20
+ # 任务键
21
+ def self.task_key
22
+ :ios_build_adhoc
23
+ end
24
+
20
25
  def initialize(options = {})
21
26
  @bundle_id = options[:bundle_id]
22
27
  @proj_name = options[:proj_name]
@@ -27,15 +32,13 @@ module Pindo
27
32
  # 保存 Unity 根目录路径(用于查找 config.json)
28
33
  @unity_root_path = options[:unity_root_path]
29
34
 
30
- super(:ios, :adhoc, options)
35
+ options[:platform] = :ios
36
+ options[:mode] = :adhoc
37
+ super("构建 IPA (AdHoc)", options)
31
38
  end
32
39
 
33
40
  protected
34
41
 
35
- def build_task_name
36
- "构建 IPA (AdHoc)"
37
- end
38
-
39
42
  #准备构建
40
43
  def prepare_build
41
44
  Dir.chdir(@project_path)
@@ -1,6 +1,6 @@
1
1
  require_relative 'ios_build_task'
2
2
  require 'pindo/module/build/build_helper'
3
- require 'pindo/module/build/version_helper'
3
+ require 'pindo/module/build/git_repo_helper'
4
4
  require 'pindo/module/build/git_repo_helper'
5
5
  require 'pindo/module/xcode/xcode_build_config'
6
6
  require 'pindo/module/xcode/xcode_build_helper'
@@ -17,6 +17,11 @@ module Pindo
17
17
  # 使用 Distribution/App Store 证书编译 iOS 工程
18
18
  # 包含 AppStore 特有的准备工作(版本号增加、Tag 创建、Quark/Swark 处理等)
19
19
  class IosBuildAppStoreTask < IosBuildTask
20
+ # 任务键
21
+ def self.task_key
22
+ :ios_build_appstore
23
+ end
24
+
20
25
  def initialize(options = {})
21
26
  @bundle_id = options[:bundle_id]
22
27
  @proj_name = options[:proj_name]
@@ -27,15 +32,13 @@ module Pindo
27
32
  # 保存 Unity 根目录路径(用于查找 config.json)
28
33
  @unity_root_path = options[:unity_root_path]
29
34
 
30
- super(:ios, :release, options)
35
+ options[:platform] = :ios
36
+ options[:mode] = :release
37
+ super("构建 IPA (AppStore)", options)
31
38
  end
32
39
 
33
40
  protected
34
41
 
35
- def build_task_name
36
- "构建 IPA (Release)"
37
- end
38
-
39
42
  #准备构建
40
43
  def prepare_build
41
44
  Dir.chdir(@project_path)
@@ -1,6 +1,6 @@
1
1
  require_relative 'ios_build_task'
2
2
  require 'pindo/module/build/build_helper'
3
- require 'pindo/module/build/version_helper'
3
+ require 'pindo/module/build/git_repo_helper'
4
4
  require 'pindo/module/build/git_repo_helper'
5
5
  require 'pindo/module/xcode/xcode_build_config'
6
6
  require 'pindo/module/xcode/xcode_build_helper'
@@ -12,6 +12,11 @@ module Pindo
12
12
  # iOS Dev 模式构建任务
13
13
  # 使用 Development 证书编译 iOS 工程
14
14
  class IosBuildDevTask < IosBuildTask
15
+ # 任务键
16
+ def self.task_key
17
+ :ios_build_dev
18
+ end
19
+
15
20
  def initialize(options = {})
16
21
  @bundle_id = options[:bundle_id]
17
22
  @proj_name = options[:proj_name]
@@ -26,27 +31,29 @@ module Pindo
26
31
  # 保存 Unity 根目录路径(用于查找 config.json)
27
32
  @unity_root_path = options[:unity_root_path]
28
33
 
29
- super(:ios, :dev, options)
34
+ # Git 版本控制参数(与 GitOptions 一致)
35
+ @ver_inc = options[:ver_inc] || Pindo::VersionIncreaseType::MINI
36
+ @tag_type = options[:tag_type] || Pindo::CreateTagType::NEW
37
+ @tag_pre = options[:tag_pre] || 'v'
38
+
39
+ options[:platform] = :ios
40
+ options[:mode] = :dev
41
+ super("构建 IPA (Dev)", options)
30
42
  end
31
43
 
32
44
  protected
33
45
 
34
- def build_task_name
35
- "构建 IPA (Dev)"
36
- end
37
-
38
46
  def prepare_build
39
47
  # 校验必需的参数
40
48
  validate_workflow_info
41
49
 
42
50
  Dir.chdir(@project_path)
43
- check_git_tag if @upload_flag
44
51
  cleanup_firebase_shell
45
52
  update_project_config
46
53
  update_version_info
47
54
  pull_config
48
55
  update_entitlements
49
-
56
+
50
57
  end
51
58
 
52
59
  def execute_build
@@ -95,21 +102,6 @@ module Pindo
95
102
 
96
103
  private
97
104
 
98
- # Git 标签检查
99
- def check_git_tag
100
- git_repo_helper = Pindo::GitRepoHelper.share_instance
101
- is_need_add_tag, tag_action_params = git_repo_helper.check_is_need_add_tag?(@project_path)
102
- if is_need_add_tag
103
- git_repo_helper.create_and_push_tag(
104
- project_dir: @project_path,
105
- mode: 'minor',
106
- force_retag: tag_action_params&.include?('--retag') || false,
107
- custom_tag: nil,
108
- release_branch: 'master'
109
- )
110
- end
111
- end
112
-
113
105
  # 校验工作流信息
114
106
  def validate_workflow_info
115
107
  unless @workflow_info && @workflow_info[:package_name]
@@ -149,18 +141,31 @@ module Pindo
149
141
 
150
142
  # 更新版本号
151
143
  def update_version_info
152
- version_helper = Pindo::VersionHelper.share_instance
153
- version_info = version_helper.get_version_info(project_dir: @project_path)
144
+ git_repo_helper = Pindo::GitRepoHelper.share_instance
154
145
 
155
- if version_info[:is_git_repo]
156
- Pindo::XcodeBuildConfig.update_ios_project_version(
157
- project_dir: @project_path,
158
- version: version_info[:version],
159
- build_number: version_info[:build_number]
160
- )
161
- else
146
+ # 检查是否是 Git 仓库
147
+ git_root = Pindo::GitHandler.git_root_directory(local_repo_dir: @project_path)
148
+ unless git_root
162
149
  Funlog.warning("非Git仓库,保持工程原有版本号")
150
+ return
163
151
  end
152
+
153
+ # 获取 build_number(从 commit hash 计算)
154
+ build_number = git_repo_helper.get_build_number_from_commit(project_dir: @project_path)
155
+
156
+ # 计算 build_version
157
+ build_version = git_repo_helper.calculate_build_version(
158
+ project_dir: @project_path,
159
+ tag_prefix: @tag_pre,
160
+ create_tag_type: @tag_type,
161
+ version_increase_type: @ver_inc
162
+ )
163
+
164
+ Pindo::XcodeBuildConfig.update_ios_project_version(
165
+ project_dir: @project_path,
166
+ version: build_version,
167
+ build_number: build_number
168
+ )
164
169
  end
165
170
 
166
171
  # 检查配置
@@ -6,16 +6,18 @@ module Pindo
6
6
  # Web 平台不需要编译,Unity 导出后即为最终产物
7
7
  # 此任务只检查构建产物是否存在
8
8
  class WebBuildDevTask < BuildTask
9
+ def self.task_key
10
+ :web_build_dev
11
+ end
12
+
9
13
  def initialize(options = {})
10
- super(:web, :dev, options)
14
+ options[:platform] = :web
15
+ options[:mode] = :dev
16
+ super("构建 WebGL", options)
11
17
  end
12
18
 
13
19
  protected
14
20
 
15
- def build_task_name
16
- "构建 WebGL"
17
- end
18
-
19
21
  def prepare_build
20
22
  # Web 不需要准备,Unity 导出后即完成
21
23
  end
@@ -13,6 +13,11 @@ module Pindo
13
13
  :build
14
14
  end
15
15
 
16
+ # 任务类型显示名称
17
+ def self.task_type_name
18
+ "编译构建"
19
+ end
20
+
16
21
  # 重试配置
17
22
  def self.default_retry_mode
18
23
  RetryMode::DELAYED
@@ -130,15 +135,12 @@ module Pindo
130
135
 
131
136
  # ========== 实例方法 ==========
132
137
 
133
- def initialize(platform, mode, options = {})
134
- @platform = platform
135
- @mode = mode
138
+ def initialize(name, options = {})
139
+ @platform = options[:platform]
140
+ @mode = options[:mode]
136
141
  @project_path = options[:project_path] || Dir.pwd
137
142
  @output_path = nil
138
143
 
139
- # 构建任务名称
140
- name = build_task_name
141
-
142
144
  super(name, options)
143
145
  end
144
146
 
@@ -164,11 +166,6 @@ module Pindo
164
166
 
165
167
  # ========== 子类必须实现的抽象方法 ==========
166
168
 
167
- # 构建任务名称
168
- def build_task_name
169
- raise NotImplementedError, "子类必须实现 build_task_name 方法"
170
- end
171
-
172
169
  # 准备构建环境
173
170
  def prepare_build
174
171
  raise NotImplementedError, "子类必须实现 prepare_build 方法"
@@ -0,0 +1,118 @@
1
+ require 'pindo/module/task/model/git_task'
2
+ require 'pindo/base/git_handler'
3
+ require 'pindo/module/build/git_repo_helper'
4
+
5
+ module Pindo
6
+ module TaskSystem
7
+ # Git 提交任务
8
+ # 负责检查并提交仓库的未提交修改
9
+ class GitCommitTask < GitTask
10
+ attr_reader :release_branch, :ver_inc, :tag_type, :tag_pre
11
+ attr_reader :build_version, :build_number
12
+
13
+ # 任务键
14
+ def self.task_key
15
+ :git_commit
16
+ end
17
+
18
+ # 重试配置:失败后重试 1 次
19
+ def self.default_retry_count
20
+ 2
21
+ end
22
+
23
+ # 初始化 Git 提交任务
24
+ # @param project_path [String] 项目路径
25
+ # @param options [Hash] 选项(与 GitOptions 参数名一致)
26
+ # - release_branch: 发布分支名称,默认 'master'
27
+ # - ver_inc: 版本号增加类型,默认 :mini
28
+ # - tag_type: 创建tag类型,默认 :new
29
+ # - tag_pre: tag前缀,默认 'v'
30
+ # - fixed_version: 外部指定的固定版本号,如果设置则跳过版本号计算
31
+ def initialize(project_path, options = {})
32
+ @release_branch = options[:release_branch] || 'master'
33
+ @ver_inc = options[:ver_inc] || Pindo::VersionIncreaseType::MINI
34
+ @tag_type = options[:tag_type] || Pindo::CreateTagType::NEW
35
+ @tag_pre = options[:tag_pre] || 'v'
36
+ @fixed_version = options[:fixed_version] # 外部指定的固定版本号
37
+
38
+ @build_version = nil
39
+ @build_number = nil
40
+ options[:project_path] = project_path
41
+
42
+ super("Git仓库文件提交检查", options)
43
+ end
44
+
45
+ def validate
46
+ super
47
+ # 不再验证是否为 Git 仓库,由 do_work 中处理
48
+ # 非 Git 仓库目录会跳过检查并成功返回
49
+ true
50
+ end
51
+
52
+ protected
53
+
54
+ def do_work
55
+ # 检查是否为 Git 仓库,如果不是则直接成功返回
56
+ unless valid_git_repository?
57
+ Funlog.instance.fancyinfo_warning("当前目录不是Git仓库,跳过Git提交检查")
58
+ return {
59
+ success: true,
60
+ is_git_repo: false,
61
+ message: "当前目录不是Git仓库,已跳过Git提交检查"
62
+ }
63
+ end
64
+
65
+ # 使用基类的 git_root_path 属性
66
+ root_dir = @git_root_path
67
+ git_repo_helper = Pindo::GitRepoHelper.share_instance
68
+
69
+ # 1. 检查并修复 .gitignore
70
+ git_repo_helper.check_gitignore(root_dir)
71
+
72
+ # 2. 检查并处理未提交的文件(使用 GitHandler)
73
+ begin
74
+ Pindo::GitHandler.check_uncommitted_files(project_dir: root_dir)
75
+ rescue Informative => e
76
+ # 用户选择手动处理时,不需要重试
77
+ if e.message.include?("请手动处理")
78
+ @retry_count = 0
79
+ end
80
+ raise
81
+ end
82
+
83
+ # 3. 获取当前分支
84
+ coding_branch = get_current_branch_name
85
+
86
+ # 4. 检查并推送本地提交到远程
87
+ Pindo::GitHandler.check_unpushed_commits(project_dir: root_dir, branch: coding_branch)
88
+
89
+ # 5. 计算 build_version
90
+ # 如果指定了固定版本号,使用它;否则计算版本号
91
+ if @fixed_version && !@fixed_version.empty?
92
+ @build_version = @fixed_version
93
+ @build_number = nil
94
+ Funlog.instance.fancyinfo_success("版本号: #{@build_version}")
95
+ else
96
+ @build_number = git_repo_helper.get_build_number_from_commit(project_dir: root_dir)
97
+ @build_version = git_repo_helper.calculate_build_version(
98
+ project_dir: root_dir,
99
+ tag_prefix: @tag_pre,
100
+ create_tag_type: @tag_type,
101
+ version_increase_type: @ver_inc
102
+ )
103
+ Funlog.instance.fancyinfo_success("版本号: #{@build_version}, Build: #{@build_number}")
104
+ end
105
+
106
+ {
107
+ success: true,
108
+ root_dir: root_dir,
109
+ current_branch: coding_branch,
110
+ release_branch: @release_branch,
111
+ build_version: @build_version,
112
+ build_number: @build_number,
113
+ tag_pre: @tag_pre
114
+ }
115
+ end
116
+ end
117
+ end
118
+ end