forked from tangqiaoboy/xcode_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdailyBuild.sh
executable file
·308 lines (270 loc) · 7.93 KB
/
dailyBuild.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/bin/bash
#
# This is the daily build script for an iOS project.
#
# Author: Tang Qiao
#
function usage() {
echo "Usage:"
echo " dailyBuild.sh [target] [server] [tag]"
echo "Argument:"
echo " target - the build target name"
echo " server - the server type, valid value are 'test_www', 'test_ape', 'online_ape' and 'online' "
echo " tag - optional. if tag is not empty, the ipa file will be put the tags directory instead of year/month directory"
echo "Example:"
echo " dailyBuild.sh Ape_kyzz test_www"
echo " dailyBuild.sh Ape_kyzz test_ape"
echo " dailyBuild.sh Ape_kyzz online_ape"
echo " dailyBuild.sh Ape_kyzz online"
echo ""
echo "Tag Example:"
echo " dailyBuild.sh Ape_kyzz test_www iPhone_1.0.0"
exit 1
}
function processIcon() {
echo "process icon: $1"
targetIcon=$1
if [[ ! -f $targetIcon ]]; then
echo "$targetIcon is not exist"
return
fi
width=`identify -format %w ${targetIcon}`
build_date=$(date +%y%m%d)
convert -background '#0008' -fill white -gravity center -size %${width}x40\
caption:"${ICON_NAME} ${build_date}"\
${targetIcon} +swap -gravity south -composite ${targetIcon}
}
function checkDependency() {
command -v convert >/dev/null 2>&1 || { echo "please: brew install imagemagick" >&2; exit 1; }
command -v identify >/dev/null 2>&1 || { echo "please: brew install ghostscript" >&2; exit 1; }
}
if [ $# -lt 2 ]; then
usage
fi
checkDependency
TARGET=$1
SERVER=$2
TAG_NAME=$3
OUTPUT_PATH="[email protected]:/var/www/apps/"
HTTP_TARGET="http://app.zhenguanyu.com"
PROJECT_HOME=`pwd`
BUILD_PATH="$PROJECT_HOME/build"
FOLDER_PREFIX="iphone"
# get bundle id
PROJECT_PLIST=`find . -type f -name "${TARGET}-Info.plist" -depth 2`
BUNDLE_ID=`grep "com.fenbi" $PROJECT_PLIST | head -1`
# remove the prefix <string> and suffix </string> and trim blankspaces
BUNDLE_ID=${BUNDLE_ID#*string>}
BUNDLE_ID=${BUNDLE_ID%</string>*}
if [ "$BUNDLE_ID" != "" ]; then
echo "bundle id = $BUNDLE_ID"
else
echo "bundle id is not found"
exit 1
fi
## clear old data
cd $PROJECT_HOME
rm -rf $BUILD_PATH
## set configuration
CONFIGURATION=""
ICON_NAME=""
if [ $SERVER == "test_www" ]; then
CONFIGURATION="Debug_www"
ICON_NAME="twww"
elif [ $SERVER == "test_ape" ]; then
CONFIGURATION="Debug_ape"
ICON_NAME="tape"
elif [ $SERVER == "online_ape" ]; then
CONFIGURATION="Online_ape"
ICON_NAME="oape"
elif [ $SERVER == "online" ]; then
CONFIGURATION="Online"
ICON_NAME="owww"
else
echo "CONFIGURATION is not valid"
usage
exit 1
fi
## set .git log info
if [[ -d "$PROJECT_HOME/.git" ]]; then
GIT_VERSION=$(git log --oneline -1 | cut -d" " -f1)
COMMIT_LOG=`git log -7`
fi
echo "GIT_VERSION = $GIT_VERSION"
# mark build info to icon file
ICON_DONE="NO"
echo "mark build info to icon files..."
for file in $( find $TARGET -type f -name "Icon*.png" )
do
processIcon $file
ICON_DONE="YES"
done
if [[ "$ICON_DONE" == "NO" ]]; then
for file in $( find . -type f -name "Icon*.png" )
do
processIcon $file
done
fi
## build
echo "building...it will take several minutes."
xcodebuild -configuration $CONFIGURATION -target "$TARGET" > /dev/null
BUILD_RES=$?
# mark build info to icon file
echo "recovery icon files..."
if [[ "$ICON_DONE" == "NO" ]]; then
for file in $( find . -not -path "./build/*" -type f -name "Icon*.png" )
do
git checkout $file
done
else
for file in $( find $TARGET -type f -name "Icon*.png" )
do
git checkout $file
done
fi
## check result
echo "BUILD_RES=$BUILD_RES"
if [ $BUILD_RES -ne 0 ]; then
echo "Failed to build dailyBuild"
exit 1
fi
if [ ! -d "$BUILD_PATH/${CONFIGURATION}-iphoneos" ]; then
echo "${CONFIGURATION}-iphoneos directory is not exist"
exit 1
fi
# get file name
PRODUCT_NAME=`find build -type dir -name "*.app"`
PRODUCT_NAME=`basename $PRODUCT_NAME`
if [ $PRODUCT_NAME == "" ]; then
echo "can not get product name"
exit 1
fi
# create ipa folder
FILE_NAME="${TARGET}_$(date +%y%m%d-%H%M)_r${GIT_VERSION}.ipa"
echo "build file using specified name: $FILE_NAME"
cd $BUILD_PATH
mkdir -p ipa/Payload
cp -r ./${CONFIGURATION}-iphoneos/$PRODUCT_NAME ./ipa/Payload/
# create ipa file
echo "creating $FILE_NAME"
cd ipa
zip -rq $FILE_NAME *
# create dSYM file
echo "creating dSYM.zip"
cd $BUILD_PATH/${CONFIGURATION}-iphoneos/
zip -rq dSYM.zip ${PRODUCT_NAME}.dSYM
# generate output folder
if [ "${TAG_NAME}" == "" ]; then
YEAR=$(date +%Y)
MONTH=$(date +%m)
FOLDER="${FOLDER_PREFIX}/${TARGET}/${YEAR}/${MONTH}/${TARGET}_${SERVER}_$(date +%y%m%d-%H%M)"
else
FOLDER="${FOLDER_PREFIX}/${TARGET}/tags/${TARGET}_${SERVER}_${TAG_NAME}"
fi
echo "Output folder=${FOLDER}"
# copy ipa & dsym
cd $BUILD_PATH
mkdir -p $FOLDER
cp ipa/$FILE_NAME $FOLDER/
cp ${CONFIGURATION}-iphoneos/dSYM.zip $FOLDER/
# copy icon
ICON_FILE=`find . -type f -name "[iI]con.png" | head -1`
if [ "$ICON_FILE" == "" ]; then
echo "icon file is not exit"
exit 1
fi
cp $ICON_FILE $FOLDER/icon.png
# Create install html
cd $FOLDER
PLIST_PATH="/${FOLDER}/appInfo.plist"
# ${str//apple/APPLE} # 替换所有apple,这里的apple是/,被转义成\/
PLIST_PATH=${PLIST_PATH//\//%2f}
cat << EOF > index.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>安装此软件</title>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0"/>
</head>
<body>
<h1><center>$PRODUCT_NAME Daily Build</center></h1>
<hr />
<ul>
<li>iOS设备直接安装:<a href="itms-services://?action=download-manifest&url=${HTTP_TARGET}${PLIST_PATH}">点击这里安装</a></li>
</ul>
<p>
<ul>
<li>下载此软件的ipa包:<br/><a href="${HTTP_TARGET}/${FOLDER}/$FILE_NAME">$FILE_NAME</a></li>
</ul>
<ul>
<li>下载此软件的dSYM文件:<br/><a href="${HTTP_TARGET}/${FOLDER}/dSYM.zip">dSYM.zip</a></li>
</ul>
<hr />
<p>
<br />
最近的提交Log:
<pre>$COMMIT_LOG
</pre>
</body>
</html>
EOF
cat << EOF > appInfo.plist
<?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>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>${HTTP_TARGET}/${FOLDER}/$FILE_NAME</string>
</dict>
<dict>
<key>kind</key>
<string>display-image</string>
<key>needs-shine</key>
<true/>
<key>url</key>
<string>${HTTP_TARGET}/${FOLDER}/icon.png</string>
</dict>
<dict>
<key>kind</key>
<string>full-size-image</string>
<key>needs-shine</key>
<true/>
<key>url</key>
<string>${HTTP_TARGET}/${FOLDER}/icon.png</string>
</dict>
</array><key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>$BUNDLE_ID</string>
<key>bundle-version</key>
<string>1.0</string>
<key>kind</key>
<string>software</string>
<key>subtitle</key>
<string>$PRODUCT_NAME</string>
<key>title</key>
<string>$PRODUCT_NAME</string>
</dict>
</dict>
</array>
</dict>
</plist>
EOF
# create latest link
cd "$BUILD_PATH/$FOLDER_PREFIX/$TARGET"
mkdir latest
find . -type f -name "appInfo.plist" | xargs -J % cp % latest/
cd $BUILD_PATH
if [ "$OUTPUT_PATH" != "" ]; then
scp -r $FOLDER_PREFIX ${OUTPUT_PATH}
fi
echo "Daily build for $PRODUCT_NAME completed!"