-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patharchive_macos.rb
More file actions
142 lines (126 loc) · 3.97 KB
/
archive_macos.rb
File metadata and controls
142 lines (126 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
59
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
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
#!/usr/bin/ruby
require_relative "./upload_app.rb"
require_relative "./color_log.rb"
puts "-------------------------------------------------"
puts "| ARCHIVE TASK |"
puts "-------------------------------------------------"
puts "🚗 Start exec archive macos script 🚗"
puts "👉 Current exec directory is: #{Dir.pwd}"
cur_path = Dir.pwd
output_dir = "./Build"
# 证书的id
DISTRIBUTION_CODE_SIGN_IDENTITY = "Apple Distribution: Haihuman Technology Co., Ltd. (M69DRNUMV4)"
DEVELOPER_CODE_SIGN_IDENTITY = "Apple Development: le huang (WSJL265X98)"
ARCHIVE_METHOD = "mac-application"
TEAM_ID = "M69DRNUMV4"
has_xcwrokspace = false
open_proj_path = ""
proj_full_name = ""
Dir::glob("*.xcworkspace") do |name|
has_xcwrokspace = true
open_proj_path = name
proj_full_name = File.basename(name)
end
if has_xcwrokspace == false
Dir::glob("*.xcodeproj") do |name|
open_proj_path = name
proj_full_name = File.basename(name)
end
end
puts yellow_text("Find a valid project named: #{white_text(proj_full_name)}")
# target名字
target_name = File.basename(open_proj_path, ".*")
# 先清理项目
puts yellow_text("First clean the target #{white_text(target_name)} 🧹 ...")
if has_xcwrokspace then
`xcodebuild clean \
-workspace #{proj_full_name} \
-scheme #{target_name} \
-configuration Release`
else
`xcodebuild clean \
-project #{proj_full_name} \
-scheme #{target_name} \
-configuration Release`
end
# pod
pod_file = "Podfile"
pod_ret = false
if File::exist?(pod_file)
puts yellow_text("🧠 Find a podfile, next step is exec #{green_text('pod install')}")
pod_ret = system("pod install")
end
if pod_ret == false
return
end
# 构建
puts yellow_text("💼 Start the archive task ...")
archive_path = output_dir + "/#{target_name}"
archive_full_path = archive_path + ".xcarchive"
archive_ret = false
if has_xcwrokspace then
archive_ret = system("xcodebuild archive -workspace #{proj_full_name} \
-scheme #{target_name} \
-configuration Release \
-archivePath #{archive_path} \
-arch x86_64 \
-quiet
")
else
archive_ret = system("xcodebuild archive -project #{proj_full_name} \
-scheme #{target_name} \
-configuration Release \
-archivePath #{archive_path} \
-arch x86_64 \
-quiet
")
end
if archive_ret == true then
puts green_text("Successfuly archived in path => #{white_text(archive_path)}")
else
puts red_text("Archived in failded")
return
end
# 生成ipa
puts yellow_text("📦 Start generate IPA packet ...")
# 判断是否存在exportPlist文件
export_options_plist_name = "exprotOptionsPlist.plist"
if File::exist?(export_options_plist_name)
File::delete(export_options_plist_name)
end
puts yellow_text("Start create file #{white_text(export_options_plist_name)}")
`touch #{export_options_plist_name}`
File.open("#{export_options_plist_name}", "w+") do |f|
f.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>teamID</key>
<string>#{TEAM_ID}</string>
<key>method</key>
<string>#{ARCHIVE_METHOD}</string>
<key>compileBitcode</key>
<false/>
</dict>
</plist>")
end
# 开始导出APP
puts yellow_text("Start export app ⛓️ ...")
export_ret = false
export_ret = system("xcodebuild -exportArchive \
-archivePath #{archive_full_path} \
-exportPath #{output_dir} \
-exportOptionsPlist #{export_options_plist_name}
")
if export_ret == true then
puts yellow_text("👏 App had exported in directory => #{white_text(output_dir)}")
else
puts red_text("Exported in failded")
return
end
# 删除archive包
puts yellow_text("🚛 Delete the useless archive file #{white_text(archive_full_path)}")
`rm -rf #{archive_full_path}`
puts green_text("💪 Now, Archive work is all finished!")
# 开始上传app
upload("#{output_dir}/#{target_name}.app")