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
146
147
148
149
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/pindo/command/unity/packbuild.rb', line 68
def run
package_dir = Dir.pwd
git_commit_opt = Pindo::Options::GitOptions.parse_git_commit_type(@options[:git_commit]) || Pindo::UncommittedFilesProcessType::COMMIT
process_type = Pindo::GitHandler.get_uncommitted_files_process_type(
project_dir: package_dir,
interactive: false,
default_process_type: git_commit_opt
)
if process_type == Pindo::UncommittedFilesProcessType::NONE
process_type = Pindo::UncommittedFilesProcessType::COMMIT
end
Funlog.instance.fancyinfo_start("Unity Package 打包流程")
task_manager = Pindo::TaskSystem::TaskManager.instance
task_manager.clear_all
tasks = []
Pindo::Unity::NugetHelper.nuget_init(package_dir)
nuspec_file = Pindo::Unity::NugetHelper.find_nuspec_file(package_dir)
unless nuspec_file
raise Informative, "初始化后仍未找到 .nuspec 文件,无法继续"
end
nuspec_info = Pindo::Unity::NugetHelper.parse_nuspec(nuspec_file)
q = nuspec_info['version']
tag_name = "#{@args_tag_pre}#{q}"
tag_at_head = Pindo::GitHandler.local_tag_exists?(local_repo_dir: package_dir, tag_name: tag_name) &&
Pindo::GitHandler.is_tag_at_head?(git_root_dir: package_dir, tag_name: tag_name)
if tag_at_head
confirmed_version = q
puts ""
Funlog.instance.fancyinfo_update("检测到 tag #{tag_name} 已存在并指向当前 HEAD,直接使用版本号: #{q.yellow}")
else
puts ""
puts "即将编译 NuGet Package 的版本是 #{q.yellow}"
if agree("确认是否继续? (Y/n)")
confirmed_version = q
else
puts ""
confirmed_version = ask("请输入新的打包版本号: ") { |q| q.required = true }.to_s.strip
end
if confirmed_version.empty?
raise Informative, "版本号不能为空"
end
end
if confirmed_version != q
Funlog.instance.fancyinfo_update("更新配置文件版本号: #{confirmed_version}")
nuspec_info['version'] = confirmed_version
doc = Nokogiri::XML(File.read(nuspec_file))
doc.remove_namespaces!
metadata = doc.at_xpath('//metadata')
version_node = metadata.at_xpath('version')
if version_node
version_node.content = confirmed_version
File.write(nuspec_file, doc.to_xml)
end
Pindo::Unity::NugetHelper.update_package_json_from_nuspec(nuspec_info, package_dir)
Funlog.instance.fancyinfo_success("版本号已更新")
end
puts ""
Funlog.instance.fancyinfo_start("生成 #{confirmed_version} 版本 Release Notes")
release_notes = Pindo::Unity::NugetHelper.generate_release_notes_from_git(package_dir, nuspec_version: confirmed_version)
if release_notes && !release_notes.empty?
Pindo::Unity::NugetHelper.update_nuspec_release_notes(nuspec_file, release_notes)
Funlog.instance.fancyinfo_success("已更新 .nuspec 的 releaseNotes 字段")
else
Funlog.instance.fancyinfo_update("未生成 Release Notes,将使用 .nuspec 中已有的内容")
end
git_commit_task = Pindo::TaskSystem::GitCommitTask.new(
package_dir,
release_branch: @args_release_branch,
ver_inc: @args_ver_inc, tag_type: @args_tag_type,
tag_pre: @args_tag_pre,
process_type: process_type,
commit_message: "chore: packbuild 更新 v#{confirmed_version} Release Notes",
fixed_version: confirmed_version )
tasks << git_commit_task
nuget_build_task = Pindo::TaskSystem::NugetBuildTask.new(
project_path: package_dir
)
nuget_build_task.dependencies << git_commit_task.id
tasks << nuget_build_task
git_tag_task = Pindo::TaskSystem::GitTagTask.new(package_dir)
git_tag_task.dependencies << nuget_build_task.id
git_tag_task.dependencies << git_commit_task.id
tasks << git_tag_task
tasks.each { |task| task_manager.add_task(task) }
task_manager.start
if nuget_build_task.status == :success && nuget_build_task.result
nupkg_file = nuget_build_task.result[:nupkg_file]
puts ""
Funlog.instance.fancyinfo_success("打包完成")
puts " 📦 生成文件: #{File.basename(nupkg_file)}"
puts " 📁 完整路径: #{nupkg_file}"
puts ""
Funlog.instance.fancyinfo_update("下一步: 运行 pindo unity packpush 上传到 JPS")
end
end
|