Class: Pindo::BuildHelper
- Inherits:
-
Object
- Object
- Pindo::BuildHelper
show all
- Includes:
- Githelper, Singleton
- Defined in:
- lib/pindo/module/build/buildhelper.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Githelper
#add_branch, #add_tag, #add_tag_with_check, #clone_clang_repo, #clone_devclang_repo, #clone_pindo_common_config_repo, #clone_pindo_env_config_repo, #clong_buildconfig_repo, #get_repo_base_name, #getcode_to_dir, #git_addpush_repo, #git_latest_commit_id, #git_root_directory, #is_git_directory?, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag
Methods included from Executable
capture_command, #executable, execute_command, which, which!
Class Method Details
.share_instance ⇒ Object
12
13
14
|
# File 'lib/pindo/module/build/buildhelper.rb', line 12
def share_instance
instance
end
|
Instance Method Details
#add_git_cliffconfig(project_path) ⇒ Object
60
61
62
63
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
|
# File 'lib/pindo/module/build/buildhelper.rb', line 60
def add_git_cliffconfig(project_path)
temp_dir = Dir.pwd
Funlog.instance.fancyinfo_start("添加日志变更git-cliff配置...")
if is_git_directory?(local_repo_dir: project_path)
current_git_root_path = git_root_directory(local_repo_dir: project_path)
Dir.chdir(current_git_root_path)
pindo_common_dir = clone_pindo_common_config_repo(force_delete:false)
if File.exist?(File.join(pindo_common_dir, 'cliff.toml'))
FileUtils.cp_r(File.join(pindo_common_dir, 'cliff.toml'), File.join(current_git_root_path, 'cliff.toml'))
end
Funlog.instance.fancyinfo_update("仓库添加git-cliff配置")
write_gitignore(current_git_root_path)
Funlog.instance.fancyinfo_update("仓库添加.gitignore")
Dir.chdir(current_git_root_path)
current_branch = git!(%W(-C #{current_git_root_path} rev-parse --abbrev-ref HEAD)).strip
git!(%W(-C #{current_git_root_path} add cliff.toml))
git!(%W(-C #{current_git_root_path} add .gitignore))
commit_message = "docs: 添加日志变更配置".encode('UTF-8')
git!(%W(-C #{current_git_root_path} commit -m #{commit_message}))
git!(%W(-C #{current_git_root_path} push origin #{current_branch}))
else
Funlog.instance.fancyinfo_error("当前目录不是git仓库,请在git仓库根目录下执行此命令")
raise Informative, "当前目录不是git仓库,请在git仓库根目录下执行此命令"
Dir.chdir(temp_dir)
end
Funlog.instance.fancyinfo_success("日志变更git-cliff配置完成!")
Dir.chdir(temp_dir)
end
|
#android_project?(project_path) ⇒ Boolean
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/pindo/module/build/buildhelper.rb', line 187
def android_project?(project_path)
gradle_file = File.exist?(File.join(project_path, "build.gradle"))
settings_gradle = File.exist?(File.join(project_path, "settings.gradle"))
app_dir = File.directory?(File.join(project_path, "app"))
if gradle_file && settings_gradle && app_dir
app_gradle = File.exist?(File.join(project_path, "app", "build.gradle"))
app_manifest = File.exist?(File.join(project_path, "app", "src", "main", "AndroidManifest.xml"))
return true if app_gradle && app_manifest
end
if File.directory?(File.join(project_path, "src"))
manifest = File.join(project_path, "AndroidManifest.xml")
return true if File.exist?(manifest)
end
false
end
|
#check_check_and_install_cliff(project_path) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/pindo/module/build/buildhelper.rb', line 17
def check_check_and_install_cliff(project_path)
if is_git_directory?(local_repo_dir: project_path)
current_git_root_path = git_root_directory(local_repo_dir: project_path)
unless File.exist?(File.join(current_git_root_path, 'cliff.toml'))
add_git_cliffconfig(current_git_root_path)
end
end
begin
if !system('which git-cliff > /dev/null 2>&1')
puts "安装git-cliff..."
install_gitcliff()
end
rescue
raise Informative, "安装git-cliff出现错误"
end
end
|
#check_is_need_add_tag?(project_path) ⇒ Boolean
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
|
# File 'lib/pindo/module/build/buildhelper.rb', line 106
def check_is_need_add_tag?(project_path)
tag_action_parms = nil
is_need_add_tag = false
if is_git_directory?(local_repo_dir: project_path)
current_git_root_path = git_root_directory(local_repo_dir: project_path)
latest_tag = get_latest_version_tag(project_dir: current_git_root_path)
unless is_tag_at_head?(git_root_dir: current_git_root_path, tag_name: latest_tag)
cli = HighLine.new
= {
"新增版本号,打新Tag" => -> {
tag_action_parms = []
:new_tag
},
"将上次的Tag删除重新打Tag" => -> {
tag_action_parms = []
tag_action_parms << "--retag"
:recreate_tag
},
"不需要Tag继续编译且上传,手动修改上传备注" => -> {
puts ""
:continue_without_tag
},
"终止退出编译" => -> {
raise Informative, "终止退出编译!"
:exit
}
}
result = cli.choose do ||
. = "当前代码并没有打Tag,上传的Changelog需要Tag"
.prompt = "请选中打Tag的方式, 请输入选项(1/2/3...):"
.each do |option, action|
.choice(option) { action.call }
end
end
is_need_add_tag = !tag_action_parms.nil?
end
end
return [is_need_add_tag, tag_action_parms]
end
|
#get_project_name(project_path) ⇒ Object
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/pindo/module/build/buildhelper.rb', line 232
def get_project_name(project_path)
case project_type(project_path)
when :unity
File.basename(project_path)
when :ios
xcodeproj = Dir.glob(File.join(project_path, "*.xcodeproj")).first
File.basename(xcodeproj, ".xcodeproj") if xcodeproj
when :android
settings_gradle = File.join(project_path, "settings.gradle")
if File.exist?(settings_gradle)
content = File.read(settings_gradle)
if content =~ /rootProject\.name\s*=\s*['"](.+)['"]/
$1
else
File.basename(project_path)
end
else
File.basename(project_path)
end
else
File.basename(project_path)
end
end
|
#get_project_version(project_path) ⇒ Object
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
# File 'lib/pindo/module/build/buildhelper.rb', line 256
def get_project_version(project_path)
case project_type(project_path)
when :unity
version_file = File.join(project_path, "ProjectSettings", "ProjectVersion.txt")
if File.exist?(version_file)
content = File.read(version_file)
if content =~ /m_EditorVersion: (.*)/
$1.strip
end
end
when :ios
nil
when :android
nil
end
end
|
#install_gitcliff ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/pindo/module/build/buildhelper.rb', line 91
def install_gitcliff()
puts "\n检查git-cliff命令是否安装"
begin
if !system('which git-cliff > /dev/null 2>&1')
system('bash -c "$(curl -fsSL https://gitee.com/goodtools/env/raw/master/gitcliff_install.sh)"')
end
rescue
raise Informative, "安装git-cliff出现错误"
end
end
|
#ios_project?(project_path) ⇒ Boolean
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/pindo/module/build/buildhelper.rb', line 164
def ios_project?(project_path)
xcodeproj_files = Dir.glob(File.join(project_path, "*.xcodeproj"))
workspace_files = Dir.glob(File.join(project_path, "*.xcworkspace"))
return false if xcodeproj_files.empty? && workspace_files.empty?
if !xcodeproj_files.empty?
project_file = File.join(xcodeproj_files.first, "project.pbxproj")
return true if File.exist?(project_file)
end
if !workspace_files.empty?
contents_file = File.join(workspace_files.first, "contents.xcworkspacedata")
return true if File.exist?(contents_file)
end
false
end
|
#project_type(project_path) ⇒ Object
209
210
211
212
213
214
215
216
217
|
# File 'lib/pindo/module/build/buildhelper.rb', line 209
def project_type(project_path)
raise ArgumentError, "项目路径不能为空" if project_path.nil? || project_path.empty?
raise ArgumentError, "项目路径不存在: #{project_path}" unless File.directory?(project_path)
return :unity if unity_project?(project_path)
return :ios if ios_project?(project_path)
return :android if android_project?(project_path)
:unknown
end
|
#project_type_name(project_path) ⇒ Object
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/pindo/module/build/buildhelper.rb', line 219
def project_type_name(project_path)
case project_type(project_path)
when :unity
"Unity"
when :ios
"iOS"
when :android
"Android"
else
"Unknown"
end
end
|
#unity_project?(project_path) ⇒ Boolean
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/pindo/module/build/buildhelper.rb', line 151
def unity_project?(project_path)
project_settings_path = File.join(project_path, "ProjectSettings")
assets_path = File.join(project_path, "Assets")
packages_path = File.join(project_path, "Packages")
File.directory?(project_settings_path) &&
File.directory?(assets_path) &&
File.directory?(packages_path) &&
File.exist?(File.join(project_settings_path, "ProjectSettings.asset"))
end
|
#write_gitignore(git_root_dir) ⇒ Object
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/module/build/buildhelper.rb', line 35
def write_gitignore(git_root_dir)
gitignore_path = File.join(git_root_dir, '.gitignore')
gitignore_content = " # Build logs\n build_ios.log\n CHANGELOG.md\n\n # Platform specific directories\n /GoodPlatform/iOS/config.json\n /GoodPlatform/iOS/*\n /GoodPlatform/Android/*\n /GoodPlatform/MacOS/*\n /GoodPlatform/BaseiOS/Unity/*\n /GoodPlatform/BaseiOS/Pods/\n /GoodPlatform/BaseiOS/Podfile.lock\n /GoodPlatform/BaseAndroid/Unity/*\n /GoodPlatform/BaseMac/Unity/*\n GITIGNORE\n # Append to existing .gitignore or create new one\n File.open(gitignore_path, 'a') do |f|\n f.puts(\"\\n# Added by Pindo\")\n f.puts(gitignore_content)\n end\nend\n"
|