pindo 5.14.3 → 5.14.5

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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pindo/base/aeshelper.rb +1 -0
  3. data/lib/pindo/base/executable.rb +2 -0
  4. data/lib/pindo/base/git_handler.rb +45 -7
  5. data/lib/pindo/base/informative.rb +11 -0
  6. data/lib/pindo/base/plistbuddyexecutable.rb +2 -0
  7. data/lib/pindo/client/feishuclient.rb +1 -1
  8. data/lib/pindo/client/httpclient.rb +88 -12
  9. data/lib/pindo/command/android/autobuild.rb +3 -7
  10. data/lib/pindo/command/appstore/autobuild.rb +8 -18
  11. data/lib/pindo/command/gplay/pullconfig.rb +3 -2
  12. data/lib/pindo/command/ios/autobuild.rb +3 -7
  13. data/lib/pindo/command/jps/bind.rb +284 -121
  14. data/lib/pindo/command/jps/media.rb +1 -15
  15. data/lib/pindo/command/unity/autobuild.rb +5 -14
  16. data/lib/pindo/command/unity/packbuild.rb +3 -8
  17. data/lib/pindo/command/utils/tag.rb +2 -7
  18. data/lib/pindo/command/utils/updateconfig.rb +3 -2
  19. data/lib/pindo/command/web/autobuild.rb +23 -33
  20. data/lib/pindo/command.rb +1 -8
  21. data/lib/pindo/config/ios_config_parser.rb +26 -25
  22. data/lib/pindo/module/android/android_build_helper.rb +1 -1
  23. data/lib/pindo/module/android/android_config_helper.rb +1 -1
  24. data/lib/pindo/module/android/android_res_helper.rb +1 -1
  25. data/lib/pindo/module/pgyer/pgyerhelper.rb +87 -0
  26. data/lib/pindo/module/task/model/build/android_build_dev_task.rb +29 -15
  27. data/lib/pindo/module/task/model/build/ios_build_adhoc_task.rb +2 -3
  28. data/lib/pindo/module/task/model/build/ios_build_dev_task.rb +30 -16
  29. data/lib/pindo/module/task/model/git/git_commit_task.rb +68 -13
  30. data/lib/pindo/module/task/model/git/git_tag_task.rb +16 -7
  31. data/lib/pindo/module/task/model/jps/jps_bind_package_task.rb +217 -0
  32. data/lib/pindo/module/task/model/jps/jps_message_task.rb +3 -2
  33. data/lib/pindo/module/task/model/jps/jps_upload_media_task.rb +168 -49
  34. data/lib/pindo/module/task/model/jps/jps_workflow_message_task.rb +190 -0
  35. data/lib/pindo/module/task/model/unity/unity_config_task.rb +4 -0
  36. data/lib/pindo/module/task/pindo_task.rb +1 -0
  37. data/lib/pindo/module/xcode/xcode_app_config.rb +26 -16
  38. data/lib/pindo/module/xcode/xcode_build_config.rb +2 -2
  39. data/lib/pindo/module/xcode/xcode_swark_helper.rb +5 -5
  40. data/lib/pindo/version.rb +1 -1
  41. metadata +13 -54
@@ -222,40 +222,30 @@ module Pindo
222
222
  # Web 只支持 Unity 工程
223
223
  tasks = []
224
224
 
225
- # 1. Git 提交任务(如果需要上传)
226
- if @args_upload_flag
227
- # 提前询问用户如何处理未提交的文件
228
- process_type = Pindo::GitHandler.get_uncommitted_files_process_type(
229
- project_dir: config[:project_path],
230
- interactive: true
231
- )
225
+ # 1. Git 提交任务(总是创建)
226
+ # 提前询问用户如何处理未提交的文件
227
+ process_type = Pindo::GitHandler.get_uncommitted_files_process_type(
228
+ project_dir: config[:project_path],
229
+ interactive: true
230
+ )
232
231
 
233
- git_commit_task = Pindo::TaskSystem::GitCommitTask.new(
234
- config[:project_path],
235
- release_branch: @args_release_branch,
236
- ver_inc: @args_ver_inc,
237
- tag_type: @args_tag_type,
238
- tag_pre: @args_tag_pre,
239
- process_type: process_type,
240
- commit_message: "feat: web autobuild 构建前提交"
241
- )
242
- tasks << git_commit_task
243
- last_task = git_commit_task
244
-
245
- # 2. Git 标签任务(依赖提交任务,在 Unity 导出之前创建)
246
- git_tag_task = Pindo::TaskSystem::GitTagTask.new(
247
- config[:project_path],
248
- release_branch: @args_release_branch,
249
- ver_inc: @args_ver_inc,
250
- tag_type: @args_tag_type,
251
- tag_pre: @args_tag_pre
252
- )
253
- git_tag_task.dependencies << git_commit_task.id
254
- tasks << git_tag_task
255
- last_task = git_tag_task
256
- else
257
- last_task = nil
258
- end
232
+ git_commit_task = Pindo::TaskSystem::GitCommitTask.new(
233
+ config[:project_path],
234
+ release_branch: @args_release_branch,
235
+ ver_inc: @args_ver_inc,
236
+ tag_type: @args_tag_type,
237
+ tag_pre: @args_tag_pre,
238
+ process_type: process_type,
239
+ commit_message: "feat: web autobuild 构建前提交"
240
+ )
241
+ tasks << git_commit_task
242
+
243
+ # 2. Git 标签任务(总是创建,依赖提交任务,在 Unity 导出之前创建)
244
+ # 所有参数都从 GitCommitTask 获取
245
+ git_tag_task = Pindo::TaskSystem::GitTagTask.new(config[:project_path])
246
+ git_tag_task.dependencies << git_commit_task.id
247
+ tasks << git_tag_task
248
+ last_task = git_tag_task
259
249
 
260
250
  # 3. Unity 更新必备库任务(可选)
261
251
  unless @args_skip_lib
data/lib/pindo/command.rb CHANGED
@@ -6,18 +6,11 @@ require 'pindo/version'
6
6
  require 'pindo/base/funlog'
7
7
  require 'pindo/base/hashhelper'
8
8
  require 'pindo/base/plaininformative'
9
+ require 'pindo/base/informative'
9
10
  require 'pindo/client/giteeclient'
10
11
  require 'pindo/config/pindoconfig'
11
12
 
12
-
13
-
14
13
  module Pindo
15
- class Informative < PlainInformative
16
- def message
17
- "[!] #{super}".red
18
- end
19
- end
20
-
21
14
  class Command < CLAide::Command
22
15
 
23
16
  include Pindoconfig::Mixin
@@ -318,10 +318,10 @@ module Pindo
318
318
 
319
319
  # 1.5 替换 Apple ID(使用 AdHoc 配置的 Apple ID)
320
320
  if adhoc_config_json.dig('account_info', 'apple_acount_id')
321
- original_apple_id = @config_json.dig('account_info', 'apple_acount_id')
322
- adhoc_apple_id = adhoc_config_json['account_info']['apple_acount_id']
321
+ original_apple_id = @config_json.dig('account_info', 'apple_acount_id')&.strip # 去除前后空格
322
+ adhoc_apple_id = adhoc_config_json['account_info']['apple_acount_id']&.strip # 去除前后空格
323
323
 
324
- if original_apple_id && adhoc_apple_id && original_apple_id != adhoc_apple_id
324
+ if original_apple_id && adhoc_apple_id && !adhoc_apple_id.empty? && original_apple_id != adhoc_apple_id
325
325
  @config_json['account_info']['apple_acount_id'] = adhoc_apple_id
326
326
  puts " 替换 Apple ID:"
327
327
  puts " 原始 Apple ID: #{original_apple_id}"
@@ -330,7 +330,8 @@ module Pindo
330
330
 
331
331
  # 如果 AdHoc 配置包含 company_name,也一并替换
332
332
  if adhoc_config_json.dig('account_info', 'acount_company_name')
333
- @config_json['account_info']['acount_company_name'] = adhoc_config_json['account_info']['acount_company_name']
333
+ company_name = adhoc_config_json['account_info']['acount_company_name']&.strip # 去除前后空格
334
+ @config_json['account_info']['acount_company_name'] = company_name if company_name && !company_name.empty?
334
335
  end
335
336
  end
336
337
 
@@ -438,7 +439,7 @@ module Pindo
438
439
  true
439
440
  rescue => e
440
441
  puts "合并发布配置失败: #{e.message}"
441
- puts e.backtrace.join("\n")
442
+ puts e.backtrace.join("\n") if ENV['PINDO_DEBUG']
442
443
  false
443
444
  end
444
445
  end
@@ -489,40 +490,40 @@ module Pindo
489
490
  # 解析账号信息
490
491
  if @config_json['account_info']
491
492
  account_info = @config_json['account_info']
492
- @config_data[:apple_id] = account_info['apple_acount_id']
493
- @config_data[:company_name] = account_info['acount_company_name']
493
+ @config_data[:apple_id] = account_info['apple_acount_id']&.strip # 去除前后空格
494
+ @config_data[:company_name] = account_info['acount_company_name']&.strip # 去除前后空格
494
495
  end
495
496
 
496
497
  # 解析应用信息
497
498
  if @config_json['app_info']
498
499
  app_info = @config_json['app_info']
499
- @config_data[:bundle_id] = app_info['app_identifier']
500
+ @config_data[:bundle_id] = app_info['app_identifier']&.strip # 去除前后空格
500
501
 
501
502
  # 保存原始 Bundle ID 作为配置仓库名称(只在第一次设置,后续不覆盖)
502
503
  if @app_repo_name.nil? && app_info['app_identifier']
503
- repo_name = app_info['app_identifier']
504
+ repo_name = app_info['app_identifier']&.strip # 去除前后空格
504
505
  # 如果是通配符 Bundle ID(以 .* 结尾),去除通配符后缀
505
- if repo_name.end_with?('.*')
506
+ if repo_name && repo_name.end_with?('.*')
506
507
  repo_name = repo_name[0...-2] # 去除最后的 .*
507
508
  end
508
509
  @app_repo_name = repo_name
509
510
  end
510
511
 
511
- @config_data[:bundle_id_pushcontent] = app_info['app_identifier_pushcontent']
512
- @config_data[:bundle_id_pushservice] = app_info['app_identifier_pushservice']
513
- @config_data[:bundle_id_keyboard] = app_info['app_identifier_keyboard']
514
- @config_data[:bundle_id_imessage] = app_info['app_identifier_imessage']
515
- @config_data[:bundle_id_extension] = app_info['app_identifier_extension']
516
- @config_data[:bundle_id_siri] = app_info['app_identifier_siri']
517
- @config_data[:bundle_id_siriui] = app_info['app_identifier_siriui']
518
- @config_data[:bundle_id_widget] = app_info['app_identifier_widget']
519
- @config_data[:bundle_id_extensionad] = app_info['app_identifier_extensionad']
520
- @config_data[:bundle_id_extensionporn] = app_info['app_identifier_extensionporn']
521
- @config_data[:bundle_id_watchapp] = app_info['app_identifier_watchapp']
522
- @config_data[:bundle_id_watchapp_extension] = app_info['app_identifier_watchapp_extension']
523
-
524
- @config_data[:app_name] = app_info['app_name']
525
- @config_data[:app_version] = app_info['app_version']
512
+ @config_data[:bundle_id_pushcontent] = app_info['app_identifier_pushcontent']&.strip
513
+ @config_data[:bundle_id_pushservice] = app_info['app_identifier_pushservice']&.strip
514
+ @config_data[:bundle_id_keyboard] = app_info['app_identifier_keyboard']&.strip
515
+ @config_data[:bundle_id_imessage] = app_info['app_identifier_imessage']&.strip
516
+ @config_data[:bundle_id_extension] = app_info['app_identifier_extension']&.strip
517
+ @config_data[:bundle_id_siri] = app_info['app_identifier_siri']&.strip
518
+ @config_data[:bundle_id_siriui] = app_info['app_identifier_siriui']&.strip
519
+ @config_data[:bundle_id_widget] = app_info['app_identifier_widget']&.strip
520
+ @config_data[:bundle_id_extensionad] = app_info['app_identifier_extensionad']&.strip
521
+ @config_data[:bundle_id_extensionporn] = app_info['app_identifier_extensionporn']&.strip
522
+ @config_data[:bundle_id_watchapp] = app_info['app_identifier_watchapp']&.strip
523
+ @config_data[:bundle_id_watchapp_extension] = app_info['app_identifier_watchapp_extension']&.strip
524
+
525
+ @config_data[:app_name] = app_info['app_name']&.strip
526
+ @config_data[:app_version] = app_info['app_version']&.strip
526
527
  @config_data[:app_id_ios] = app_info['app_id_ios']
527
528
  end
528
529
 
@@ -397,7 +397,7 @@ module Pindo
397
397
  end
398
398
  rescue => e
399
399
  puts "警告:设置 Play Asset Delivery 失败: #{e.message}"
400
- puts e.backtrace.first(5).join("\n")
400
+ puts e.backtrace.first(5).join("\n") if ENV['PINDO_DEBUG']
401
401
  end
402
402
  end
403
403
 
@@ -955,7 +955,7 @@ module Pindo
955
955
 
956
956
  rescue => e
957
957
  Funlog.instance.fancyinfo_error("Icon 处理失败: #{e.message}")
958
- puts e.backtrace
958
+ puts e.backtrace.join("\n") if ENV['PINDO_DEBUG']
959
959
  replace_success = false
960
960
  ensure
961
961
  # 清理临时文件(无论成功失败都清理)
@@ -287,7 +287,7 @@ module Pindo
287
287
 
288
288
  rescue => e
289
289
  Funlog.instance.fancyinfo_error("安装icon时出错: #{e.message}")
290
- puts e.backtrace
290
+ puts e.backtrace.join("\n") if ENV['PINDO_DEBUG']
291
291
  return false
292
292
  end
293
293
  end
@@ -1550,6 +1550,93 @@ module Pindo
1550
1550
  end
1551
1551
  end
1552
1552
 
1553
+ # 绑定 Git commit 到项目包
1554
+ #
1555
+ # @param commit_id [String] Git commit SHA
1556
+ # @param project_package_ids [Array<String>] 项目包 ID 数组
1557
+ # @return [Hash] 绑定结果
1558
+ def bind_commit_to_package(commit_id:, project_package_ids:)
1559
+ if commit_id.nil? || commit_id.empty?
1560
+ Funlog.instance.fancyinfo_error("commit_id 不能为空")
1561
+ return { success: false, error: "commit_id 不能为空" }
1562
+ end
1563
+
1564
+ if project_package_ids.nil? || project_package_ids.empty?
1565
+ Funlog.instance.fancyinfo_error("project_package_ids 不能为空")
1566
+ return { success: false, error: "project_package_ids 不能为空" }
1567
+ end
1568
+
1569
+ begin
1570
+ result = @pgyer_client.bind_commit_to_package(
1571
+ commitId: commit_id,
1572
+ projectPackageIds: project_package_ids
1573
+ )
1574
+
1575
+ # 兼容两种响应格式
1576
+ response_code = result&.dig("code") || result&.dig("meta", "code")
1577
+
1578
+ if result && (response_code == 0 || response_code == 200)
1579
+ return { success: true, result: result }
1580
+ else
1581
+ error_msg = result&.dig("msg") || result&.dig("meta", "message") || result&.dig("message") || "未知错误"
1582
+ return { success: false, error: error_msg, result: result }
1583
+ end
1584
+ rescue => e
1585
+ Funlog.instance.fancyinfo_error("绑定失败: #{e.message}")
1586
+ return { success: false, error: e.message }
1587
+ end
1588
+ end
1589
+
1590
+ # 发送工作流消息(commit log 消息)
1591
+ #
1592
+ # @param project_id [String] 项目 ID
1593
+ # @param workflow_id [Integer] 工作流 ID
1594
+ # @param commit_id [String] Git commit SHA
1595
+ # @param branch [String] 分支名(可选,默认 'master')
1596
+ # @param single [Boolean] 是否单个提交(可选,默认 true)
1597
+ # @return [Hash] 发送结果
1598
+ def send_workflow_message(project_id:, workflow_id:, commit_id:, branch: 'master', single: true)
1599
+ if project_id.nil? || project_id.empty?
1600
+ Funlog.instance.fancyinfo_error("project_id 不能为空")
1601
+ return { success: false, error: "project_id 不能为空" }
1602
+ end
1603
+
1604
+ if workflow_id.nil?
1605
+ Funlog.instance.fancyinfo_error("workflow_id 不能为空")
1606
+ return { success: false, error: "workflow_id 不能为空" }
1607
+ end
1608
+
1609
+ if commit_id.nil? || commit_id.empty?
1610
+ Funlog.instance.fancyinfo_error("commit_id 不能为空")
1611
+ return { success: false, error: "commit_id 不能为空" }
1612
+ end
1613
+
1614
+ begin
1615
+ result = @pgyer_client.send_commit_log_message(
1616
+ projectId: project_id,
1617
+ workflowId: workflow_id,
1618
+ params: {
1619
+ single: single,
1620
+ branch: branch,
1621
+ commitIds: [commit_id]
1622
+ }
1623
+ )
1624
+
1625
+ # 兼容两种响应格式
1626
+ response_code = result&.dig("code") || result&.dig("meta", "code")
1627
+
1628
+ if result && (response_code == 0 || response_code == 200)
1629
+ return { success: true, result: result }
1630
+ else
1631
+ error_msg = result&.dig("msg") || result&.dig("meta", "message") || result&.dig("message") || "未知错误"
1632
+ return { success: false, error: error_msg, result: result }
1633
+ end
1634
+ rescue => e
1635
+ Funlog.instance.fancyinfo_error("发送工作流消息失败: #{e.message}")
1636
+ return { success: false, error: e.message }
1637
+ end
1638
+ end
1639
+
1553
1640
  private
1554
1641
 
1555
1642
  # 确定 JPSBuildConfig.json 文件路径
@@ -129,25 +129,39 @@ module Pindo
129
129
  # 更新版本号
130
130
  def update_version_info
131
131
  git_repo_helper = Pindo::GitRepoHelper.share_instance
132
+ build_version = nil
133
+ build_number = nil
132
134
 
133
- # 检查是否是 Git 仓库
134
- git_root = Pindo::GitHandler.git_root_directory(local_repo_dir: @project_path)
135
- unless git_root
136
- Funlog.warning("非Git仓库,保持工程原有版本号")
137
- return
138
- end
135
+ # 优先级 1: 从 GitCommitTask 获取版本号(无论当前目录是否为 Git 仓库)
136
+ git_commit_data = get_data_param_by_key(:git_commit)
137
+ if git_commit_data && git_commit_data[:task_param] &&
138
+ git_commit_data[:task_param][:build_version] && git_commit_data[:task_param][:build_number]
139
+ build_version = git_commit_data[:task_param][:build_version]
140
+ build_number = git_commit_data[:task_param][:build_number]
141
+ Funlog.instance.fancyinfo_success("使用 GitCommitTask 的版本号: #{build_version}, Build: #{build_number}")
139
142
 
140
- # 获取 build_number(从 commit hash 计算)
141
- build_number = git_repo_helper.get_build_number_from_commit(project_dir: @project_path)
143
+ else
144
+ # 优先级 2: 检查当前目录是否是 Git 仓库
145
+ git_root = Pindo::GitHandler.git_root_directory(local_repo_dir: @project_path)
142
146
 
143
- # 计算 build_version
144
- build_version = git_repo_helper.calculate_build_version(
145
- project_dir: @project_path,
146
- tag_prefix: @tag_pre,
147
- create_tag_type: @tag_type,
148
- version_increase_type: @ver_inc
149
- )
147
+ if git_root
148
+ # Git 仓库,自己计算版本号
149
+ build_number = git_repo_helper.get_build_number_from_commit(project_dir: @project_path)
150
+ build_version = git_repo_helper.calculate_build_version(
151
+ project_dir: @project_path,
152
+ tag_prefix: @tag_pre,
153
+ create_tag_type: @tag_type,
154
+ version_increase_type: @ver_inc
155
+ )
156
+ Funlog.instance.fancyinfo_success("自己计算版本号: #{build_version}, Build: #{build_number}")
157
+ else
158
+ # 不是 Git 仓库且没有从 GitCommitTask 获取到版本号,跳过版本更新
159
+ Funlog.warning("非Git仓库且未从 GitCommitTask 获取到版本号,保持工程原有版本号")
160
+ return
161
+ end
162
+ end
150
163
 
164
+ # 更新版本号
151
165
  Pindo::AndroidConfigHelper.update_android_project_version(
152
166
  project_dir: @project_path,
153
167
  version_name: build_version,
@@ -1,7 +1,7 @@
1
1
  require_relative 'ios_build_task'
2
+ require 'pindo/base/git_handler'
2
3
  require 'pindo/module/build/build_helper'
3
4
  require 'pindo/module/build/git_repo_helper'
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'
7
7
  require 'pindo/module/xcode/xcode_app_config'
@@ -69,7 +69,7 @@ module Pindo
69
69
  end
70
70
 
71
71
  # 克隆 AdHoc 配置仓库
72
- adhoc_config_dir = build_info_manager.clong_buildconfig_repo(repo_name: adhoc_repo_name)
72
+ adhoc_config_dir = Pindo::GitHandler.clong_buildconfig_repo(repo_name: adhoc_repo_name)
73
73
 
74
74
  # 合并 AdHoc 配置
75
75
  config_parser.modify_config_with_adhoc(adhoc_config_dir: adhoc_config_dir)
@@ -146,7 +146,6 @@ module Pindo
146
146
 
147
147
  # 获取配置仓库目录(用于备份)
148
148
  # 使用 clong_buildconfig_repo 确保仓库已克隆或更新
149
- require 'pindo/base/git_handler'
150
149
  app_config_dir = Pindo::GitHandler.clong_buildconfig_repo(repo_name: app_repo_name)
151
150
 
152
151
  # 1. 清理 Pods 和 Podfile.lock(强制清理)
@@ -142,25 +142,39 @@ module Pindo
142
142
  # 更新版本号
143
143
  def update_version_info
144
144
  git_repo_helper = Pindo::GitRepoHelper.share_instance
145
+ build_version = nil
146
+ build_number = nil
145
147
 
146
- # 检查是否是 Git 仓库
147
- git_root = Pindo::GitHandler.git_root_directory(local_repo_dir: @project_path)
148
- unless git_root
149
- Funlog.warning("非Git仓库,保持工程原有版本号")
150
- return
151
- end
152
-
153
- # 获取 build_number(从 commit hash 计算)
154
- build_number = git_repo_helper.get_build_number_from_commit(project_dir: @project_path)
148
+ # 优先级 1: 从 GitCommitTask 获取版本号(无论当前目录是否为 Git 仓库)
149
+ git_commit_data = get_data_param_by_key(:git_commit)
150
+ if git_commit_data && git_commit_data[:task_param] &&
151
+ git_commit_data[:task_param][:build_version] && git_commit_data[:task_param][:build_number]
152
+ build_version = git_commit_data[:task_param][:build_version]
153
+ build_number = git_commit_data[:task_param][:build_number]
154
+ Funlog.instance.fancyinfo_success("使用 GitCommitTask 的版本号: #{build_version}, Build: #{build_number}")
155
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
- )
156
+ else
157
+ # 优先级 2: 检查当前目录是否是 Git 仓库
158
+ git_root = Pindo::GitHandler.git_root_directory(local_repo_dir: @project_path)
159
+
160
+ if git_root
161
+ # 是 Git 仓库,自己计算版本号
162
+ build_number = git_repo_helper.get_build_number_from_commit(project_dir: @project_path)
163
+ build_version = git_repo_helper.calculate_build_version(
164
+ project_dir: @project_path,
165
+ tag_prefix: @tag_pre,
166
+ create_tag_type: @tag_type,
167
+ version_increase_type: @ver_inc
168
+ )
169
+ Funlog.instance.fancyinfo_success("自己计算版本号: #{build_version}, Build: #{build_number}")
170
+ else
171
+ # 不是 Git 仓库且没有从 GitCommitTask 获取到版本号,跳过版本更新
172
+ Funlog.warning("非Git仓库且未从 GitCommitTask 获取到版本号,保持工程原有版本号")
173
+ return
174
+ end
175
+ end
163
176
 
177
+ # 更新版本号
164
178
  Pindo::XcodeBuildConfig.update_ios_project_version(
165
179
  project_dir: @project_path,
166
180
  version: build_version,
@@ -27,9 +27,15 @@ module Pindo
27
27
  # - ver_inc: 版本号增加类型,默认 :mini
28
28
  # - tag_type: 创建tag类型,默认 :new
29
29
  # - tag_pre: tag前缀,默认 'v'
30
- # - fixed_version: 外部指定的固定版本号,如果设置则跳过版本号计算
30
+ # - fixed_version: 外部指定的固定版本号
31
31
  # - process_type: 未提交文件的处理方式 ('skip', 'commit', 'reset', 'stash'),默认 'skip'
32
32
  # - commit_message: 提交消息,默认 'build: 构建产生提交'
33
+ #
34
+ # 版本号计算逻辑:
35
+ # 1. 如果 fixed_version 为 nil 且 HEAD 存在 tag 且工作目录干净,
36
+ # 自动设置 fixed_version 为 HEAD tag 的版本(在 check_gitignore 之前)
37
+ # 2. 执行 check_gitignore(可能创建新提交)
38
+ # 3. 最终使用 fixed_version(如果有)或计算新版本号
33
39
  def initialize(project_path, options = {})
34
40
  @release_branch = options[:release_branch] || 'master'
35
41
  @ver_inc = options[:ver_inc] || Pindo::VersionIncreaseType::MINI
@@ -70,10 +76,24 @@ module Pindo
70
76
  root_dir = @git_root_path
71
77
  git_repo_helper = Pindo::GitRepoHelper.share_instance
72
78
 
73
- # 1. 检查并修复 .gitignore
79
+ # 1. 如果 fixed_version 为 nil,尝试从 HEAD 的 tag 获取版本
80
+ # 必须在 check_gitignore 之前检查,因为 check_gitignore 可能创建提交导致 HEAD 移动
81
+ if (@fixed_version.nil? || @fixed_version.empty?) &&
82
+ git_repo_helper.head_has_version_tag?(project_dir: root_dir, tag_prefix: @tag_pre) &&
83
+ !Pindo::GitHandler.has_uncommitted_changes?(git_root_dir: root_dir)
84
+ # HEAD 有 tag 且工作目录干净,使用 tag 的版本
85
+ latest_tag = Pindo::GitHandler.get_latest_version_tag(
86
+ project_dir: root_dir,
87
+ tag_prefix: @tag_pre
88
+ )
89
+ @fixed_version = latest_tag.sub(/^#{@tag_pre}/, '') if latest_tag
90
+ Funlog.instance.fancyinfo_success("HEAD 存在 tag 且工作目录干净,设置 fixed_version: #{@fixed_version}")
91
+ end
92
+
93
+ # 2. 检查并修复 .gitignore(可能创建新提交,但 fixed_version 已经确定)
74
94
  git_repo_helper.check_gitignore(root_dir)
75
95
 
76
- # 2. 检查并处理未提交的文件(使用 GitHandler)
96
+ # 3. 检查并处理未提交的文件(使用 GitHandler)
77
97
  # process_type 已经在初始化时确定(由外部传入或默认为 skip)
78
98
  begin
79
99
  Pindo::GitHandler.process_need_add_files(
@@ -81,26 +101,29 @@ module Pindo
81
101
  process_type: @process_type || 'skip',
82
102
  commit_message: @commit_message
83
103
  )
84
- rescue Informative => e
104
+ rescue Pindo::Informative => e
85
105
  # 用户选择手动处理时,不需要重试
86
106
  if e.message.include?("请手动处理")
87
107
  @retry_count = 0
88
108
  end
89
- raise Informative "GitCommitTask 任务失败!"
109
+ # 重新抛出原始异常,保留错误信息
110
+ raise e
90
111
  end
91
112
 
92
- # 3. 获取当前分支
113
+ # 4. 获取当前分支
93
114
  coding_branch = get_current_branch_name
94
115
 
95
- # 4. 检查并推送本地提交到远程
116
+ # 5. 检查并推送本地提交到远程
96
117
  Pindo::GitHandler.check_unpushed_commits(project_dir: root_dir, branch: coding_branch)
97
118
 
98
- # 5. 计算 build_version
99
- # 如果指定了固定版本号,使用它;否则计算版本号
119
+ # 6. 计算 build_version
120
+ # 优先级 1: 如果指定了 fixed_version(外部传入或从 HEAD tag 获取),使用它
100
121
  if @fixed_version && !@fixed_version.empty?
101
122
  @build_version = @fixed_version
102
- @build_number = nil
103
- Funlog.instance.fancyinfo_success("版本号: #{@build_version}")
123
+ @build_number = git_repo_helper.get_build_number_from_commit(project_dir: root_dir)
124
+ Funlog.instance.fancyinfo_success("使用 fixed_version: #{@build_version}, Build: #{@build_number}")
125
+
126
+ # 优先级 2: 计算新版本号
104
127
  else
105
128
  @build_number = git_repo_helper.get_build_number_from_commit(project_dir: root_dir)
106
129
  @build_version = git_repo_helper.calculate_build_version(
@@ -109,18 +132,50 @@ module Pindo
109
132
  create_tag_type: @tag_type,
110
133
  version_increase_type: @ver_inc
111
134
  )
112
- Funlog.instance.fancyinfo_success("版本号: #{@build_version}, Build: #{@build_number}")
135
+ Funlog.instance.fancyinfo_success("计算新版本号: #{@build_version}, Build: #{@build_number}")
113
136
  end
114
137
 
115
138
  {
116
139
  success: true,
117
140
  root_dir: root_dir,
118
141
  current_branch: coding_branch,
142
+ message: "Git 提交检查完成"
143
+ }
144
+ end
145
+
146
+ # 构建任务参数(供其他任务使用)
147
+ def build_task_param
148
+ return {} unless @status == TaskStatus::SUCCESS
149
+
150
+ # 如果不是 Git 仓库,返回空参数(让依赖任务知道没有有效数据)
151
+ return {} if @build_version.nil? || @build_number.nil?
152
+
153
+ param = {
119
154
  release_branch: @release_branch,
120
155
  build_version: @build_version,
121
156
  build_number: @build_number,
122
- tag_pre: @tag_pre
157
+ tag_pre: @tag_pre,
158
+ tag_type: @tag_type,
159
+ ver_inc: @ver_inc
123
160
  }
161
+
162
+ # 添加 git commit 信息(供 JPSUploadMediaTask 等任务使用)
163
+ if @git_root_path
164
+ begin
165
+ # 获取当前 HEAD commit 信息
166
+ git_commit_info = Pindo::GitHandler.get_latest_conventional_commit(project_dir: @git_root_path)
167
+ if git_commit_info
168
+ param[:git_commit_id] = git_commit_info[:commit_id]
169
+ param[:git_commit_time] = git_commit_info[:commit_time]
170
+ param[:git_commit_desc] = git_commit_info[:commit_desc]
171
+ end
172
+ rescue => e
173
+ # 如果获取失败,不影响主流程
174
+ Funlog.instance.fancyinfo_warning("获取 git commit 信息失败: #{e.message}") if ENV['PINDO_DEBUG']
175
+ end
176
+ end
177
+
178
+ param
124
179
  end
125
180
  end
126
181
  end
@@ -27,13 +27,12 @@ module Pindo
27
27
  # - ver_inc: 版本号增加类型,默认 :mini
28
28
  # - tag_type: 创建tag类型,默认 :new
29
29
  # - tag_pre: tag前缀,默认 'v'
30
- # - fixed_version: 外部指定的固定版本号,如果设置则跳过版本号计算
30
+ # 注意:版本号从 GitCommitTask 获取(GitTagTask 必须依赖 GitCommitTask)
31
31
  def initialize(project_path, options = {})
32
32
  @release_branch = options[:release_branch] || 'master'
33
33
  @ver_inc = options[:ver_inc] || Pindo::VersionIncreaseType::MINI
34
34
  @tag_type = options[:tag_type] || Pindo::CreateTagType::NEW
35
35
  @tag_pre = options[:tag_pre] || 'v'
36
- @fixed_version = options[:fixed_version] # 外部指定的固定版本号
37
36
 
38
37
  @build_version = nil
39
38
  @build_number = nil
@@ -83,11 +82,20 @@ module Pindo
83
82
  )
84
83
  end
85
84
 
86
- # 3. 计算版本信息
87
- # 如果指定了固定版本号,使用它;否则计算版本号
88
- if @fixed_version && !@fixed_version.empty?
89
- @build_version = @fixed_version
90
- @build_number = nil
85
+ # 3. 获取版本信息
86
+ # 优先级 1: 从 GitCommitTask 获取所有版本相关参数(标准方式)
87
+ git_commit_data = get_data_param_by_key(:git_commit)
88
+ if git_commit_data && git_commit_data[:task_param] &&
89
+ git_commit_data[:task_param][:build_version] && git_commit_data[:task_param][:build_number]
90
+ @build_version = git_commit_data[:task_param][:build_version]
91
+ @build_number = git_commit_data[:task_param][:build_number]
92
+ @tag_pre = git_commit_data[:task_param][:tag_pre] if git_commit_data[:task_param][:tag_pre]
93
+ @release_branch = git_commit_data[:task_param][:release_branch] if git_commit_data[:task_param][:release_branch]
94
+ @tag_type = git_commit_data[:task_param][:tag_type] if git_commit_data[:task_param][:tag_type]
95
+ @ver_inc = git_commit_data[:task_param][:ver_inc] if git_commit_data[:task_param][:ver_inc]
96
+ Funlog.instance.fancyinfo_success("使用 GitCommitTask 的版本号: #{@build_version}, Build: #{@build_number}, Tag前缀: #{@tag_pre}, Tag类型: #{@tag_type}")
97
+
98
+ # 优先级 2: 自己计算(降级方案,用于向后兼容或 GitCommitTask 无有效数据)
91
99
  else
92
100
  @build_number = git_repo_helper.get_build_number_from_commit(project_dir: root_dir)
93
101
  @build_version = git_repo_helper.calculate_build_version(
@@ -96,6 +104,7 @@ module Pindo
96
104
  create_tag_type: @tag_type,
97
105
  version_increase_type: @ver_inc
98
106
  )
107
+ Funlog.instance.fancyinfo_warning("未找到 GitCommitTask 依赖,降级为自己计算版本号: #{@build_version}")
99
108
  end
100
109
 
101
110
  # 4. 创建并推送 Tag