-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shell.sh
280 lines (231 loc) · 7.53 KB
/
Shell.sh
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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/bin/sh
# ============项目配置信息============"
# 工程名称
name_project="qizuang"
# 工程Scheme
name_scheme="qizuang"
# AppStore上传使用秘钥
AppStore_key="23JS8279KH";
AppStore_issuer="de2a9f39-f5f8-4416-825e-4b4d34b11cb3";
# 蒲公英发布Ukey、Api_key
PGY_UKey="a3905abac345ec2ed6e65484378786e4";
PGY_AKey="1598c6d546afe087a297d4a5226ee3bd";
# 项目路径、配置文件路径
# path_project="/Users/Home/Desktop/SourceTree/app_qz_ios/qizuang"
path_project="/Users/Home/Desktop/iOS/SwiftUI"
path_plist="/Users/Home/Pictures/AutoTool/ExportOptions.plist"
# ========================《验证路径信息》=======================
# 项目文件是否存在
if [ ! -e ${path_project} ];then
echo "=================================="
echo " 打包项目文件路径无效 ";
echo "=================================="
exit;
fi
# 导出配置文件是否存在
if [ ! -e ${path_plist} ];then
echo "=================================="
echo " 导出配置文件路径无效 ";
echo "=================================="
exit;
fi
# ========================《操作方式选择》=========================
# 选择打包方式
Tag_output=0;
while ([ ${Tag_output} != 1 ] && [ ${Tag_output} != 2 ] &&
[ ${Tag_output} != 3 ] && [ ${Tag_output} != 4 ]) do
echo "选择发布方式(输入序号) 【 1:AppStore 2:Ad-Hoc 3:Enterprise 4:Development 】\n"
read Tag_output
done
# 选择编译方式
if [ "${Tag_output}" != 1 ];then
Tag_build=0;
while ([ ${Tag_build} != 1 ] && [ ${Tag_build} != 2 ]) do
echo "选择编译方式(输入序号) 【 1:Release 2:Debug 】\n"
read Tag_build
done
fi
# 选择发布方式
if [ "${Tag_output}" != 1 ];then
Tag_upload=0;
while ([ ${Tag_upload} != 1 ] && [ ${Tag_upload} != 2 ]) do
echo "选择发布方式(输入序号) 【 1:蒲公英 2:不发布 】\n"
read Tag_upload
done
fi
# ========================《配置导出文件》=========================
# 编译方式
if [ "${Tag_output}" == 1 -o "${Tag_build}" == 1 ];then
configuration="Release";
else
configuration="Debug";
fi
# 打包方式
case ${Tag_output} in
1) method="app-store";;
2) method="ad-hoc";;
3) method="enterprise";;
4) method="development";;
esac
/usr/libexec/PlistBuddy -c "Set :method ${method}" ${path_plist}
# ========================《设置文件路径》=========================
# 桌面路径
desktop=$(cd ~/Desktop/;pwd)
# 打包路径
package="${desktop}/package"
# 当前时间
dateStr=$(date '+%Y-%m-%d-%H:%M:%S')
# 导出目录
path_export="${package}/${dateStr}"
# 归档文件
path_archive="${path_export}/${name_project}.xcarchive"
# ipa文件
path_ipa="${path_export}/${name_project}.ipa"
cd ${path_project}
# ========================《开始打包操作》=========================
echo "============开始清洁工程============"
echo "\n\n\n"
xcodebuild clean -configuration ${configuration} -quiet
# 工程清洁结果
if [ $? = 0 ];then
echo "****** Clean Success ******";
echo "====================================";
else
echo "****** Clean Failure ******";
echo "====================================";
exit
fi
echo "============开始编译工程============"
echo "\n\n"
# 项目是否使用cocoapods 管理
if [ -e "${name_project}.xcworkspace" ];then
# 编译文件路径
path_workspace="${path_project}/${name_project}.xcworkspace"
# 打包命令
xcodebuild OTHER_CFLAGS="-fembed-bitcode" \
archive \
-scheme ${name_scheme} \
-workspace ${path_workspace} \
-configuration ${configuration} \
-archivePath ${path_archive} -quiet
elif [ -e "${name_project}.xcodeproj" ];then
# 编译文件路径
path_xcodeproj="${path_project}/${name_project}.xcodeproj"
# 打包命令
xcodebuild OTHER_CFLAGS="-fembed-bitcode" \
archive \
-scheme ${name_scheme} \
-project ${path_xcodeproj} \
-configuration ${configuration} \
-archivePath ${path_archive} -quiet
else
echo "****** 当前目录缺少工程文件 ******";
echo "====================================";
exit
fi
# 工程编译结果
if [ -e ${path_archive} -a $?=0 ];then
echo "\n\n"
echo "****** Archive Success ******";
echo "====================================";
else
echo "\n\n"
echo "****** Archive Failure ******";
echo "====================================";
exit
fi
echo "============开始导出工程============"
echo "\n\n"
# 导出命令
xcodebuild OTHER_CFLAGS="-fembed-bitcode" \
-exportArchive \
-archivePath ${path_archive} \
-configuration ${configuration} \
-exportPath ${path_export} \
-exportOptionsPlist ${path_plist} -quiet
# 导出安装包是否成功
if [ -e ${path_ipa} -a $?=0 ];then
echo "\n\n"
echo "****** Export Success ******";
echo "====================================";
else
echo "\n\n"
echo "****** Export Failure ******";
echo "====================================";
exit
fi
# ========================《安装包操作函数》=========================
# AppStore验证App
function validate_appStore(){
echo "==========AppStore(验证APP)========="
echo "\n\n"
# AppStore验证命令
xcrun altool --validate-app -f $ipa_path -t ios --apiKey $AppStore_key --apiIssuer $AppStore_issuer -quiet
# AppStore验证结果
if [ $? != 0 ];then
echo "\n\n"
echo "****** AppStore验证失败 ******";
echo "====================================";
else
echo "\n\n"
echo "****** AppStore验证成功 ******";
echo "====================================";
fi
}
# AppStore上传APP
function upload_appStore(){
echo "==========AppStore(上传APP)========="
echo "\n\n"
# AppStore上传命令
xcrun altool --upload-app -f $ipa_path -t ios --apiKey $AppStore_key --apiIssuer $AppStore_issuer -quiet
# AppStore上传结果
if [ $? != 0 ];then
echo "\n\n"
echo "****** AppStore上传失败 ******";
echo "====================================";
else
echo "\n\n"
echo "****** AppStore上传成功 ******";
echo "====================================";
fi
}
# 蒲公英上传App
function upload_pgy(){
echo "=============蒲公英发布============="
echo "\n\n"
# 蒲公英发布命令
RESULT=$(curl \
-F "file=@${path_ipa}" \
-F "uKey=${PGY_UKey}" \
-F "_api_key=${PGY_AKey}" \
http://www.pgyer.com/apiv1/app/upload)
# 命令执行失败
if [ $? != 0 ];then
echo "\n\n"
echo "****** 蒲公英发布失败 ******";
echo "====================================";
exit;
fi
# 蒲公英发布结果
code=`echo $RESULT | awk -F 'code\":' '{print $2}'| awk -F ',' '{print $1}'`;
if [ "${code}" = 0 ];then
echo "\n\n"
echo "****** 蒲公英发布成功 ******";
echo "====================================";
else
echo "\n\n"
echo "****** 蒲公英发布失败 ******";
echo "====================================";
fi
}
# ipa发布流程
if [ "${Tag_output}" = 1 ];then
validate_appStore
if [ $? != 0 ];then
upload_appStore
fi
elif [ "${Tag_upload}" = 1 ];then
upload_pgy
else
exit;
fi