Skip to content

Commit a1f4c75

Browse files
author
Tang Qiao
committed
ADD: add dailyBuild script & convert image size script.
1 parent e648e1f commit a1f4c75

File tree

2 files changed

+353
-0
lines changed

2 files changed

+353
-0
lines changed

Shells/convertImage.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#! /bin/bash
2+
3+
# print usage
4+
usage() {
5+
cat << EOF
6+
Usage:
7+
convertImage.sh <src directory> <dest directory>
8+
EOF
9+
}
10+
11+
if [ $# -ne 2 ]; then
12+
usage
13+
exit 1
14+
fi
15+
16+
SRC_DIR=$1
17+
DEST_DIR=$2
18+
19+
# check src dir
20+
if [ ! -d $SRC_DIR ]; then
21+
echo "src directory not exist: $SRC_DIR"
22+
exit 1
23+
fi
24+
25+
# check dest dir
26+
if [ ! -d $DEST_DIR ]; then
27+
mkdir -p $DEST_DIR
28+
fi
29+
30+
for src_file in $SRC_DIR/*.* ; do
31+
echo "process file name: $src_file"
32+
# 获得去掉文件名的纯路径
33+
src_path=`dirname $src_file`
34+
# 获得去掉路径的纯文件名
35+
filename=`basename $src_file`
36+
# 获得文件名字(不包括扩展名)
37+
name=`echo "$filename" | cut -d'.' -f1`
38+
# remove @2x in filename if there is
39+
name=`echo "$name" | cut -d"@" -f1`
40+
# 获得文件扩展名
41+
extension=`echo "$filename" | cut -d'.' -f2`
42+
dest_file="$DEST_DIR/${name}.${extension}"
43+
44+
convert $src_file -resize 50% $dest_file
45+
done

Shells/dailyBuild.sh

Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
#!/bin/bash
2+
#
3+
# This is the daily build script for an iOS project.
4+
#
5+
# Author: Tang Qiao
6+
#
7+
8+
function usage() {
9+
echo "Usage:"
10+
echo " dailyBuild.sh [target] [server] [tag]"
11+
echo "Argument:"
12+
echo " target - the build target name"
13+
echo " server - the server type, valid value are 'test_www', 'test_ape', 'online_ape' and 'online' "
14+
echo " tag - optional. if tag is not empty, the ipa file will be put the tags directory instead of year/month directory"
15+
echo "Example:"
16+
echo " dailyBuild.sh Ape_kyzz test_www"
17+
echo " dailyBuild.sh Ape_kyzz test_ape"
18+
echo " dailyBuild.sh Ape_kyzz online_ape"
19+
echo " dailyBuild.sh Ape_kyzz online"
20+
echo ""
21+
echo "Tag Example:"
22+
echo " dailyBuild.sh Ape_kyzz test_www iPhone_1.0.0"
23+
exit 1
24+
}
25+
26+
function processIcon() {
27+
echo "process icon: $1"
28+
targetIcon=$1
29+
if [[ ! -f $targetIcon ]]; then
30+
echo "$targetIcon is not exist"
31+
return
32+
fi
33+
width=`identify -format %w ${targetIcon}`
34+
build_date=$(date +%y%m%d)
35+
convert -background '#0008' -fill white -gravity center -size %${width}x40\
36+
caption:"${ICON_NAME} ${build_date}"\
37+
${targetIcon} +swap -gravity south -composite ${targetIcon}
38+
}
39+
40+
function checkDependency() {
41+
command -v convert >/dev/null 2>&1 || { echo "please: brew install imagemagick" >&2; exit 1; }
42+
command -v identify >/dev/null 2>&1 || { echo "please: brew install ghostscript" >&2; exit 1; }
43+
}
44+
45+
46+
if [ $# -lt 2 ]; then
47+
usage
48+
fi
49+
50+
checkDependency
51+
52+
TARGET=$1
53+
SERVER=$2
54+
TAG_NAME=$3
55+
56+
OUTPUT_PATH="fenbi@192.168.0.102:/var/www/apps/"
57+
HTTP_TARGET="http://app.zhenguanyu.com"
58+
59+
PROJECT_HOME=`pwd`
60+
BUILD_PATH="$PROJECT_HOME/build"
61+
FOLDER_PREFIX="iphone"
62+
63+
# get bundle id
64+
PROJECT_PLIST=`find . -type f -name "${TARGET}-Info.plist" -depth 2`
65+
BUNDLE_ID=`grep "com.fenbi" $PROJECT_PLIST | head -1`
66+
# remove the prefix <string> and suffix </string> and trim blankspaces
67+
BUNDLE_ID=${BUNDLE_ID#*string>}
68+
BUNDLE_ID=${BUNDLE_ID%</string>*}
69+
if [ "$BUNDLE_ID" != "" ]; then
70+
echo "bundle id = $BUNDLE_ID"
71+
else
72+
echo "bundle id is not found"
73+
exit 1
74+
fi
75+
76+
## clear old data
77+
cd $PROJECT_HOME
78+
rm -rf $BUILD_PATH
79+
80+
## set configuration
81+
CONFIGURATION=""
82+
ICON_NAME=""
83+
if [ $SERVER == "test_www" ]; then
84+
CONFIGURATION="Debug_www"
85+
ICON_NAME="twww"
86+
elif [ $SERVER == "test_ape" ]; then
87+
CONFIGURATION="Debug_ape"
88+
ICON_NAME="tape"
89+
elif [ $SERVER == "online_ape" ]; then
90+
CONFIGURATION="Online_ape"
91+
ICON_NAME="oape"
92+
elif [ $SERVER == "online" ]; then
93+
CONFIGURATION="Online"
94+
ICON_NAME="owww"
95+
else
96+
echo "CONFIGURATION is not valid"
97+
usage
98+
exit 1
99+
fi
100+
101+
## set .git log info
102+
if [[ -d "$PROJECT_HOME/.git" ]]; then
103+
GIT_VERSION=$(git log --oneline -1 | cut -d" " -f1)
104+
COMMIT_LOG=`git log -7`
105+
fi
106+
echo "GIT_VERSION = $GIT_VERSION"
107+
108+
# mark build info to icon file
109+
ICON_DONE="NO"
110+
echo "mark build info to icon files..."
111+
for file in $( find $TARGET -type f -name "Icon*.png" )
112+
do
113+
processIcon $file
114+
ICON_DONE="YES"
115+
done
116+
if [[ "$ICON_DONE" == "NO" ]]; then
117+
for file in $( find . -type f -name "Icon*.png" )
118+
do
119+
processIcon $file
120+
done
121+
fi
122+
123+
## build
124+
echo "building...it will take several minutes."
125+
xcodebuild -configuration $CONFIGURATION -target "$TARGET" > /dev/null
126+
BUILD_RES=$?
127+
128+
129+
# mark build info to icon file
130+
echo "recovery icon files..."
131+
if [[ "$ICON_DONE" == "NO" ]]; then
132+
for file in $( find . -not -path "./build/*" -type f -name "Icon*.png" )
133+
do
134+
git checkout $file
135+
done
136+
else
137+
for file in $( find $TARGET -type f -name "Icon*.png" )
138+
do
139+
git checkout $file
140+
done
141+
fi
142+
143+
## check result
144+
echo "BUILD_RES=$BUILD_RES"
145+
if [ $BUILD_RES -ne 0 ]; then
146+
echo "Failed to build dailyBuild"
147+
exit 1
148+
fi
149+
150+
if [ ! -d "$BUILD_PATH/${CONFIGURATION}-iphoneos" ]; then
151+
echo "${CONFIGURATION}-iphoneos directory is not exist"
152+
exit 1
153+
fi
154+
155+
# get file name
156+
PRODUCT_NAME=`find build -type dir -name "*.app"`
157+
PRODUCT_NAME=`basename $PRODUCT_NAME`
158+
if [ $PRODUCT_NAME == "" ]; then
159+
echo "can not get product name"
160+
exit 1
161+
fi
162+
163+
164+
# create ipa folder
165+
FILE_NAME="${TARGET}_$(date +%y%m%d-%H%M)_r${GIT_VERSION}.ipa"
166+
echo "build file using specified name: $FILE_NAME"
167+
168+
cd $BUILD_PATH
169+
mkdir -p ipa/Payload
170+
cp -r ./${CONFIGURATION}-iphoneos/$PRODUCT_NAME ./ipa/Payload/
171+
172+
# create ipa file
173+
echo "creating $FILE_NAME"
174+
cd ipa
175+
zip -rq $FILE_NAME *
176+
177+
# create dSYM file
178+
echo "creating dSYM.zip"
179+
cd $BUILD_PATH/${CONFIGURATION}-iphoneos/
180+
zip -rq dSYM.zip ${PRODUCT_NAME}.dSYM
181+
182+
# generate output folder
183+
if [ "${TAG_NAME}" == "" ]; then
184+
YEAR=$(date +%Y)
185+
MONTH=$(date +%m)
186+
FOLDER="${FOLDER_PREFIX}/${TARGET}/${YEAR}/${MONTH}/${TARGET}_${SERVER}_$(date +%y%m%d-%H%M)"
187+
else
188+
FOLDER="${FOLDER_PREFIX}/${TARGET}/tags/${TARGET}_${SERVER}_${TAG_NAME}"
189+
fi
190+
echo "Output folder=${FOLDER}"
191+
192+
# copy ipa & dsym
193+
194+
cd $BUILD_PATH
195+
mkdir -p $FOLDER
196+
cp ipa/$FILE_NAME $FOLDER/
197+
cp ${CONFIGURATION}-iphoneos/dSYM.zip $FOLDER/
198+
199+
# copy icon
200+
ICON_FILE=`find . -type f -name "[iI]con.png" | head -1`
201+
if [ "$ICON_FILE" == "" ]; then
202+
echo "icon file is not exit"
203+
exit 1
204+
fi
205+
cp $ICON_FILE $FOLDER/icon.png
206+
207+
# Create install html
208+
cd $FOLDER
209+
PLIST_PATH="/${FOLDER}/appInfo.plist"
210+
# ${str//apple/APPLE} # 替换所有apple,这里的apple是/,被转义成\/
211+
PLIST_PATH=${PLIST_PATH//\//%2f}
212+
cat << EOF > index.html
213+
<!DOCTYPE HTML>
214+
<html>
215+
<head>
216+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
217+
<title>安装此软件</title>
218+
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0"/>
219+
</head>
220+
<body>
221+
<h1><center>$PRODUCT_NAME Daily Build</center></h1>
222+
<hr />
223+
<ul>
224+
<li>iOS设备直接安装:<a href="itms-services://?action=download-manifest&url=${HTTP_TARGET}${PLIST_PATH}">点击这里安装</a></li>
225+
</ul>
226+
<p>
227+
<ul>
228+
<li>下载此软件的ipa包:<br/><a href="${HTTP_TARGET}/${FOLDER}/$FILE_NAME">$FILE_NAME</a></li>
229+
</ul>
230+
<ul>
231+
<li>下载此软件的dSYM文件:<br/><a href="${HTTP_TARGET}/${FOLDER}/dSYM.zip">dSYM.zip</a></li>
232+
</ul>
233+
<hr />
234+
<p>
235+
<br />
236+
最近的提交Log:
237+
<pre>$COMMIT_LOG
238+
</pre>
239+
</body>
240+
</html>
241+
EOF
242+
243+
cat << EOF > appInfo.plist
244+
<?xml version="1.0" encoding="UTF-8"?>
245+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
246+
<plist version="1.0">
247+
<dict>
248+
<key>items</key>
249+
<array>
250+
<dict>
251+
<key>assets</key>
252+
<array>
253+
<dict>
254+
<key>kind</key>
255+
<string>software-package</string>
256+
<key>url</key>
257+
<string>${HTTP_TARGET}/${FOLDER}/$FILE_NAME</string>
258+
</dict>
259+
<dict>
260+
<key>kind</key>
261+
<string>display-image</string>
262+
<key>needs-shine</key>
263+
<true/>
264+
<key>url</key>
265+
<string>${HTTP_TARGET}/${FOLDER}/icon.png</string>
266+
</dict>
267+
<dict>
268+
<key>kind</key>
269+
<string>full-size-image</string>
270+
<key>needs-shine</key>
271+
<true/>
272+
<key>url</key>
273+
<string>${HTTP_TARGET}/${FOLDER}/icon.png</string>
274+
</dict>
275+
</array><key>metadata</key>
276+
<dict>
277+
<key>bundle-identifier</key>
278+
<string>$BUNDLE_ID</string>
279+
<key>bundle-version</key>
280+
<string>1.0</string>
281+
<key>kind</key>
282+
<string>software</string>
283+
<key>subtitle</key>
284+
<string>$PRODUCT_NAME</string>
285+
<key>title</key>
286+
<string>$PRODUCT_NAME</string>
287+
</dict>
288+
</dict>
289+
</array>
290+
</dict>
291+
</plist>
292+
293+
EOF
294+
295+
# create latest link
296+
297+
cd "$BUILD_PATH/$FOLDER_PREFIX/$TARGET"
298+
mkdir latest
299+
find . -type f -name "appInfo.plist" | xargs -J % cp % latest/
300+
301+
cd $BUILD_PATH
302+
303+
if [ "$OUTPUT_PATH" != "" ]; then
304+
scp -r $FOLDER_PREFIX ${OUTPUT_PATH}
305+
fi
306+
307+
308+
echo "Daily build for $PRODUCT_NAME completed!"

0 commit comments

Comments
 (0)