Skip to content

Instantly share code, notes, and snippets.

@hjeffrey
Last active September 23, 2015 10:11
Show Gist options
  • Save hjeffrey/2e8c958dab01eed1f8a9 to your computer and use it in GitHub Desktop.
Save hjeffrey/2e8c958dab01eed1f8a9 to your computer and use it in GitHub Desktop.
Automatic make ipa after XCode build. and upload it to ftp, then send a email.

使用说明

功能

XCode 执行编译后,启动此脚本完成以下工作

  • 制作 ipa,
  • 上传到指定 FTP 服务器
  • 读取 history.txt 的更新内容,组织邮件,发送到邮件

要点

打包所依赖的环境变量都是从 Build Settting 中的,
脚本文件内未设置任何编译相关的环境变量。
如果出现编译错误,请检查 Build Setting 中关于签名和打包的配置项。
另外邮件发送和自己电脑配置有关,可能只能发送给“自己”。

用法

在 XCode 中找到 active scheme
选择 Edit Scheme
展开 Build
选择 Post-actions
点击左下角的 + ,选择 New Run Script Action 填写如下内容:

`${SRCROOT}/Shell/distributeApp.sh [email protected]`

在 XCode 选择目标 Target
找到 Build Phases
点击 +
选择 New Run script phase 填写内容如下:

`#echo ${PLATFORM_NAME} > ${SRCROOT}/Shell/platform_name`  
代码 github
#!/bin/sh
# distributeApp.sh
#
# Created by Jia Yuhui on 29/06/2015.
# Copyright 2015 Jia Yuhui. All rights reserved.
# chmod 755 distributeApp.sh
if [[ ${PLATFORM_NAME} == "iphonesimulator" ]]; then
# 不支持模拟器
printf "此脚本(distributeApp.sh)不支持${PLATFORM_NAME}"
exit 0
elif [[ ${PLATFORM_NAME} == "iphoneos" ]]; then
#statements
printf "开始生产IPA,并打包上传到禅道,发包邮件发送到指定用户"
sh ${SRCROOT}/shell/makeIPA.sh $1
elif [[ ${PLATFORM_NAME}="macosx" ]]; then
printf "此脚本(testApp.sh)不支持${PLATFORM_NAME}"
exit 1
fi
#!/bin/sh
# makeIPA.sh
#
# Created by Jia Yuhui on 24/06/2015.
# Copyright 2015 Jia Yuhui. All rights reserved.
# chmod 755 makeIPA.sh
WORK_PATH="${BUILD_DIR}/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}"
APP_PATH=${WORK_PATH}/${EXECUTABLE_FOLDER_PATH}
APP_VERSION=`defaults read $APP_PATH/Info CFBundleShortVersionString`
APP_REVISION=`defaults read $APP_PATH/Info CFBundleVersion`
APP_NAME="iOS_V${APP_VERSION}_store_build${APP_REVISION}_$(date +%Y%m%d_%H%M)"
IPA_NAME="${APP_NAME}.ipa"
IPA_PATH=${WORK_PATH}/${IPA_NAME}
#WIDGET_dSYM_PATH="Widget.appex.dSYM"
dSYM_NAME="${IPA_NAME}.dSYM.zip"
dSYM_PATH="${WORK_PATH}/$dSYM_NAME"
USER_IPA_PATH="${SRCROOT}/${IPA_NAME}"
USER_dSYM_PATH="${SRCROOT}/${dSYM_NAME}"
cd $WORK_PATH
#### make ipa
# cp -q $APP_PATH/embedded.mobileprovision embedded.mobileprovision
/usr/bin/xcrun -sdk ${PLATFORM_NAME} PackageApplication -v "${APP_PATH}" -o "$IPA_PATH" #--sign "$CODE_SIGN_IDENTITY" --embed "embedded.mobileprovision"
if [[ $? != 0 ]]; then
printf '!!Make IPA error'
exit 1
fi
#### zip dSYM
zip -r -q "$dSYM_PATH" "$DWARF_DSYM_FILE_NAME" #"$WIDGET_dSYM_PATH"
mv $dSYM_PATH $USER_dSYM_PATH
mv $IPA_PATH $USER_IPA_PATH
#### upload and send email
${SRCROOT}/Shell/uploadIPA.sh $1 "$IPA_NAME" "$dSYM_NAME" "$APP_NAME" "$APP_VERSION"
#!/bin/sh
# sendEmail.sh
#
# Created by Jia Yuhui on 24/06/2015.
# Modified by Jia Yuhui on 20/07/2015. Add email address as parameter.
# Copyright 2015 Jia Yuhui. All rights reserved.
# chmod 755 sendEmail.sh
CONTENTFILE="${SRCROOT}/feature-${3}-$(date +%Y%m%d_%H-%M-%S)"
echo "名称编号" >> $CONTENTFILE
echo ${2} >> $CONTENTFILE
echo ${4} >> $CONTENTFILE
echo ${5} >> $CONTENTFILE
UPDATECONTENT="${SRCROOT}/history.txt"
cat $UPDATECONTENT | while read LINE
do
echo $LINE >> $CONTENTFILE
done
EMAIL_ADDRESS="$1"
EMAIL_NAME="自动打包邮件"
EMAIL_TITLE="[发包邮件]${TARGET_NAME}_iOS_${3}"
mail -s $EMAIL_TITLE $EMAIL_ADDRESS -f $EMAIL_NAME < $CONTENTFILE
if [ $? != 0 ]
then
rm -r $CONTENTFILE
printf Mail error !!!
exit 3
fi
rm -r $CONTENTFILE
open .
exit 0
#!/bin/sh
# uploadIPA.sh
#
# Created by Jia Yuhui on 24/06/2015.
# Modified bu Jia Yuhui on 17/07/2015. Fixed Uploading file type error.
# Copyright 2015 Jia Yuhui. All rights reserved.
# chmod 755 uploadIPA.sh
cd ${SRCROOT}
HOST='192.168.1.1'
USER='name'
PASSWD='password'
REMOTEDIR='path'
ftp -n $HOST <<EOF
quote USER $USER
quote PASS $PASSWD
type binary
cd $REMOTEDIR
put $2
put $3
quit
EOF
FTP_FILE1="ftp://$HOST/$REMOTEDIR/$2"
FTP_FILE2="ftp://$HOST/$REMOTEDIR/$3"
sh ${SRCROOT}/shell/sendEmail.sh $1 $4 $5 $FTP_FILE1 $FTP_FILE2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment