iOS自动化打包脚本

export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
pod repo update ~/.cocoapods/repos/JKDJSpec
pod install
# #!/bin/sh

#导出包类型 plist
EXPORT_TYPE="Adhoc"

#打包类型
BUILD_TYPE="Adhoc"

# 工程名
APP_NAME="工程名字"

# workspace名
WORK_SPACE="工程名字.xcworkspace"

#info.plist路径
project_infoplist_path="./${APP_NAME}/Info.plist"
 
#取版本号
#bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${project_infoplist_path}")
bundleShortVersion=`xcodebuild -showBuildSettings | grep MARKETING_VERSION | tr -d 'MARKETING_VERSION ='`

#取build值 
#bundleVersion=`xcodebuild -showBuildSettings | grep CURRENT_PROJECT_VERSION | tr -d 'CURRENT_PROJECT_VERSION ='`
bundleVersion=`git log -a |wc -l | sed 's/^[ \t]*//g'`


#时间
DATE="$(date +%Y%m%d)"

# IPA路径
IPAPATH="${APP_NAME}_${BUILD_TYPE}_V${bundleShortVersion}_B${bundleVersion}_${DATE}"

# xcarchive
XCARCHIVE="${APP_NAME}_${BUILD_TYPE}_V${bundleShortVersion}_B${bundleVersion}_${DATE}.xcarchive"

#IPA输入路径
IPAPATHOUT="./build/${IPAPATH}/${APP_NAME}.ipa"


echo "\n\n\033[32m -----------------------Xcode打包-----------------------\033[0m\n\n\n"

$(/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${bundleVersion}" "${project_infoplist_path}")


# 清理
echo "\n\n\033[32m +++++++++++++++++清理中+++++++++++++++++\033[0m\n\n\n"
xcodebuild -workspace "${WORK_SPACE}" -scheme "${APP_NAME}" -configuration "${BUILD_TYPE}" clean

# 编译
echo "\n\n\033[32m +++++++++++++++++编译中+++++++++++++++++\033[0m\n\n\n"
xcodebuild -workspace "${WORK_SPACE}" -sdk iphoneos -scheme "${APP_NAME}" -archivePath "./build/${XCARCHIVE}" -configuration "${BUILD_TYPE}" archive

# 打包
echo "\n\n\033[32m +++++++++++++++++打包中++++++++++++++++++\033[0m\n\n\n"
xcodebuild -exportArchive -archivePath "./build/${XCARCHIVE}" -exportPath "./build/${IPAPATH}" -exportOptionsPlist "./ExportOptionsPlist/${EXPORT_TYPE}ExportOptionsPlist.plist" -allowProvisioningUpdates


echo "\n\n\033[32m -----------------------上传到蒲公英-----------------------\033[0m\n\n\n"


#蒲公英上的user Key
uKey="4371fb11c6bbccb4c613ae93ded1fef0"
 
#蒲公英上的API Key
apiKey="789438bcbd5da6f7b5620f0ed143e72f"
 
#蒲公英版本更新描述,这里取git最后一条提交记录作为描述
MSG=`git log -1 --pretty=%B`

#要上传的ipa文件路径
echo $IPAPATHOUT
  
# 执行上传至蒲公英的命令
echo "++++++++++++++upload+++++++++++++"

curl -F "file=@${IPAPATHOUT}" -F "uKey=${uKey}" -F "_api_key=${apiKey}" -F "buildUpdateDescription=${MSG}" http://www.pgyer.com/apiv2/app/upload > uploadResponse.json

#cat uploadResponse.json

echo 
echo "++++++++++++++提取上传响应信息+++++++++++++"

uploadResult=`cat $WORKSPACE/uploadResponse.json`


url1=`echo "${uploadResult##*"buildQRCodeURL"}"`

urlLength=`expr ${#url1} - 6`

url2=`echo ${url1:3:$urlLength}`

buildQRCodeURL=`echo $url2 | sed 's:\\\/:\/:g'`


if [ ! $buildQRCodeURL ]; then
   echo "~~~~~~~~~~~~~~~~~~~上传失败~~~~~~~~~~~~~~~~~~~"
else
   echo "~~~~~~~~~~~~~~~~~~~上传成功~~~~~~~~~~~~~~~~~~~"
   echo "构建版本:${bundleShortVersion}"
   echo "二维码链接:${buildQRCodeURL}"
fi

echo "buildQRCodeURL=${buildQRCodeURL}\r\nbuildVersion=${bundleShortVersion}">> uploadResult.txt



echo "\n\n\033[32m -----------------------上传钉钉群通知-----------------------\033[0m\n\n\n"

curl 'https://oapi.dingtalk.com/robot/send?access_token=48c80fea344d28d6a4c5d2965013a1dd3f54976d01ee39951f39c9b68a4d6f3c' \
   -H 'Content-Type: application/json' \
   -d "{'msgtype':'markdown','markdown':{'title':'iOS端','text':'### iOS端  \n * 构建分支 => ${Branch_Tag}  \n * 构建环境 => ${BUILD_TYPE}  \n * 构建版本 => ${bundleShortVersion}(${bundleVersion})  \n ![screenshot](${buildQRCodeURL})  \n>'}}"

猜你喜欢

转载自blog.csdn.net/yezuiqingxin/article/details/120368023